[add] backend:calendar_add

This commit is contained in:
Fenris Wolf 2024-09-26 10:52:31 +02:00
parent 7d8a4de1ab
commit 485589e3f7
2 changed files with 79 additions and 19 deletions

View file

@ -12,6 +12,36 @@ namespace _zeitbild.frontend_web.backend
) = null; ) = null;
/**
*/
function access_level_encode(
access_level : _zeitbild.frontend_web.type.enum_access_level
) : ("none" | "view" | "edit" | "admin")
{
switch (access_level) {
case _zeitbild.frontend_web.type.enum_access_level.none: return "none";
case _zeitbild.frontend_web.type.enum_access_level.view: return "view";
case _zeitbild.frontend_web.type.enum_access_level.edit: return "edit";
case _zeitbild.frontend_web.type.enum_access_level.admin: return "admin";
}
}
/**
*/
function access_level_decode(
access_level_encoded : ("none" | "view" | "edit" | "admin")
) : _zeitbild.frontend_web.type.enum_access_level
{
switch (access_level_encoded) {
case "none": return _zeitbild.frontend_web.type.enum_access_level.none;
case "view": return _zeitbild.frontend_web.type.enum_access_level.view;
case "edit": return _zeitbild.frontend_web.type.enum_access_level.edit;
case "admin": return _zeitbild.frontend_web.type.enum_access_level.admin;
}
}
/** /**
*/ */
export async function init( export async function init(
@ -221,6 +251,37 @@ namespace _zeitbild.frontend_web.backend
} }
/**
*/
export async function calendar_add(
calendar_object : _zeitbild.frontend_web.type.type_calendar_object
) : Promise<
_zeitbild.frontend_web.type.calendar_id
>
{
return call(
lib_plankton.http.enum_method.post,
"/calendar",
{
"name": calendar_object.name,
"access": {
"default_level": access_level_encode(calendar_object.access.default_level),
"attributed": (
lib_plankton.map.dump(calendar_object.access.attributed)
.map(
(pair) => ({
"user_id": pair.key,
"level": access_level_encode(pair.value),
})
)
)
},
"resource": calendar_object.resource,
}
);
}
/** /**
*/ */
export async function calendar_event_add( export async function calendar_event_add(
@ -233,7 +294,7 @@ namespace _zeitbild.frontend_web.backend
lib_plankton.string.coin( lib_plankton.string.coin(
"/calendar/{{calendar_id}}/event", "/calendar/{{calendar_id}}/event",
{ {
"calendar_id": calendar_id, "calendar_id": calendar_id.toFixed(0),
} }
), ),
event_object event_object
@ -254,8 +315,8 @@ namespace _zeitbild.frontend_web.backend
lib_plankton.string.coin( lib_plankton.string.coin(
"/calendar/{{calendar_id}}/event/{{event_id}}", "/calendar/{{calendar_id}}/event/{{event_id}}",
{ {
"calendar_id": calendar_id, "calendar_id": calendar_id.toFixed(0),
"event_id": event_id, "event_id": event_id.toFixed(0),
} }
), ),
null null

View file

@ -6,13 +6,12 @@ namespace _zeitbild.frontend_web.type
/** /**
*/ */
export type role = ( export enum enum_access_level {
"admin" none,
| view,
"editor" edit,
| admin
"viewer" }
);
/** /**
@ -89,16 +88,16 @@ namespace _zeitbild.frontend_web.type
/** /**
*/ */
export type calendar_object = { export type type_calendar_object = {
name : string; name : string;
public : boolean; access : {
members : Array< default_level : enum_access_level;
{ attributed : lib_plankton.map.type_map<
user_id : user_id; user_id,
role : role; enum_access_level
} >;
>; };
resource_id : resource_id; resource : resource_object;
}; };
} }