Skip to content

Commit

Permalink
[Build]: trigger new build
Browse files Browse the repository at this point in the history
  • Loading branch information
akinfelami committed Apr 26, 2024
2 parents 91e1717 + b3c6c01 commit 88e3807
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion backend/src/events/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ const getEvent = async (eventID: string) => {
});
};

/**
* Returns a boleean indicating whether event is past or not
* @param eventID (String)
* @returns promise with boolean or error
*/
export const isEventPast = async (eventID: string) => {
const currentDateTime = new Date();
const event = (await getEvent(eventID)) as Event;
const eventDate = new Date(event.startDate);
return eventDate < currentDateTime;
};

/**
* Gets all attendees registered for an event
* @param eventID (String)
Expand Down Expand Up @@ -333,8 +345,9 @@ const addAttendee = async (eventID: string, userID: string) => {
var eventDateTimeUnknown = event?.startDate as unknown;
var eventDateTimeString = eventDateTimeUnknown as string;
var textBody = "Your registration was successful.";
const eventIsInThePast = await isEventPast(eventID);

if (process.env.NODE_ENV != "test") {
if (process.env.NODE_ENV != "test" && !eventIsInThePast) {
// creates updated html path with the changed inputs
const updatedHtml = replaceEventInputs(
stringEventUpdate,
Expand All @@ -350,6 +363,9 @@ const addAttendee = async (eventID: string, userID: string) => {
updatedHtml
);
}
if (eventIsInThePast) {
return Promise.reject("Event is past, cannot enroll new user");
}
return await prisma.eventEnrollment.create({
data: {
event: {
Expand Down Expand Up @@ -427,6 +443,10 @@ const deleteAttendee = async (
* @returns promise with event or error
*/
const updateEventStatus = async (eventID: string, status: string) => {
if (await isEventPast(eventID)) {
return Promise.reject("Event is past, cannot update status");
}

return await prisma.event.update({
where: {
id: eventID,
Expand Down

0 comments on commit 88e3807

Please sign in to comment.