199 lines
4.3 KiB
TypeScript
199 lines
4.3 KiB
TypeScript
|
|
namespace _zeitbild.api
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export function register_events(
|
|
rest_subject : lib_plankton.rest.type_rest
|
|
) : void
|
|
{
|
|
register<
|
|
{
|
|
from : int;
|
|
to : int;
|
|
calendar_ids : (
|
|
null
|
|
|
|
|
Array<_zeitbild.type_calendar_id>
|
|
);
|
|
},
|
|
(
|
|
Array<
|
|
{
|
|
calendar_id : int;
|
|
calendar_name : string;
|
|
access_level : string;
|
|
event_id : (null | int);
|
|
event_object : _zeitbild.type_event_object;
|
|
}
|
|
>
|
|
|
|
|
string
|
|
)
|
|
>(
|
|
rest_subject,
|
|
lib_plankton.http.enum_method.get,
|
|
"/events",
|
|
{
|
|
"description": "stellt Veranstaltungen aus verschiedenen Kalendern zusammen",
|
|
"query_parameters": () => ([
|
|
{
|
|
"name": "from",
|
|
"required": true,
|
|
"description": "UNIX timestamp",
|
|
},
|
|
{
|
|
"name": "to",
|
|
"required": true,
|
|
"description": "UNIX timestamp",
|
|
},
|
|
{
|
|
"name": "calendar_ids",
|
|
"required": false,
|
|
"description": "comma separated",
|
|
},
|
|
]),
|
|
"output_schema": () => ({
|
|
"type": "array",
|
|
"items": {
|
|
"nullable": false,
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"calendar_id": {
|
|
"nullable": false,
|
|
"type": "number",
|
|
},
|
|
"calendar_name": {
|
|
"nullable": false,
|
|
"type": "string",
|
|
},
|
|
"access_level": {
|
|
"nullable": false,
|
|
"type": "string",
|
|
"enum": ["none","view","edit","admin"],
|
|
},
|
|
"event_id": {
|
|
"nullable": true,
|
|
"type": "number",
|
|
},
|
|
"event_object": {
|
|
"nullable": false,
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"name": {
|
|
"type": "string",
|
|
"nullable": false,
|
|
},
|
|
"begin": _zeitbild.api.datetime_type(
|
|
{
|
|
"nullable": false,
|
|
}
|
|
),
|
|
"end": _zeitbild.api.datetime_type(
|
|
{
|
|
"nullable": true,
|
|
}
|
|
),
|
|
"location": {
|
|
"type": "string",
|
|
"nullable": true,
|
|
},
|
|
"link": {
|
|
"type": "string",
|
|
"nullable": true,
|
|
},
|
|
"description": {
|
|
"type": "string",
|
|
"nullable": true,
|
|
},
|
|
},
|
|
"required": [
|
|
"name",
|
|
"begin",
|
|
"end",
|
|
"location",
|
|
"description",
|
|
]
|
|
}
|
|
},
|
|
"required": [
|
|
"calendar_id",
|
|
"event_id",
|
|
"calendar_name",
|
|
"event_object",
|
|
],
|
|
}
|
|
}),
|
|
"restriction": restriction_none,
|
|
"execution": async (stuff) => {
|
|
const user_id : (null | _zeitbild.type_user_id) = await (
|
|
session_from_stuff(stuff)
|
|
.then(
|
|
(session : {key : string; value : lib_plankton.session.type_session;}) => (
|
|
_zeitbild.service.user.identify(session.value.name)
|
|
.catch(x => Promise.resolve(null))
|
|
)
|
|
)
|
|
.catch(x => Promise.resolve(null))
|
|
);
|
|
|
|
const from : lib_plankton.pit.type_pit = parseInt(stuff.query_parameters["from"]);
|
|
const to : lib_plankton.pit.type_pit = parseInt(stuff.query_parameters["to"]);
|
|
const calendar_ids_wanted : (null | Array<_zeitbild.type_calendar_id>) = (
|
|
(
|
|
("calendar_ids" in stuff.query_parameters)
|
|
&&
|
|
(stuff.query_parameters["calendar_ids"] !== null)
|
|
)
|
|
?
|
|
lib_plankton.call.convey(
|
|
stuff.query_parameters["calendar_ids"],
|
|
[
|
|
(x : string) => x.split(","),
|
|
(x : Array<string>) => x.map(parseInt),
|
|
(x : Array<int>) => x.filter(y => (! isNaN(y)))
|
|
]
|
|
)
|
|
:
|
|
null
|
|
);
|
|
return (
|
|
_zeitbild.service.calendar.gather_events(
|
|
calendar_ids_wanted,
|
|
from,
|
|
to,
|
|
user_id
|
|
)
|
|
.then(
|
|
(data) => Promise.resolve({
|
|
"status_code": 200,
|
|
"data": (
|
|
data
|
|
.map(
|
|
(entry) => ({
|
|
"calendar_id": entry.calendar_id,
|
|
"calendar_name": entry.calendar_name,
|
|
"access_level": _zeitbild.api.access_level_encode(entry.access_level),
|
|
"event_id": entry.event_id,
|
|
"event_object": entry.event_object,
|
|
})
|
|
)
|
|
),
|
|
})
|
|
)
|
|
.catch(
|
|
(reason) => Promise.resolve({
|
|
"status_code": 403,
|
|
"data": String(reason),
|
|
})
|
|
)
|
|
);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|