100 lines
2 KiB
TypeScript
100 lines
2 KiB
TypeScript
![]() |
|
||
|
namespace _zeitbild.api
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
export function register_calendar_event_change(
|
||
|
rest_subject : lib_plankton.rest.type_rest
|
||
|
) : void
|
||
|
{
|
||
|
register<
|
||
|
_zeitbild.type_event_object, // TODO aufdröseln
|
||
|
(
|
||
|
null
|
||
|
|
|
||
|
string
|
||
|
)
|
||
|
>(
|
||
|
rest_subject,
|
||
|
lib_plankton.http.enum_method.put,
|
||
|
"/calendar/:calendar_id/event/:event_id",
|
||
|
{
|
||
|
"description": "ändert einen Termin",
|
||
|
"input_schema": () => ({
|
||
|
"type": "object",
|
||
|
"properties": {
|
||
|
"name": {
|
||
|
"nullable": false,
|
||
|
"type": "string"
|
||
|
},
|
||
|
"begin": _zeitbild.api.datetime_type(
|
||
|
{
|
||
|
"nullable": false,
|
||
|
}
|
||
|
),
|
||
|
"end": _zeitbild.api.datetime_type(
|
||
|
{
|
||
|
"nullable": true,
|
||
|
}
|
||
|
),
|
||
|
"location": {
|
||
|
"type": "string",
|
||
|
"nullable": true,
|
||
|
},
|
||
|
"description": {
|
||
|
"type": "string",
|
||
|
"nullable": true,
|
||
|
},
|
||
|
},
|
||
|
"required": [
|
||
|
"name",
|
||
|
"begin",
|
||
|
"end",
|
||
|
"location",
|
||
|
"description",
|
||
|
],
|
||
|
"additionalProperties": false
|
||
|
}),
|
||
|
"output_schema": () => ({
|
||
|
"nullable": true,
|
||
|
"type": "null"
|
||
|
}),
|
||
|
"restriction": restriction_logged_in,
|
||
|
"execution": async (stuff) => {
|
||
|
const session : {key : string; value : lib_plankton.session.type_session;} = await session_from_stuff(stuff);
|
||
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(session.value.name);
|
||
|
|
||
|
if (stuff.input === null) {
|
||
|
return Promise.reject(new Error("impossible"));
|
||
|
}
|
||
|
else {
|
||
|
return (
|
||
|
_zeitbild.service.calendar.event_change(
|
||
|
parseInt(stuff.path_parameters["calendar_id"]),
|
||
|
parseInt(stuff.path_parameters["event_id"]),
|
||
|
stuff.input,
|
||
|
user_id
|
||
|
)
|
||
|
.then(
|
||
|
() => Promise.resolve({
|
||
|
"status_code": 200,
|
||
|
"data": null,
|
||
|
})
|
||
|
)
|
||
|
// TODO distinguish
|
||
|
.catch(
|
||
|
(reason) => Promise.resolve({
|
||
|
"status_code": 403,
|
||
|
"data": String(reason),
|
||
|
})
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|