Archived
1
0
Fork 0

Add disabled option for sandwiches and departments

This commit is contained in:
Ethanell 2020-09-30 11:35:24 +02:00
parent df5ef943d2
commit 405690094f
20 changed files with 60 additions and 19 deletions

View file

@ -74,7 +74,8 @@
"lastDate": "Last date",
"paid": "Paid",
"given": "Given",
"chooseUser": "Choose an user"
"chooseUser": "Choose an user",
"enable": "Enable"
},
"payment": {
"payment": "Payment",

View file

@ -74,7 +74,8 @@
"lastDate": "Dernière date",
"paid": "Payé",
"given": "Donné",
"chooseUser": "Choisissez un utilisateur"
"chooseUser": "Choisissez un utilisateur",
"enable": "Activer"
},
"payment": {
"payment": "Paiement",

View file

@ -13,6 +13,11 @@ module.exports = (sequelize, DataTypes) => {
name: {
type: DataTypes.STRING,
primaryKey: true
},
enable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
sequelize,

View file

@ -16,6 +16,11 @@ module.exports = (sequelize, DataTypes) => {
price: {
type: DataTypes.FLOAT,
allowNull: false
},
enable: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
}
}, {
sequelize,

View file

@ -15,7 +15,7 @@ router.get("/", sessionCheck(3), (req, res) => {
if (await models.Department.findByPk(req.body.name))
return error(req, res, "Fail to add department", 400, "Name already used");
await models.Department.create({name: req.body.name});
await models.Department.create({name: req.body.name, enable: !!req.body.enable});
res.redirect("/admin/departments");
});

View file

@ -24,7 +24,10 @@ router.get("/", sessionCheck(3), async (req, res) => {
if (!department)
return error(req, res, "Fail to edit department !", 400, "Invalid department name");
if (department.enable !== req.body.enable)
department.enable = !!req.body.enable;
await department.save();
if (req.body.newName && req.body.newName !== department.name)
await models.Department.update({name: req.body.newName}, {where: {name: req.body.name}});

View file

@ -6,9 +6,7 @@ let models = require("../../models");
router.get("/", sessionCheck(3), async (req, res) => {
res.render("admin/index", {
title: "SOD - Administration",
sandwiches: await models.Sandwich.findAll(),
users: await models.User.findAll()
title: "SOD - Administration"
});
})
.use("/orders", require("./orders"))

View file

@ -8,8 +8,8 @@ const addOrder = require("../../utils/addOrder");
router.get("/", sessionCheck(3), async (req, res) => {
res.render("admin/orders/add", {
title: "SOD - Orders administration",
departments: await models.Department.findAll(),
sandwiches: await models.Sandwich.findAll(),
departments: await models.Department.findAll({where: {enable: true}}),
sandwiches: await models.Sandwich.findAll({where: {enable: true}}),
users: await models.User.findAll()
});
}).post("/", sessionCheck(3), async (req, res) => {

View file

@ -15,7 +15,7 @@ router.get("/", sessionCheck(3), (req, res) => {
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});
await models.Sandwich.create({name: req.body.name, price: req.body.price, enable: !!req.body.enable});
res.redirect("/admin/sandwiches");
});

View file

@ -26,9 +26,13 @@ router.get("/", sessionCheck(3), async (req, res) => {
if (req.body.price && req.body.price !== sandwich.price)
sandwich.price = req.body.price;
if(req.body.enable !== sandwich.enable)
sandwich.enable = !!req.body.enable;
await sandwich.save();
if (req.body.newName && req.body.newName !== sandwich.name)
await models.Sandwich.update({name: req.body.newName}, {where: {name: req.body.name}});
res.redirect("/admin/sandwiches");
});

View file

@ -7,7 +7,7 @@ let userCreate = require("../../utils/userCreate");
router.get("/", sessionCheck(3), async (req, res) => {
res.render("admin/users/add", {
title: "SOD - Users administration",
departments: await models.Department.findAll()
departments: await models.Department.findAll({where: {enable: true}})
});
}).post("/", sessionCheck(3), async (req, res) => {
let user = await userCreate(req, res);

View file

@ -20,8 +20,8 @@ router.get("/", async (req, res) => {
res.render("index", {
title: "SOD - Home",
departments: await models.Department.findAll(),
sandwiches: await models.Sandwich.findAll(),
departments: await models.Department.findAll({where: {enable: true}}),
sandwiches: await models.Sandwich.findAll({where: {enable: true}}),
date: {
firstDate: firstDate,
lastDate: lastDate

View file

@ -9,7 +9,7 @@ let error = require("./utils/error");
router.get("/", sessionCheck(0), async (req, res) => {
res.render("profile", {
title: "SOD - Profile",
departments: await models.Department.findAll(),
departments: await models.Department.findAll({where: {enable: true}}),
orders: await models.Order.findAll({
where: {UserUsername: req.session.user.username, paid: true},
include: models.Sandwich,

View file

@ -9,7 +9,7 @@ router.get("/", async (req, res) => {
if (req.session.user)
res.redirect("/");
else
res.render("register", {title: "SOD - register", departments: await models.Department.findAll()});
res.render("register", {title: "SOD - register", departments: await models.Department.findAll({where: {enable: true}})});
})
.post("/", reCaptcha, async (req, res) => {
let user = await userCreate(req, res);

View file

@ -6,7 +6,7 @@ module.exports = async (req, res, args, dateCheck = true) => {
args.sandwiches.length !== args.dates.length)
return error(req, res, "Invalid order !", 400, "Missing arguments");
let department = await models.Department.findByPk(args.department);
let department = await models.Department.findByPk(args.department, {where: {enable: true}});
if (!department)
return error(req, res, "Invalid order !", 400, "Invalid department");
@ -20,7 +20,7 @@ module.exports = async (req, res, args, dateCheck = true) => {
if (!args.dates[s])
return error(req, res, "Invalid order !", 400, "Sandwich without date");
let sandwich = await models.Sandwich.findByPk(args.sandwiches[s]);
let sandwich = await models.Sandwich.findByPk(args.sandwiches[s], {where: {enable: true}});
if (!sandwich)
return error(req, res, "Invalid order !", 400, "Invalid sandwich: "+args.sandwiches[s]);

View file

@ -18,7 +18,7 @@ module.exports = async (req, res) => {
if (await models.User.findOne({where: {email: req.body.email}}))
return error(req, res, "Invalid register !", 400, "Email already used");
let department = await models.Department.findByPk(req.body.department);
let department = await models.Department.findByPk(req.body.department, {where: {enable: true}});
if (!department)
return error(req, res, "Invalid register !", 400, "Invalid department");

View file

@ -9,6 +9,12 @@ block content
div.input-field.col.s12
label(for="name")=__("admin.name")+":"
input#name(type="text" name="name" required)
div.row
div.input-field.col.s12
p
label(for="enable")
input#enable(type="checkbox" name="enable" checked)
span=__("admin.enable")
div.row.center
div.input-field.col.s12
+submit(__("admin.add"))

View file

@ -8,8 +8,14 @@ block content
input.hide(type="text" name="name" value=department.name required)
div.row
div.input-field.col.s12
label(for="name")=__("admin.name")+":"
input#name(type="text" name="newName" value=department.name required)
label(for="name")=__("admin.name")+":"
div.row
div.input-field.col.s12
p
label(for="enable")
input#enable(type="checkbox" name="enable" checked=department.enable)
span=__("admin.enable")
div.row.center
div.input-field.col.s12
+submit(__("save"))

View file

@ -13,6 +13,12 @@ block content
div.input-field.col.s12
label(for="price")=__("admin.price") + ":"
input#price(type="number" min="0" step="any" name="price" value="0" required)
div.row
div.input-field.col.s12
p
label(for="enable")
input#enable(type="checkbox" name="enable" checked)
span=__("admin.enable")
div.row.center
div.input-field.col.s12
+submit(__("admin.add"))

View file

@ -14,6 +14,12 @@ block content
div.input-field.col.s12
label(for="price")=__("admin.price") + ":"
input#price(type="number" min="0" step="any" name="price" value=sandwich.price required)
div.row
div.input-field.col.s12
p
label(for="enable")
input#enable(type="checkbox" name="enable" checked=sandwich.enable)
span=__("admin.enable")
div.row.center
div.input-field.col.s12
+submit(__("save"))