backend/source/api/actions/events.ts
Fenris Wolf 78014d6a3a [mod]
2024-09-12 19:35:31 +02:00

157 lines
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;
event : _zeitbild.type.event_object;
}
>
>(
rest_subject,
lib_plankton.http.enum_method.post,
"/events",
{
"description": "stellt Veranstaltungen aus verschiedenen Kalendern zusammen",
"query_parameters": [
],
"input_schema": () => ({
"type": "object",
"nullable": false,
"additionalProperties": false,
"properties": {
"from": {
"type": "number",
"nullable": false,
},
"to": {
"type": "number",
"nullable": false,
},
"calendar_id": {
"type": "array",
"nullable": false,
"items": {
"type": "number",
"nullable": false
}
}
},
"required": [
"from",
"to",
]
}),
"output_schema": () => ({
"type": "array",
"items": {
"type": "object",
"nullable": false,
"additionalProperties": false,
"properties": {
"calendar_id": {
"type": "number",
"nullable": false,
},
"event": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"nullable": false,
},
"begin": {
"type": "int",
"nullable": false,
},
"end": {
"type": "int",
"nullable": true,
},
"location": {
"type": "string",
"nullable": true,
},
"description": {
"type": "string",
"nullable": true,
},
},
"required": [
"name",
"begin",
"end",
"location",
"description",
]
}
},
"required": [
"calendar_id",
"event",
],
}
}),
"restriction": restriction_none, // TODO
"execution": (stuff) => {
if (stuff.input === null) {
return Promise.resolve({
"status_code": 400,
"data": null,
});
}
else {
return (
(
(stuff.input.calendar_ids !== null)
?
Promise.resolve(stuff.input.calendar_ids)
:
(
_zeitbild.service.calendar.overview(0) // TODO: user_id
.then(
(x : any) => x.map((y : any) => y.id)
)
)
)
.then(
(calendar_ids : Array<_zeitbild.type.calendar_id>) => _zeitbild.service.calendar.gather_events(
calendar_ids,
// @ts-ignore
stuff.input.from,
// @ts-ignore
stuff.input.to
)
)
.then(
(data : any) => Promise.resolve({
"status_code": 200,
"data": data,
})
)
);
}
}
}
);
}
}