@@ -0,0 +1,41 @@
|
||||
const API_BASE_URL = process.env.ANNOUNCEMENT_API || "http://localhost:3000";
|
||||
|
||||
export type Announcement = {
|
||||
id: number;
|
||||
text_content?: string;
|
||||
author: string;
|
||||
flags: Flag[];
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
};
|
||||
|
||||
export enum Flag {
|
||||
SHOW_ALL_ENTRIES
|
||||
}
|
||||
|
||||
export type AnnouncementResponse = {
|
||||
[date: string]: Announcement[];
|
||||
}
|
||||
|
||||
export default async function getAnnouncements(dates: string[]): Promise<AnnouncementResponse> {
|
||||
if (dates.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const url = new URL(`/v1/announcements/${dates.join(",")}`, API_BASE_URL).toString();
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (e) {
|
||||
console.error("Some random ahh error:", e);
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user