mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-04 02:39:16 +02:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import {Event} from "../model/event.ts";
|
|
|
|
export async function fetchRoom(): Promise<string[]> {
|
|
const rooms: string[] = [];
|
|
await fetch("/api/rooms")
|
|
.then((response) => {
|
|
return response.json();
|
|
})
|
|
.then((roomsResponse) => {
|
|
roomsResponse.forEach((room: string) => rooms.push(room));
|
|
});
|
|
return rooms;
|
|
}
|
|
|
|
export async function fetchEventsByRoomAndDuration(
|
|
room: string,
|
|
from_date: string,
|
|
to_date: string,
|
|
): Promise<Event[]> {
|
|
const events: Event[] = [];
|
|
await fetch("/api/schedule?room=" + room + "&from=" + from_date + "&to=" + to_date)
|
|
.then((response) => {
|
|
console.log(response);
|
|
return response.json();
|
|
})
|
|
.then((eventsResponse) => {
|
|
console.log("Response:", eventsResponse);
|
|
eventsResponse.forEach((event: Event) =>
|
|
events.push(event));
|
|
}).catch((error) => {
|
|
console.log("Error fetching events: ", error);
|
|
return null;
|
|
})
|
|
console.log("occupations: ", events);
|
|
return events;
|
|
} |