forked from athenekilta/ilmomasiina
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add separate admin list for past events
- Loading branch information
1 parent
82cb977
commit f531527
Showing
5 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import type { AdminEventListItem } from "@tietokilta/ilmomasiina-models"; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
/** Determines the effective end date of the event, matching the scope logic in `backend/src/models/event`. */ | ||
function getEffectiveEndDate(event: Pick<AdminEventListItem, "date" | "endDate" | "registrationEndDate">) { | ||
const endDates = [event.endDate, event.date, event.registrationEndDate] | ||
.filter((date): date is string => date != null) | ||
.map((date) => new Date(date).getTime()); | ||
if (!endDates.length) return null; | ||
return endDates.reduce((lhs, rhs) => Math.max(lhs, rhs)); | ||
} | ||
|
||
/** Checks whether the event's effective end date is before now. */ | ||
export function isEventInPast(event: Pick<AdminEventListItem, "date" | "endDate" | "registrationEndDate">) { | ||
const endDate = event.endDate ?? event.date ?? event.registrationEndDate; | ||
return endDate != null && new Date(endDate) < new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); | ||
const endDate = getEffectiveEndDate(event); | ||
return endDate != null && endDate < Date.now(); | ||
} | ||
|
||
/** Checks whether the event is hidden from regular users due to the scope logic in `backend/src/models/event`. */ | ||
export function isEventHiddenFromUsersDueToAge( | ||
event: Pick<AdminEventListItem, "date" | "endDate" | "registrationEndDate">, | ||
) { | ||
const endDate = getEffectiveEndDate(event); | ||
return endDate != null && endDate < Date.now() - 7 * 24 * 60 * 60 * 1000; | ||
} |