115 lines
2.1 KiB
TypeScript
115 lines
2.1 KiB
TypeScript
![]() |
|
||
|
namespace _zeitbild.api
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
export function register_davina_event_list(
|
||
|
rest_subject : lib_plankton.rest_caldav.type_rest
|
||
|
) : void
|
||
|
{
|
||
|
register<
|
||
|
null,
|
||
|
(
|
||
|
Array<
|
||
|
{
|
||
|
event_id : (null | int);
|
||
|
event_name : string;
|
||
|
}
|
||
|
>
|
||
|
|
|
||
|
string
|
||
|
)
|
||
|
>(
|
||
|
rest_subject,
|
||
|
lib_plankton.http.enum_method.get,
|
||
|
"/davina/event_list",
|
||
|
{
|
||
|
"query_parameters": () => ([
|
||
|
{
|
||
|
"name": "username",
|
||
|
"required": true,
|
||
|
"description": "user name",
|
||
|
},
|
||
|
{
|
||
|
"name": "calendar_id",
|
||
|
"required": true,
|
||
|
"description": "calendar ID",
|
||
|
},
|
||
|
]),
|
||
|
"output_schema": () => ({
|
||
|
"type": "array",
|
||
|
"items": {
|
||
|
"nullable": false,
|
||
|
"type": "object",
|
||
|
"additionalProperties": false,
|
||
|
"properties": {
|
||
|
"event_id": {
|
||
|
"nullable": true,
|
||
|
"type": "number",
|
||
|
},
|
||
|
"event_name": {
|
||
|
"nullable": false,
|
||
|
"type": "string",
|
||
|
},
|
||
|
},
|
||
|
"required": [
|
||
|
"event_id",
|
||
|
"event_name",
|
||
|
],
|
||
|
}
|
||
|
}),
|
||
|
/**
|
||
|
* @todo
|
||
|
*/
|
||
|
"restriction": restriction_none,
|
||
|
"execution": async (stuff) => {
|
||
|
const username : string = stuff.query_parameters["username"];
|
||
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(username);
|
||
|
|
||
|
/**
|
||
|
* @todo
|
||
|
*/
|
||
|
const from : lib_plankton.pit.type_pit = 0;
|
||
|
const to : lib_plankton.pit.type_pit = 1800000000;
|
||
|
const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]);
|
||
|
|
||
|
return (
|
||
|
_zeitbild.service.calendar.gather_events(
|
||
|
[calendar_id],
|
||
|
from,
|
||
|
to,
|
||
|
user_id
|
||
|
)
|
||
|
.then(
|
||
|
(data) => Promise.resolve(
|
||
|
{
|
||
|
"status_code": 200,
|
||
|
"data": (
|
||
|
data
|
||
|
.map(
|
||
|
(entry) => ({
|
||
|
"event_id": entry.event_id,
|
||
|
"event_name": entry.event_object.name,
|
||
|
})
|
||
|
)
|
||
|
),
|
||
|
}
|
||
|
)
|
||
|
)
|
||
|
.catch(
|
||
|
(reason) => Promise.resolve(
|
||
|
{
|
||
|
"status_code": 403,
|
||
|
"data": String(reason),
|
||
|
}
|
||
|
)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|