backend/source/api/actions/calendar_event_add.ts
Fenris Wolf a17b7dd785 [fix]
2024-09-25 15:28:25 +02:00

102 lines
1.9 KiB
TypeScript

namespace _zeitbild.api
{
/**
*/
export function register_calendar_event_add(
rest_subject : lib_plankton.rest.type_rest
) : void
{
register<
{
calendar_id : int;
event : _zeitbild.type_event_object; // TODO aufdröseln
},
null
>(
rest_subject,
lib_plankton.http.enum_method.post,
"/calendar/event_add",
{
"description": "fügt einen Termin hinzu",
"input_schema": () => ({
"nullable": false,
"type": "object",
"properties": {
"calendar_id": {
"nullable": false,
"type": "integer",
},
"event": {
"nullable": false,
"type": "object",
"properties": {
"name": {
"nullable": false,
"type": "string"
},
// TODO: fix
"begin": {
"type": "int",
"nullable": false,
},
// TODO: fix
"end": {
"type": "int",
"nullable": true,
},
"location": {
"type": "string",
"nullable": true,
},
"description": {
"type": "string",
"nullable": true,
},
},
"required": [
"name",
"begin",
"end",
"location",
"description",
],
"additionalProperties": false
},
},
"required": [
"calendar_id",
"event",
],
"additionalProperties": false
}),
"output_schema": () => ({
"nullable": true,
"type": "null"
}),
"restriction": restriction_logged_in,
"execution": async (stuff) => {
if (stuff.input === null) {
return Promise.reject(new Error("impossible"));
}
else {
return (
_zeitbild.service.calendar.event_add(
stuff.input.calendar_id,
stuff.input.event
)
.then(
() => Promise.resolve({
"status_code": 200,
"data": null,
})
)
);
}
}
}
);
}
}