Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Filter out passed events
Browse files Browse the repository at this point in the history
  • Loading branch information
Allypost committed Oct 6, 2020
1 parent b051908 commit 171b62a
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions api/routes/companies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
fixCompany,
fixCompany,
} from "../../helpers/company";
import {
keysFromSnakeToCamelCase,
Expand Down Expand Up @@ -38,14 +38,47 @@ router.get("/participants", cachedFetcher(cacheForMs, async () => {
}));

router.get("/events", cachedFetcher(cacheForMs, async () => {
const { companies, ...events } = await graphQlQuery(participantEventsQuery());
const { companies, ...eventList } = await graphQlQuery(participantEventsQuery());

const { data: panels } = await internalRequest("get", "/panels/list/with-info");

const eventHasNotPassed =
(
{
date,
occuresAt,
occures_at: occuresAtOther,
},
) =>
new Date(date || occuresAt || occuresAtOther) >= new Date()
;

const removePassedEvents =
(
[
key,
events,
],
) =>
[
key,
events.filter(eventHasNotPassed),
]
;

const events = Object.fromEntries(
Object
.entries({
panels,
...eventList,
})
.map(removePassedEvents)
,
);

return keysFromSnakeToCamelCase({
companies: companies.map(fixCompany),
panels: panels.map((id) => id),
...events,
events,
});
}));

Expand Down

0 comments on commit 171b62a

Please sign in to comment.