backend/source/api/actions/calendar_list.ts

97 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-09-12 00:03:29 +02:00
namespace _zeitbild.api
{
/**
*/
export function register_calendar_list(
2024-10-30 07:20:13 +01:00
rest_subject : lib_plankton.rest_caldav.type_rest
2024-09-12 00:03:29 +02:00
) : void
{
register<
null,
Array<
{
2024-09-21 10:56:00 +02:00
id : int;
2024-09-12 20:42:06 +02:00
name : string;
2024-09-21 10:56:00 +02:00
access_level : string;
2024-09-12 00:03:29 +02:00
}
>
>(
rest_subject,
lib_plankton.http.enum_method.get,
"/calendar",
2024-09-12 00:03:29 +02:00
{
2024-09-12 20:42:06 +02:00
"description": "listet alle verfügbaren Kalender auf",
2024-09-19 13:34:07 +02:00
"query_parameters": () => ([
]),
2024-09-12 00:03:29 +02:00
"output_schema": () => ({
"type": "array",
"items": {
"type": "object",
"nullable": false,
"additionalProperties": false,
"properties": {
"id": {
"type": "number",
"nullable": false,
},
2024-09-12 20:42:06 +02:00
"name": {
"type": "string",
"nullable": false,
},
2024-09-21 10:56:00 +02:00
"access_level": {
2024-09-12 20:42:06 +02:00
"type": "string",
"nullable": true,
2024-09-21 10:56:00 +02:00
"enum": ["none", "edit", "view", "admin"]
2024-09-12 20:42:06 +02:00
},
2024-09-12 00:03:29 +02:00
},
"required": [
"id",
2024-09-12 20:42:06 +02:00
"name",
"public",
"role",
2024-09-12 00:03:29 +02:00
],
}
}),
2024-10-10 23:00:29 +02:00
"restriction": restriction_none,
2024-09-18 18:17:25 +02:00
"execution": async (stuff) => {
2024-10-10 23:00:29 +02:00
const user_id : (null | _zeitbild.type_user_id) = await (
session_from_stuff(stuff)
.then(
(session : {key : string; value : lib_plankton.session.type_session;}) => (
_zeitbild.service.user.identify(session.value.name)
.catch(x => Promise.resolve(null))
)
)
.catch(x => Promise.resolve(null))
);
2024-09-18 18:17:25 +02:00
return (
_zeitbild.service.calendar.overview(user_id)
.then(
2024-09-21 10:56:00 +02:00
(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({
2024-09-18 18:17:25 +02:00
"status_code": 200,
"data": data,
})
)
);
}
2024-09-12 00:03:29 +02:00
}
);
}
}