-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-util.js
More file actions
37 lines (28 loc) · 909 Bytes
/
Copy pathapi-util.js
File metadata and controls
37 lines (28 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export async function getAllEvents() {
const response = await fetch(process.env.ENV_LOCAL_VARIABLE);
const data = await response.json();
const events = [];
for (const key in data) {
events.push({ id: key, ...data[key] });
}
return events;
}
export async function getFeaturedEvents() {
const allEvents = await getAllEvents();
return allEvents.filter((event) => event.isFeatured);
}
export async function getEventById(id) {
const allEvents = await getAllEvents();
return allEvents.find((event) => event.id === id);
}
export async function getFilteredEvents(dateFilter) {
const { year, month } = dateFilter;
const allEvents = await getAllEvents();
let filteredEvents = allEvents.filter((event) => {
const eventDate = new Date(event.date);
return (
eventDate.getFullYear() === year && eventDate.getMonth() === month - 1
);
});
return filteredEvents;
}