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; 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", }, "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, }, "description": { "type": "string", "nullable": true, }, }, "required": [ "name", "begin", "end", "location", "description", ] } }, "required": [ "calendar_id", "event_id", "calendar_name", "event_object", ], } }), "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); 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) => x.map(parseInt), (x : Array) => 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, }) ) .catch( (reason) => Promise.resolve({ "status_code": 403, "data": String(reason), }) ) ); } } ); } }