mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-16 11:32:26 +01:00
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { Module } from "../model/module.ts";
|
|
|
|
export async function createIndividualFeed(modules: Module[]): Promise<string> {
|
|
let token = "";
|
|
|
|
await fetch("/api/createFeed", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(modules),
|
|
})
|
|
.then((response) => {
|
|
return response.json();
|
|
})
|
|
.then((response) => {
|
|
token = response;
|
|
});
|
|
return token;
|
|
}
|
|
|
|
export async function saveIndividualFeed(
|
|
token: string,
|
|
modules: Module[],
|
|
): Promise<string> {
|
|
await fetch("/api/collections/feeds/records/" + token, {
|
|
method: "PATCH",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: '{"modules":' + JSON.stringify(modules) + "}",
|
|
})
|
|
.then((response) => {
|
|
return response.json();
|
|
})
|
|
.then((response) => {
|
|
token = response;
|
|
});
|
|
return token;
|
|
}
|
|
|
|
export async function deleteIndividualFeed(token: string): Promise<void> {
|
|
await fetch("/api/feed?token=" + token, {
|
|
method: "DELETE",
|
|
}).then ((response) => {
|
|
if (response.ok) {
|
|
return Promise.resolve(response);
|
|
} else {
|
|
return Promise.reject(response);
|
|
}
|
|
}).catch((error) => {
|
|
return Promise.reject(error);
|
|
});
|
|
|
|
}
|