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/orders/index.js

28 lines
933 B
JavaScript
Raw Normal View History

2020-08-18 17:54:00 +02:00
let express = require("express");
let router = express.Router();
2020-08-24 23:23:46 +02:00
let sessionCheck = require("../../../middlewares/sessionCheck");
let models = require("../../../models");
let error = require("../../utils/error");
2020-08-18 17:54:00 +02:00
router.get("/", sessionCheck(3), async (req, res) => {
res.render("admin/orders", {
title: "SOD - Orders administration",
orders: await models.Order.findAll({include: models.Sandwich, order: ["date"]})
});
}).get("/delete", sessionCheck(3), async (req, res) => {
if (!req.query.id)
2020-08-20 12:14:38 +02:00
return error(req, res, "Fail to remove order !", 400, "Missing args");
let order = await models.Order.findByPk(req.query.id);
if (!order)
return error(req, res, "Invalid order !", 400);
2020-08-20 12:14:38 +02:00
await order.destroy();
res.redirect("/admin/orders");
}).use("/date", require("./date"))
.use("/add", require("./add"))
.use("/edit", require("./edit"));
2020-08-18 17:54:00 +02:00
module.exports = router;