Add sandwich administration add to routes
This commit is contained in:
parent
3c5185496f
commit
83ed17efc4
9 changed files with 54 additions and 9 deletions
2
app.js
2
app.js
|
@ -58,7 +58,7 @@ app.use("/admin", adminRouter);
|
|||
// catch 404 and forward to error handler
|
||||
app.use((req, res) => {
|
||||
res.status(404);
|
||||
res.render("error", {message: "Page not found", "error": {}})
|
||||
res.render("error", {title: "SOD - Page not found", user: req.session.user, message: "Page not found", "error": {}})
|
||||
});
|
||||
|
||||
// error handler
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
},
|
||||
"index": {
|
||||
"welcome": "Welcome to Sandwiches Order Doua",
|
||||
"sandwich": "Sandwich",
|
||||
"day": "Day",
|
||||
"pay": "Pay"
|
||||
},
|
||||
|
@ -47,7 +46,8 @@
|
|||
"edit": "Edit",
|
||||
"remove": "Remove",
|
||||
"name": "Name,",
|
||||
"price": "Price"
|
||||
"price": "Price",
|
||||
"new": "New"
|
||||
},
|
||||
"firstName": "First name",
|
||||
"lastName": "Last name",
|
||||
|
@ -59,5 +59,6 @@
|
|||
"sandwiches": "Sandwiches",
|
||||
"date": "Date",
|
||||
"order": "Order",
|
||||
"save": "Save"
|
||||
"save": "Save",
|
||||
"sandwich": "Sandwich"
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
},
|
||||
"index": {
|
||||
"welcome": "Bienvenue sur Sandwiches Order Doua",
|
||||
"sandwich": "Sandwich",
|
||||
"day": "Jour",
|
||||
"pay": "Payer"
|
||||
},
|
||||
|
@ -47,7 +46,8 @@
|
|||
"edit": "Éditer",
|
||||
"remove": "Supprimer",
|
||||
"name": "Nom",
|
||||
"price": "Prix"
|
||||
"price": "Prix",
|
||||
"new": "Nouveau"
|
||||
},
|
||||
"firstName": "Prénom",
|
||||
"lastName": "Nom de famille",
|
||||
|
@ -59,5 +59,6 @@
|
|||
"sandwiches": "Sandwichs",
|
||||
"date": "Date",
|
||||
"order": "Commande",
|
||||
"save": "Enregistrer"
|
||||
"save": "Enregistrer",
|
||||
"sandwich": "Sandwich"
|
||||
}
|
|
@ -217,6 +217,10 @@ p.before-link a::before {
|
|||
cursor: pointer;
|
||||
}
|
||||
|
||||
#sandwichesManagement>a>button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (hover: none) and (pointer: coarse) {
|
||||
body {
|
||||
font-size: xx-large;
|
||||
|
|
23
routes/admin/sandwiches/add.js
Normal file
23
routes/admin/sandwiches/add.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
let express = require("express");
|
||||
let router = express.Router();
|
||||
let sessionCheck = require("../../../middlewares/sessionCheck");
|
||||
let models = require("../../../models");
|
||||
let error = require("../../utils/error");
|
||||
|
||||
router.get("/", sessionCheck(3), (req, res) => {
|
||||
res.render("admin/sandwiches/add", {
|
||||
title: "SOD - Sandwiches administration",
|
||||
user: req.session.user
|
||||
});
|
||||
}).post("/", sessionCheck(3), async (req, res) => {
|
||||
if (!req.body.name || !req.body.price)
|
||||
return error(req, res, "Fail to add sandwich !", 400, "Missing arg");
|
||||
|
||||
if (await models.Sandwich.findByPk(req.body.name))
|
||||
return error(req, res, "Fail to add sandwich", 400, "Name already used");
|
||||
|
||||
await models.Sandwich.create({name: req.body.name, price: req.body.price});
|
||||
res.redirect("/admin/sandwiches");
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -13,6 +13,7 @@ router.get("/", sessionCheck(3), async (req, res) => {
|
|||
});
|
||||
})
|
||||
.use("/edit", require("./edit"))
|
||||
.use("/add", require("./add"))
|
||||
.get("/delete", sessionCheck(3), async (req, res) => {
|
||||
if (!req.query.name)
|
||||
return error(req, res, "Can't remove sandwich !", 400, "Missing arg");
|
||||
|
|
14
views/admin/sandwiches/add.pug
Normal file
14
views/admin/sandwiches/add.pug
Normal file
|
@ -0,0 +1,14 @@
|
|||
extends ../../layout
|
||||
|
||||
block content
|
||||
div.card#sandwichesManagement
|
||||
h1=__("admin.new")+" "+__("sandwich")
|
||||
form(action="/admin/sandwiches/add" method="POST")
|
||||
div.field
|
||||
label(for="name")=__("admin.name")+":"
|
||||
input#name(type="text" name="name" required)
|
||||
div.field
|
||||
label(for="price")=__("admin.price") + ":"
|
||||
input#price(type="number" min="0" step="any" name="price" value="0" required)
|
||||
div.field
|
||||
input(type="submit" value=__("admin.add"))
|
|
@ -3,7 +3,8 @@ extends ../../layout
|
|||
block content
|
||||
div.card#sandwichesManagement
|
||||
h1=__("admin.sandwichManagement")
|
||||
input.add(type="button" value=__("admin.add"))
|
||||
a.add(href="/admin/sandwiches/add")
|
||||
button=__("admin.add")
|
||||
div
|
||||
each sandwich in sandwiches
|
||||
div.sandwich
|
||||
|
|
|
@ -22,7 +22,7 @@ block content
|
|||
div#order1.order
|
||||
h2=__("order")+" 1"
|
||||
div.field
|
||||
label(for="sandwich1")=__("index.sandwich")+":"
|
||||
label(for="sandwich1")=__("sandwich")+":"
|
||||
input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required)
|
||||
div.field
|
||||
label(for="day1")=__("index.day")+":"
|
||||
|
|
Reference in a new issue