-
Notifications
You must be signed in to change notification settings - Fork 0
Fetch User's Upcoming Interested/Attending Events #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4e25cd1
7cc80a8
f094627
0545975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ const { | |
attendeeStatusValidator, | ||
} = require("../../validators/events"); | ||
const { guildIdValidator } = require("../../validators/guilds"); | ||
const { userIdBodyValidator } = require("../../validators/users"); | ||
const { | ||
userIdValidator, | ||
userIdBodyValidator, | ||
} = require("../../validators/users"); | ||
const { validationResult, matchedData } = require("express-validator"); | ||
const DEFAULT_EVENT_LIMIT = 10; | ||
/** | ||
|
@@ -43,7 +46,7 @@ router.get( | |
const events = await EventController.getEvents( | ||
eventLimit, | ||
action, | ||
eventId | ||
eventId, | ||
); | ||
|
||
if (events.length === 0) { | ||
|
@@ -56,10 +59,10 @@ router.get( | |
const firstEventId = events[0].eventId; | ||
const lastEventId = events[events.length - 1].eventId; | ||
const prevCursor = Buffer.from( | ||
`${currentPage - 1}___prev___${firstEventId}` | ||
`${currentPage - 1}___prev___${firstEventId}`, | ||
).toString("base64"); | ||
const nextCursor = Buffer.from( | ||
`${currentPage + 1}___next___${lastEventId}` | ||
`${currentPage + 1}___next___${lastEventId}`, | ||
).toString("base64"); | ||
|
||
// follow-up request, not first request to api route | ||
|
@@ -97,7 +100,7 @@ router.get( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.post( | ||
|
@@ -135,7 +138,7 @@ router.post( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.get( | ||
|
@@ -168,7 +171,7 @@ router.get( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.delete( | ||
|
@@ -203,7 +206,7 @@ router.delete( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.put( | ||
|
@@ -231,7 +234,7 @@ router.put( | |
|
||
const updatedEvent = await EventController.updateEvent( | ||
eventId, | ||
validatedData | ||
validatedData, | ||
); | ||
|
||
response.status(200).json({ | ||
|
@@ -249,7 +252,7 @@ router.put( | |
}); | ||
return; | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.get( | ||
|
@@ -266,9 +269,8 @@ router.get( | |
} | ||
try { | ||
const { eventId } = matchedData(request); | ||
const eventAttendeesData = await EventController.getEventAttendees( | ||
eventId | ||
); | ||
const eventAttendeesData = | ||
await EventController.getEventAttendees(eventId); | ||
response.status(200).json({ | ||
status: "success", | ||
data: { | ||
|
@@ -281,7 +283,7 @@ router.get( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.get( | ||
|
@@ -309,7 +311,7 @@ router.get( | |
//Should return a list of events from the guild that are upcoming and in ascending order | ||
const upcoming = await EventController.getUpcomingEvents( | ||
currDate, | ||
guildId | ||
guildId, | ||
); | ||
|
||
response.status(200).json({ | ||
|
@@ -324,7 +326,7 @@ router.get( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.post( | ||
|
@@ -348,7 +350,7 @@ router.post( | |
const eventAttendeeData = await EventController.updateAttendeeStatus( | ||
eventId, | ||
userId, | ||
"CheckedIn" | ||
"CheckedIn", | ||
); | ||
|
||
response.status(200).json({ | ||
|
@@ -363,7 +365,7 @@ router.post( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.put( | ||
|
@@ -403,7 +405,45 @@ router.put( | |
message: error.message, | ||
}); | ||
} | ||
} | ||
}, | ||
); | ||
|
||
router.get( | ||
"/:userId/events", | ||
Comment on lines
+411
to
+412
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking into it a bit more, I think it makes more sense to move this to the user router instead so it becomes |
||
AuthController.authenticate, | ||
userIdValidator, | ||
async (request, response) => { | ||
const result = validationResult(request); | ||
|
||
// if validation result is not empty, errors occurred | ||
if (!result.isEmpty()) { | ||
response.status(400).json({ | ||
status: "fail", | ||
data: result.array(), | ||
}); | ||
return; | ||
} | ||
const currDate = new Date(); | ||
|
||
const data = matchedData(request); | ||
const userId = data.userId; | ||
|
||
try { | ||
const userEvents = await EventController.getUserEvents(currDate, userId); | ||
|
||
response.status(200).json({ | ||
status: "success", | ||
data: { | ||
upcomingEvents: userEvents, | ||
}, | ||
}); | ||
} catch (error) { | ||
response.status(500).json({ | ||
status: "error", | ||
message: error.message, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
module.exports = router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will be displayed as a list of event info cards for the user, let's sort them by ascending start date for convenience.