backend/source/api/actions/davina_event_list.ts

99 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-08-29 10:52:37 +00:00
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",
{
"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",
],
}
}),
2025-09-04 07:46:49 +00:00
"restriction": restriction_web_auth,
2025-08-29 10:52:37 +00:00
"execution": async (stuff) => {
2025-09-04 07:46:49 +00:00
const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff);
2025-09-04 09:53:18 +00:00
2025-08-29 10:52:37 +00:00
/**
* @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,
2025-09-04 07:46:49 +00:00
user.id
2025-08-29 10:52:37 +00:00
)
.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),
}
)
)
);
}
}
);
}
}