Files
vinlottis/api/controllers/lotteryController.js
KevinMidboe 18d8c2c7ca 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.
2021-01-24 10:14:00 +01:00

38 lines
833 B
JavaScript

const path = require("path");
const lotteryRepository = require(path.join(__dirname, "../lottery"));
const allAttendees = (req, res) => {
const isAdmin = req.isAuthenticated();
return lotteryRepository
.allAttendees(isAdmin === "true")
.then(attendees =>
res.send({
attendees: attendees,
success: true
})
)
.catch(error => {
const { statusCode, message } = error;
return res.status(statusCode || 500).send({
success: false,
message: message || "Unable to fetch lottery attendees."
});
});
};
const deleteAttendees = (req, res) => {
return lotteryRepository.deleteAttendees().then(success =>
res.send({
message: "Removed all attendees",
success: success
})
);
};
module.exports = {
allAttendees,
deleteAttendees
};