backend/source/api/actions/calendar_list.ts

116 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-09-25 17:18:16 +02:00
/*
This file is part of »zeitbild«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»zeitbild« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»zeitbild« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
*/
2024-09-12 00:03:29 +02:00
namespace _zeitbild.api
{
/**
*/
export function register_calendar_list(
2025-09-25 16:48:16 +02:00
rest_subject : lib_plankton.rest_http.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
}
);
}
}