Endpoint for getting wine schema.
This is for manual registration of prelottery wines from the admin page.
This commit is contained in:
@@ -169,11 +169,32 @@ const deleteWines = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const wineSchema = (req, res) => {
|
||||||
|
return prelotteryWineRepository
|
||||||
|
.wineSchema()
|
||||||
|
.then(schema =>
|
||||||
|
res.send({
|
||||||
|
schema: schema,
|
||||||
|
message: `Wine schema template.`,
|
||||||
|
success: true
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch(error => {
|
||||||
|
const { statusCode, message } = error;
|
||||||
|
|
||||||
|
return res.status(statusCode || 500).send({
|
||||||
|
success: false,
|
||||||
|
message: message || "Unable to fetch wine schema template."
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
allWines,
|
allWines,
|
||||||
addWines,
|
addWines,
|
||||||
wineById,
|
wineById,
|
||||||
updateWineById,
|
updateWineById,
|
||||||
deleteWineById,
|
deleteWineById,
|
||||||
deleteWines
|
deleteWines,
|
||||||
|
wineSchema
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -70,11 +70,22 @@ const deleteWines = () => {
|
|||||||
return PreLotteryWine.deleteMany();
|
return PreLotteryWine.deleteMany();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const wineSchema = () => {
|
||||||
|
let schema = { ...PreLotteryWine.schema.obj };
|
||||||
|
let nulledSchema = Object.keys(schema).reduce((accumulator, current) => {
|
||||||
|
accumulator[current] = "";
|
||||||
|
return accumulator;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return Promise.resolve(nulledSchema);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
allWines,
|
allWines,
|
||||||
addWines,
|
addWines,
|
||||||
wineById,
|
wineById,
|
||||||
updateWineById,
|
updateWineById,
|
||||||
deleteWineById,
|
deleteWineById,
|
||||||
deleteWines
|
deleteWines,
|
||||||
|
wineSchema
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ router.get("/history/by-date/", historyController.groupByDate);
|
|||||||
// router.delete("/highscore/:id", highscoreController.deletePersonById);
|
// router.delete("/highscore/:id", highscoreController.deletePersonById);
|
||||||
|
|
||||||
router.get("/lottery/wines", prelotteryWineController.allWines);
|
router.get("/lottery/wines", prelotteryWineController.allWines);
|
||||||
|
router.get("/lottery/wine/schema", mustBeAuthenticated, prelotteryWineController.wineSchema);
|
||||||
router.get("/lottery/wine/:id", mustBeAuthenticated, prelotteryWineController.wineById);
|
router.get("/lottery/wine/:id", mustBeAuthenticated, prelotteryWineController.wineById);
|
||||||
router.post("/lottery/wines", mustBeAuthenticated, prelotteryWineController.addWines);
|
router.post("/lottery/wines", mustBeAuthenticated, prelotteryWineController.addWines);
|
||||||
router.delete("/lottery/wines", mustBeAuthenticated, prelotteryWineController.deleteWines);
|
router.delete("/lottery/wines", mustBeAuthenticated, prelotteryWineController.deleteWines);
|
||||||
|
|||||||
Reference in New Issue
Block a user