-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventCards.js
49 lines (46 loc) · 1.42 KB
/
EventCards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { Events } = require("../models/Events");
const Express = require("express");
const _ = require("lodash");
const router = Express.Router();
//importing middle ware
const AuthenticateUser = require("../middleware/AuthenticateUser");
const RedirectAdminUser = require("../middleware/RedirectAdminUser");
router.get(
"/",
[AuthenticateUser, RedirectAdminUser],
async (request, response) => {
const AllActiveEvents = await Events.find({});
//for debugging purposes
console.log(AllActiveEvents);
var cardViewOutput = [];
AllActiveEvents.forEach((event) => {
cardViewOutput.push(
_.pick(event, [
"_id",
"ImageUrl",
"Title",
"OrganizingClub",
"Description",
"Date",
"ContactDetails",
])
);
});
//for debugging
console.log(cardViewOutput);
response.status(200).send(cardViewOutput);
}
);
//when clicked call this end point using the event id
router.get("/:SelectedEventId", AuthenticateUser, async (request, response) => {
const SelectedEventDetails = await Events.find({
_id: request.params.SelectedEventId,
});
//if no event exists send 400 status
if (!SelectedEventDetails) {
response.status(400).send("Sorry..! Bad Request");
}
// if event exists then render the specific event details and send 200 status code
response.status(200).send(SelectedEventDetails);
});
module.exports = router;