Skip to content

Commit

Permalink
Update app.ts (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnie4k authored Nov 26, 2023
1 parent 6fe1c48 commit b8d7027
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import OrganizationResolver from './resolvers/OrganizationResolver';
import PublicationResolver from './resolvers/PublicationResolver';
import UserResolver from './resolvers/UserResolver';
import utils from './utils';
import FlyerRepo from './repos/FlyerRepo';
import FlyerRepo, { Actions } from './repos/FlyerRepo';

const main = async () => {
const schema = await buildSchema({
Expand Down Expand Up @@ -146,7 +146,12 @@ const main = async () => {
startDate,
title,
});
await FlyerModel.create(newFlyer);
const flyer = await FlyerModel.create(newFlyer);
NotificationRepo.notifyFlyersForOrganizations(
flyer.id,
' just added a new flyer!',
Actions.Add,
);
return res.status(201).json(newFlyer);
});

Expand Down Expand Up @@ -174,7 +179,7 @@ const main = async () => {

// Get the file from form-data and await the upload service
const imageURL = req.file ? await utils.uploadImage(req.file) : undefined;
await FlyerRepo.editFlyer(
const flyer = await FlyerRepo.editFlyer(
flyerID,
categorySlug,
endDate,
Expand All @@ -185,6 +190,29 @@ const main = async () => {
title,
);

let editedResponse = '';
if ((endDate && location) || (location && startDate)) {
// if endDate and location or startDate and location are nonempty, notification body would return date and location changed
editedResponse = 'changed its date and location';
} else if (endDate && startDate) {
// if both endDate and startDate values changed, the notifcation body would just return that the event changed its date
editedResponse = 'changed its date';
} else if (endDate) {
// if only the endDate changed for the event, then the notification body would print out specifically what the date was changed to
const date = new Date(endDate);
// the format for toDateString is Day of the Week Month Date Year ex: Tue Sep 05 2023
editedResponse = `changed its end date to ${date.toDateString()}`;
} else if (location) {
// if only the location changed for the event, then the notification body would print out specifically what the location was changed to
editedResponse = `changed its location to ${location}`;
} else if (startDate) {
// if only the startDate changed for the event, then the notification body would print out specifically what the date was changed to
const date = new Date(startDate);
// the format for toDateString is Day of the Week Month Date Year ex: Tue Sep 05 2023
editedResponse = `changed its start date to ${date.toDateString()}`;
}

NotificationRepo.notifyFlyersForBookmarks(flyer.id, editedResponse, Actions.Edit);
return res.status(201).json(await FlyerModel.findById(flyerID));
});

Expand Down

0 comments on commit b8d7027

Please sign in to comment.