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:
2021-01-24 10:14:00 +01:00
parent edc4d26647
commit 18d8c2c7ca
2 changed files with 72 additions and 0 deletions

35
api/lottery.js Normal file
View 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
};