backend/source/api/actions/davina_calendars.ts

76 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-29 10:52:37 +00:00
namespace _zeitbild.api
{
/**
*/
export function register_davina_calendars(
rest_subject : lib_plankton.rest_caldav.type_rest
) : void
{
register<
null,
null | Array<
{
id : int;
name : string;
access_level : string;
}
>
>
(
rest_subject,
lib_plankton.http.enum_method.get,
"/davina/calendars",
{
"input_schema": () => ({
"nullable": true,
}),
"output_schema": () => ({
"nullable": false,
"type": "boolean",
}),
"query_parameters": () => ([
{
"name": "username",
"required": true,
"description": "username",
},
]),
/**
* @todo
*/
"restriction": restriction_none,
"execution": async ({"query_parameters": query_parameters}) => {
const username : string = query_parameters["username"];
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(username);
return (
_zeitbild.service.calendar.overview(user_id)
.then(
(data_raw) => Promise.resolve(
data_raw
.map(
(entry) => ({
"id": entry.id,
"name": entry.name,
"access_level": _zeitbild.value_object.access_level.to_string(entry.access_level),
})
)
)
)
.then(
(data) => Promise.resolve({
"status_code": 200,
"data": data,
})
)
);
},
}
);
}
}