mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
interface EventData {
|
||
title: string;
|
||
location: string;
|
||
description: string;
|
||
eventDate: string;
|
||
organisationName: string,
|
||
organisationId: number
|
||
}
|
||
|
||
interface MyAccount {
|
||
userId: number;
|
||
email: string;
|
||
firstName: string;
|
||
lastName: string;
|
||
createdAt: string;
|
||
isOrganisation: boolean;
|
||
organisationId: number;
|
||
}
|
||
|
||
export async function unhideElementById(document: Document, e: string) {
|
||
var element = document.getElementById(e);
|
||
if (element) {
|
||
element.classList.remove('hidden-before-load');
|
||
}
|
||
}
|
||
|
||
export async function getEvent(id: string): Promise<EventData> {
|
||
const res = await fetch("/api/events/" + id);
|
||
if (!res.ok) {
|
||
throw Error("To wydarzenie nie istnieje");
|
||
}
|
||
const events = await res.json();
|
||
return events;
|
||
}
|
||
|
||
export async function getMyAccount(): Promise<MyAccount> {
|
||
const res = await fetch("/api/auth/my_account");
|
||
if (!res.ok) {
|
||
throw Error("U<>ytkownik niezalogowany!");
|
||
}
|
||
const data = await res.json();
|
||
return data;
|
||
}
|
||
|
||
export async function getMyRegisteredEventIds(): Promise<number[]> {
|
||
const res = await fetch("/api/auth/my_events");
|
||
|
||
if (!res.ok) {
|
||
throw Error("Użytkownik niezalogowany!");
|
||
}
|
||
|
||
const events = await res.json();
|
||
|
||
return events.map((event: { eventId: number }) => event.eventId);
|
||
}
|