Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/routes/admin/sandwiches/index.js

29 lines
964 B
JavaScript
Raw Normal View History

2020-08-20 11:48:28 +02:00
let express = require("express");
let router = express.Router();
let sessionCheck = require("../../../middlewares/sessionCheck");
let models = require("../../../models");
2020-08-20 12:14:38 +02:00
let error = require("../../utils/error");
2020-08-20 11:48:28 +02:00
router.get("/", sessionCheck(3), async (req, res) => {
res.render("admin/sandwiches/index", {
title: "SOD - Sandwiches administration",
sandwiches: await models.Sandwich.findAll()
});
})
.use("/edit", require("./edit"))
.use("/add", require("./add"))
2020-08-20 11:48:28 +02:00
.get("/delete", sessionCheck(3), async (req, res) => {
if (!req.query.name)
2020-08-20 12:14:38 +02:00
return error(req, res, "Can't remove sandwich !", 400, "Missing arg");
let sandwich = await models.Sandwich.findByPk(req.query.name);
if (!sandwich)
return error(req, res, "Can't remove sandwich !", 400, "Invalid sandwich");
await sandwich.destroy();
res.redirect("/admin/sandwiches");
2020-08-20 11:48:28 +02:00
});
module.exports = router;