2024-09-12 19:35:31 +02:00
|
|
|
|
|
|
|
namespace _zeitbild.api
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export function register_events(
|
|
|
|
rest_subject : lib_plankton.rest.type_rest
|
|
|
|
) : void
|
|
|
|
{
|
|
|
|
register<
|
|
|
|
{
|
|
|
|
from : int;
|
|
|
|
to : int;
|
|
|
|
calendar_ids : (
|
|
|
|
null
|
|
|
|
|
|
2024-09-21 11:05:24 +02:00
|
|
|
Array<_zeitbild.type_calendar_id>
|
2024-09-12 19:35:31 +02:00
|
|
|
);
|
|
|
|
},
|
2024-09-26 10:33:33 +02:00
|
|
|
(
|
|
|
|
Array<
|
|
|
|
{
|
|
|
|
calendar_id : int;
|
|
|
|
calendar_name : string;
|
2024-09-30 12:01:40 +02:00
|
|
|
event_id : (null | int);
|
|
|
|
event_object : _zeitbild.type_event_object;
|
2024-09-26 10:33:33 +02:00
|
|
|
}
|
|
|
|
>
|
|
|
|
|
|
|
|
|
string
|
|
|
|
)
|
2024-09-12 19:35:31 +02:00
|
|
|
>(
|
|
|
|
rest_subject,
|
2024-09-12 20:42:06 +02:00
|
|
|
lib_plankton.http.enum_method.get,
|
2024-09-12 19:35:31 +02:00
|
|
|
"/events",
|
|
|
|
{
|
|
|
|
"description": "stellt Veranstaltungen aus verschiedenen Kalendern zusammen",
|
2024-09-19 13:34:07 +02:00
|
|
|
"query_parameters": () => ([
|
2024-09-12 20:42:06 +02:00
|
|
|
{
|
|
|
|
"name": "from",
|
|
|
|
"required": true,
|
|
|
|
"description": "UNIX timestamp",
|
2024-09-12 19:35:31 +02:00
|
|
|
},
|
2024-09-12 20:42:06 +02:00
|
|
|
{
|
|
|
|
"name": "to",
|
|
|
|
"required": true,
|
|
|
|
"description": "UNIX timestamp",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "calendar_ids",
|
|
|
|
"required": false,
|
|
|
|
"description": "comma separated",
|
|
|
|
},
|
2024-09-19 13:34:07 +02:00
|
|
|
]),
|
2024-09-12 19:35:31 +02:00
|
|
|
"output_schema": () => ({
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"nullable": false,
|
2024-09-30 12:01:40 +02:00
|
|
|
"type": "object",
|
2024-09-12 19:35:31 +02:00
|
|
|
"additionalProperties": false,
|
|
|
|
"properties": {
|
|
|
|
"calendar_id": {
|
2024-09-30 12:01:40 +02:00
|
|
|
"nullable": false,
|
2024-09-12 19:35:31 +02:00
|
|
|
"type": "number",
|
2024-09-30 12:01:40 +02:00
|
|
|
},
|
|
|
|
"calendar_name": {
|
2024-09-12 19:35:31 +02:00
|
|
|
"nullable": false,
|
2024-09-30 12:01:40 +02:00
|
|
|
"type": "string",
|
2024-09-12 19:35:31 +02:00
|
|
|
},
|
2024-09-30 12:01:40 +02:00
|
|
|
"event_id": {
|
|
|
|
"nullable": true,
|
|
|
|
"type": "number",
|
|
|
|
},
|
|
|
|
"event_object": {
|
|
|
|
"nullable": false,
|
2024-09-12 19:35:31 +02:00
|
|
|
"type": "object",
|
|
|
|
"additionalProperties": false,
|
|
|
|
"properties": {
|
|
|
|
"name": {
|
|
|
|
"type": "string",
|
|
|
|
"nullable": false,
|
|
|
|
},
|
2024-09-26 10:33:33 +02:00
|
|
|
"begin": _zeitbild.api.datetime_type(
|
|
|
|
{
|
|
|
|
"nullable": false,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"end": _zeitbild.api.datetime_type(
|
|
|
|
{
|
|
|
|
"nullable": true,
|
|
|
|
}
|
|
|
|
),
|
2024-09-12 19:35:31 +02:00
|
|
|
"location": {
|
|
|
|
"type": "string",
|
|
|
|
"nullable": true,
|
|
|
|
},
|
|
|
|
"description": {
|
|
|
|
"type": "string",
|
|
|
|
"nullable": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"required": [
|
|
|
|
"name",
|
|
|
|
"begin",
|
|
|
|
"end",
|
|
|
|
"location",
|
|
|
|
"description",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"required": [
|
2024-09-30 12:01:40 +02:00
|
|
|
"calendar_id",
|
|
|
|
"event_id",
|
2024-09-12 20:42:06 +02:00
|
|
|
"calendar_name",
|
2024-09-30 12:01:40 +02:00
|
|
|
"event_object",
|
2024-09-12 19:35:31 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
}),
|
2024-09-25 14:50:32 +02:00
|
|
|
"restriction": restriction_logged_in,
|
2024-09-12 20:42:06 +02:00
|
|
|
"execution": async (stuff) => {
|
2024-09-18 18:17:25 +02:00
|
|
|
const session : {key : string; value : lib_plankton.session.type_session;} = await session_from_stuff(stuff);
|
2024-09-21 11:05:24 +02:00
|
|
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(session.value.name);
|
2024-09-18 18:17:25 +02:00
|
|
|
|
2024-09-26 16:47:38 +02:00
|
|
|
const from : lib_plankton.pit.type_pit = parseInt(stuff.query_parameters["from"]);
|
|
|
|
const to : lib_plankton.pit.type_pit = parseInt(stuff.query_parameters["to"]);
|
2024-09-26 10:33:33 +02:00
|
|
|
const calendar_ids_wanted : (null | Array<_zeitbild.type_calendar_id>) = (
|
2024-09-12 20:42:06 +02:00
|
|
|
(
|
|
|
|
("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
|
|
|
|
);
|
2024-09-26 10:33:33 +02:00
|
|
|
return (
|
|
|
|
_zeitbild.service.calendar.gather_events(
|
|
|
|
calendar_ids_wanted,
|
|
|
|
from,
|
|
|
|
to,
|
|
|
|
user_id
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
(data) => Promise.resolve({
|
|
|
|
"status_code": 200,
|
|
|
|
"data": data,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.catch(
|
|
|
|
(reason) => Promise.resolve({
|
|
|
|
"status_code": 403,
|
|
|
|
"data": String(reason),
|
|
|
|
})
|
2024-09-12 20:42:06 +02:00
|
|
|
)
|
|
|
|
);
|
2024-09-12 19:35:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|