2024-09-18 18:17:25 +02:00
|
|
|
|
|
|
|
namespace _zeitbild.service.resource
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export function add(
|
2024-09-21 11:05:24 +02:00
|
|
|
resource_object : _zeitbild.type_resource_object
|
|
|
|
) : Promise<_zeitbild.type_resource_id>
|
2024-09-18 18:17:25 +02:00
|
|
|
{
|
|
|
|
return _zeitbild.repository.resource.create(resource_object);
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:50:32 +02:00
|
|
|
|
2024-09-30 12:01:40 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function event_get(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
|
|
|
local_resource_event_id : _zeitbild.type_local_resource_event_id
|
|
|
|
) : Promise<_zeitbild.type_event_object>
|
|
|
|
{
|
|
|
|
const resource_object : _zeitbild.type_resource_object = await _zeitbild.repository.resource.read(
|
|
|
|
resource_id
|
|
|
|
);
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
|
|
|
const event_object : _zeitbild.type_event_object = await _zeitbild.repository.resource.local_resource_event_read(
|
|
|
|
resource_id,
|
|
|
|
local_resource_event_id
|
|
|
|
);
|
|
|
|
return Promise.resolve<_zeitbild.type_event_object>(event_object);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
// TODO
|
|
|
|
return Promise.reject(new Error("not implemented"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// @ts-ignore
|
|
|
|
throw (new Error("unhandled resource kind: " + resource_object.kind));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-25 14:50:32 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function event_add(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
|
|
|
event_object : _zeitbild.type_event_object
|
2024-09-26 10:33:33 +02:00
|
|
|
) : Promise<_zeitbild.type_local_resource_event_id>
|
2024-09-25 14:50:32 +02:00
|
|
|
{
|
2024-09-25 15:28:25 +02:00
|
|
|
const resource_object : _zeitbild.type_resource_object = await _zeitbild.repository.resource.read(
|
2024-09-25 14:50:32 +02:00
|
|
|
resource_id
|
|
|
|
);
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
2024-09-26 10:33:33 +02:00
|
|
|
const local_resource_event_id : _zeitbild.type_local_resource_event_id = await _zeitbild.repository.resource.local_resource_event_create(
|
2024-09-25 14:50:32 +02:00
|
|
|
resource_id,
|
2024-09-26 10:33:33 +02:00
|
|
|
event_object
|
2024-09-25 14:50:32 +02:00
|
|
|
);
|
2024-09-26 10:33:33 +02:00
|
|
|
return Promise.resolve<_zeitbild.type_local_resource_event_id>(local_resource_event_id);
|
2024-09-25 14:50:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
if (resource_object.data.read_only) {
|
|
|
|
return Promise.reject(new Error("can not add event to read only caldav resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// TODO
|
|
|
|
return Promise.reject(new Error("not implemented"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2024-09-25 15:28:25 +02:00
|
|
|
// @ts-ignore
|
2024-09-30 12:01:40 +02:00
|
|
|
throw (new Error("unhandled resource kind: " + resource_object.kind));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function event_change(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
|
|
|
local_resource_event_id : _zeitbild.type_local_resource_event_id,
|
|
|
|
event_object : _zeitbild.type_event_object
|
|
|
|
) : Promise<void>
|
|
|
|
{
|
|
|
|
const resource_object : _zeitbild.type_resource_object = await _zeitbild.repository.resource.read(
|
|
|
|
resource_id
|
|
|
|
);
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
|
|
|
await _zeitbild.repository.resource.local_resource_event_update(
|
|
|
|
resource_id,
|
|
|
|
local_resource_event_id,
|
|
|
|
event_object
|
|
|
|
);
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
if (resource_object.data.read_only) {
|
|
|
|
return Promise.reject(new Error("can not change event of read only caldav resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// TODO
|
|
|
|
return Promise.reject(new Error("not implemented"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// @ts-ignore
|
2024-09-25 14:50:32 +02:00
|
|
|
throw (new Error("unhandled resource kind: " + resource_object.kind));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function event_remove(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
2024-09-26 10:33:33 +02:00
|
|
|
local_resource_event_id : _zeitbild.type_local_resource_event_id
|
2024-09-25 14:50:32 +02:00
|
|
|
) : Promise<void>
|
|
|
|
{
|
2024-09-25 15:28:25 +02:00
|
|
|
const resource_object : _zeitbild.type_resource_object = await _zeitbild.repository.resource.read(
|
2024-09-25 14:50:32 +02:00
|
|
|
resource_id
|
|
|
|
);
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
|
|
|
await _zeitbild.repository.resource.local_resource_event_delete(
|
|
|
|
resource_id,
|
2024-09-26 10:33:33 +02:00
|
|
|
local_resource_event_id
|
2024-09-25 14:50:32 +02:00
|
|
|
);
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
if (resource_object.data.read_only) {
|
|
|
|
return Promise.reject(new Error("can not delete event from read only caldav resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// TODO
|
|
|
|
return Promise.reject(new Error("not implemented"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2024-09-25 15:28:25 +02:00
|
|
|
// @ts-ignore
|
2024-09-25 14:50:32 +02:00
|
|
|
throw (new Error("unhandled resource kind: " + resource_object.kind));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-18 18:17:25 +02:00
|
|
|
}
|