79 lines
2 KiB
TypeScript
79 lines
2 KiB
TypeScript
![]() |
|
||
|
namespace _zeitbild.api
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
export function register_davina_event_get(
|
||
|
rest_subject : lib_plankton.rest_caldav.type_rest
|
||
|
) : void
|
||
|
{
|
||
|
register<
|
||
|
null,
|
||
|
lib_plankton.ical.type_vcalendar
|
||
|
>(
|
||
|
rest_subject,
|
||
|
lib_plankton.http.enum_method.get,
|
||
|
"/davina/event_get",
|
||
|
{
|
||
|
"query_parameters": () => ([
|
||
|
{
|
||
|
"name": "username",
|
||
|
"required": true,
|
||
|
"description": "user name",
|
||
|
},
|
||
|
{
|
||
|
"name": "calendar_id",
|
||
|
"required": true,
|
||
|
"description": "calendar ID",
|
||
|
},
|
||
|
{
|
||
|
"name": "event_id",
|
||
|
"required": true,
|
||
|
"description": "event ID",
|
||
|
},
|
||
|
]),
|
||
|
"output_schema": () => ({
|
||
|
"nullable": false,
|
||
|
"type": "string",
|
||
|
}),
|
||
|
"response_body_mimetype": "text/calendar",
|
||
|
"response_body_encode": (output) => Buffer.from(
|
||
|
(typeof(output) === "string")
|
||
|
?
|
||
|
output
|
||
|
:
|
||
|
(
|
||
|
lib_plankton.ical.ics_encode(output)
|
||
|
/**
|
||
|
* @todo add event encoder function to plankton
|
||
|
*/
|
||
|
// .replace(new RegExp("[\\s\\S]*BEGIN:VEVENT([\\s\\S]*)END:VEVENT[\\s\\S]*", "m"), "BEGIN:VEVENT$1END:VEVENT")
|
||
|
)
|
||
|
),
|
||
|
/**
|
||
|
* @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);
|
||
|
|
||
|
const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]);
|
||
|
const calendar_object : _zeitbild.type_calendar_object = await _zeitbild.service.calendar.get(calendar_id, user_id);
|
||
|
const event_id : int = parseInt(stuff.query_parameters["event_id"]);
|
||
|
const event_object : _zeitbild.type_event_object = await _zeitbild.service.resource.event_get(calendar_object.resource_id, event_id);
|
||
|
|
||
|
return Promise.resolve(
|
||
|
{
|
||
|
"status_code": 200,
|
||
|
"data": _zeitbild.helpers.ical_vcalendar_from_own_event_list([event_object]),
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|