Lottery, get/delete attendees.
Changed so get attendees no longer is done in two endpoints, now we use req.isAuthenticated() to check if we want to return full or minimal json data about each attendee.
This commit is contained in:
35
api/lottery.js
Normal file
35
api/lottery.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const path = require("path");
|
||||
const Attendee = require(path.join(__dirname, "/schemas/Attendee"));
|
||||
|
||||
const redactAttendeeInfoMapper = attendee => {
|
||||
return {
|
||||
name: attendee.name,
|
||||
raffles: attendee.red + attendee.blue + attendee.yellow + attendee.green,
|
||||
red: attendee.red,
|
||||
blue: attendee.blue,
|
||||
green: attendee.green,
|
||||
yellow: attendee.yellow
|
||||
};
|
||||
};
|
||||
|
||||
const allAttendees = isAdmin => {
|
||||
if (!isAdmin) {
|
||||
return Attendee.find().then(attendees => attendees.map(redactAttendeeInfoMapper));
|
||||
} else {
|
||||
return Attendee.find();
|
||||
}
|
||||
};
|
||||
|
||||
const deleteAttendees = () => {
|
||||
const io = req.app.get("socketio");
|
||||
|
||||
return Attendee.deleteMany().then(_ => {
|
||||
io.emit("refresh_data", {});
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
allAttendees,
|
||||
deleteAttendees
|
||||
};
|
||||
Reference in New Issue
Block a user