implemented assigning users to events

This commit is contained in:
z1glr
2025-01-23 21:29:08 +00:00
parent 19e7d2b366
commit 00ab161261
8 changed files with 229 additions and 42 deletions

View File

@@ -59,7 +59,7 @@ export async function apiCall<K>(
},
credentials: "include",
method,
body: body !== undefined ? JSON.stringify(body) : undefined,
body: prepareBody(body),
});
return response;
@@ -79,6 +79,19 @@ function getContentType(type: string): string {
}
}
function prepareBody(
body: object | number | string | boolean | undefined,
): BodyInit | undefined {
switch (typeof body) {
case "object":
return JSON.stringify(body);
case "undefined":
return undefined;
default:
return body.toString();
}
}
export function classNames(classNames: Record<string, boolean>): string {
return Object.entries(classNames)
.map(([classString, value]) => {
@@ -157,11 +170,11 @@ export async function getAvailabilities(): Promise<Availability[]> {
const result = await apiCall<Availability[]>("GET", "availabilities");
if (result.ok) {
const tasks = await result.json();
const availabilities = await result.json();
state.patch({ availabilities: tasks });
state.patch({ availabilities: availabilities });
return tasks;
return availabilities;
} else {
return [];
}