Fix a big misspell
This commit is contained in:
parent
6849aff655
commit
7eba97a420
27 changed files with 206 additions and 206 deletions
12
app.js
12
app.js
|
@ -9,12 +9,12 @@ let indexRouter = require("./routes/index");
|
||||||
let registerRouter = require("./routes/register");
|
let registerRouter = require("./routes/register");
|
||||||
let loginRouter = require("./routes/login");
|
let loginRouter = require("./routes/login");
|
||||||
let logoutRouter = require("./routes/logout");
|
let logoutRouter = require("./routes/logout");
|
||||||
let commandRouter = require("./routes/command");
|
let orderRouter = require("./routes/order");
|
||||||
let ordersRouter = require("./routes/commands");
|
let ordersRouter = require("./routes/orders");
|
||||||
let sandwichesRouter = require("./routes/sandwiches");
|
let sandwichesRouter = require("./routes/sandwiches");
|
||||||
let profileRouter = require("./routes/profile");
|
let profileRouter = require("./routes/profile");
|
||||||
let adminRouter = require("./routes/admin");
|
let adminRouter = require("./routes/admin");
|
||||||
let adminCommandsRouter = require("./routes/admin/commands");
|
let adminOrdersRouter = require("./routes/admin/orders");
|
||||||
|
|
||||||
let app = express();
|
let app = express();
|
||||||
let sess = {
|
let sess = {
|
||||||
|
@ -50,12 +50,12 @@ app.use("/", indexRouter);
|
||||||
app.use("/register", registerRouter);
|
app.use("/register", registerRouter);
|
||||||
app.use("/login", loginRouter);
|
app.use("/login", loginRouter);
|
||||||
app.use("/logout", logoutRouter);
|
app.use("/logout", logoutRouter);
|
||||||
app.use("/command", commandRouter);
|
app.use("/order", orderRouter);
|
||||||
app.use("/commands", ordersRouter);
|
app.use("/orders", ordersRouter);
|
||||||
app.use("/sandwiches", sandwichesRouter);
|
app.use("/sandwiches", sandwichesRouter);
|
||||||
app.use("/profile", profileRouter);
|
app.use("/profile", profileRouter);
|
||||||
app.use("/admin", adminRouter);
|
app.use("/admin", adminRouter);
|
||||||
app.use("/admin/commands", adminCommandsRouter);
|
app.use("/admin/orders", adminOrdersRouter);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
|
|
|
@ -37,9 +37,9 @@
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
"title": "Administration",
|
"title": "Administration",
|
||||||
"commandsManagement": "Commands management",
|
"ordersManagement": "Orders management",
|
||||||
"ordersDate": "Orders date",
|
"ordersDate": "Orders date",
|
||||||
"manageCommands": "Manage commands",
|
"manageOrders": "Manage orders",
|
||||||
"sandwichManagement": "Sandwich management",
|
"sandwichManagement": "Sandwich management",
|
||||||
"manageSandwiches": "Manage sandwiches",
|
"manageSandwiches": "Manage sandwiches",
|
||||||
"userManagement": "User management",
|
"userManagement": "User management",
|
||||||
|
@ -51,8 +51,8 @@
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"department": "Department",
|
"department": "Department",
|
||||||
"commands": "Commands",
|
"orders": "Orders",
|
||||||
"sandwiches": "Sandwiches",
|
"sandwiches": "Sandwiches",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"command": "Command"
|
"order": "Order"
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"IT": "BDE Info",
|
"IT": "BDE Info",
|
||||||
"made": "Fait avec ❤️ par",
|
"made": "Fait avec ❤️ par",
|
||||||
"contact": "Contact",
|
"contact": "Contact",
|
||||||
"orderIssue": "Problème de ordere"
|
"orderIssue": "Problème de commande"
|
||||||
},
|
},
|
||||||
"index": {
|
"index": {
|
||||||
"welcome": "Bienvenue sur Sandwiches Order Doua",
|
"welcome": "Bienvenue sur Sandwiches Order Doua",
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
},
|
},
|
||||||
"login": {
|
"login": {
|
||||||
"title": "Se connecter",
|
"title": "Se connecter",
|
||||||
"submit": "Connection"
|
"submit": "Connexion"
|
||||||
},
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"title": "S'inscrire",
|
"title": "S'inscrire",
|
||||||
|
@ -37,9 +37,9 @@
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
"title": "Administration",
|
"title": "Administration",
|
||||||
"commandsManagement": "Gestion des orderes",
|
"ordersManagement": "Gestion des commandes",
|
||||||
"ordersDate": "Date des orderes",
|
"ordersDate": "Date des commandes",
|
||||||
"manageCommands": "Gérer les orderes",
|
"manageOrders": "Gérer les commandes",
|
||||||
"sandwichManagement": "Gestion des sandwichs",
|
"sandwichManagement": "Gestion des sandwichs",
|
||||||
"manageSandwiches": "Gérer les sandwichs",
|
"manageSandwiches": "Gérer les sandwichs",
|
||||||
"userManagement": "Gestion des utilisateurs",
|
"userManagement": "Gestion des utilisateurs",
|
||||||
|
@ -51,8 +51,8 @@
|
||||||
"password": "Mot de passe",
|
"password": "Mot de passe",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"department": "Département",
|
"department": "Département",
|
||||||
"commands": "Orderes",
|
"orders": "Commandes",
|
||||||
"sandwiches": "Sandwichs",
|
"sandwiches": "Sandwichs",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"command": "Order"
|
"order": "Commande"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ const {
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class Department extends Model {
|
class Department extends Model {
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
Department.hasMany(models.Command);
|
Department.hasMany(models.Order);
|
||||||
Department.hasMany(models.User);
|
Department.hasMany(models.User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ const {
|
||||||
Model
|
Model
|
||||||
} = require("sequelize");
|
} = require("sequelize");
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class Command extends Model {
|
class Order extends Model {
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
Command.belongsToMany(models.Sandwich, {through: {model: models.SandwichCommand, unique: false}});
|
Order.belongsToMany(models.Sandwich, {through: {model: models.SandwichOrder, unique: false}});
|
||||||
Command.belongsTo(models.Department);
|
Order.belongsTo(models.Department);
|
||||||
Command.belongsTo(models.User);
|
Order.belongsTo(models.User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.init({
|
Order.init({
|
||||||
firstName: {
|
firstName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
|
@ -30,7 +30,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: "Command",
|
modelName: "Order",
|
||||||
});
|
});
|
||||||
return Command;
|
return Order;
|
||||||
};
|
};
|
|
@ -5,7 +5,7 @@ const {
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class Sandwich extends Model {
|
class Sandwich extends Model {
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
Sandwich.belongsToMany(models.Command, {through: {model: models.SandwichCommand, unique: false}});
|
Sandwich.belongsToMany(models.Order, {through: {model: models.SandwichOrder, unique: false}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Sandwich.init({
|
Sandwich.init({
|
||||||
|
|
|
@ -3,11 +3,11 @@ const {
|
||||||
Model
|
Model
|
||||||
} = require("sequelize");
|
} = require("sequelize");
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class SandwichCommand extends Model {
|
class SandwichOrder extends Model {
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SandwichCommand.init({
|
SandwichOrder.init({
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -20,7 +20,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: "SandwichCommand",
|
modelName: "SandwichOrder",
|
||||||
});
|
});
|
||||||
return SandwichCommand;
|
return SandwichOrder;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
class User extends Model {
|
class User extends Model {
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
User.belongsTo(models.Department);
|
User.belongsTo(models.Department);
|
||||||
User.hasMany(models.Command);
|
User.hasMany(models.Order);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPassword(password) {
|
checkPassword(password) {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
const commandAction = document.getElementById("command-action");
|
const orderAction = document.getElementById("order-action");
|
||||||
const rmButton = document.getElementById("remove-command");
|
const rmButton = document.getElementById("remove-order");
|
||||||
const locals = {
|
const locals = {
|
||||||
command: document.querySelector("#command1>h2").innerHTML.replace(" 1", ""),
|
order: document.querySelector("#order1>h2").innerHTML.replace(" 1", ""),
|
||||||
sandwich: document.querySelector("label[for='sandwich1']").innerHTML,
|
sandwich: document.querySelector("label[for='sandwich1']").innerHTML,
|
||||||
day: document.querySelector("label[for='day1']").innerHTML
|
day: document.querySelector("label[for='day1']").innerHTML
|
||||||
};
|
};
|
||||||
|
|
||||||
function lastCommandId() {
|
function lastOrderId() {
|
||||||
let list = document.querySelectorAll("div.command h2");
|
let list = document.querySelectorAll("div.order h2");
|
||||||
return parseInt(list[list.length-1].innerText.replace("Command ", ""));
|
return parseInt(list[list.length-1].innerText.replace(locals.order+" ", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("add-command").addEventListener("click", () => {
|
document.getElementById("add-order").addEventListener("click", () => {
|
||||||
let id = lastCommandId() + 1;
|
let id = lastOrderId() + 1;
|
||||||
commandAction.insertAdjacentHTML("beforebegin", `<div id="command${id}" class="command">
|
orderAction.insertAdjacentHTML("beforebegin", `<div id="order${id}" class="order">
|
||||||
<h2>${locals.command} ${id}</h2>
|
<h2>${locals.order} ${id}</h2>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="sandwich${id}">${locals.sandwich}</label>
|
<label for="sandwich${id}">${locals.sandwich}</label>
|
||||||
<input id="sandwich${id}" type="list" list="sandwich-list" name="sandwich${id}" autocomplete="off" required>
|
<input id="sandwich${id}" type="list" list="sandwich-list" name="sandwich${id}" autocomplete="off" required>
|
||||||
|
@ -24,13 +24,13 @@ document.getElementById("add-command").addEventListener("click", () => {
|
||||||
<input id="da${id}y" type="date" name="date${id}" required>
|
<input id="da${id}y" type="date" name="date${id}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>`);
|
</div>`);
|
||||||
document.getElementById("command"+lastCommandId()).scrollIntoView({behavior: "smooth"});
|
document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"});
|
||||||
rmButton.classList.remove("hide");
|
rmButton.classList.remove("hide");
|
||||||
});
|
});
|
||||||
|
|
||||||
rmButton.addEventListener("click", () => {
|
rmButton.addEventListener("click", () => {
|
||||||
let id = lastCommandId();
|
let id = lastOrderId();
|
||||||
document.getElementById("command"+id).remove();
|
document.getElementById("order"+id).remove();
|
||||||
if (id === 2)
|
if (id === 2)
|
||||||
rmButton.classList.add("hide");
|
rmButton.classList.add("hide");
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,7 +38,7 @@ a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#command {
|
#order {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -70,12 +70,12 @@ a {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#command-action {
|
#order-action {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add-command, #remove-command {
|
#add-order, #remove-order {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
margin: auto auto 1em auto;
|
margin: auto auto 1em auto;
|
||||||
|
@ -185,33 +185,33 @@ p.before-link a::before {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#userCommandList {
|
#userOrderList {
|
||||||
max-height: 90%;
|
max-height: 90%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement {
|
#ordersManagement {
|
||||||
max-height: 90%;
|
max-height: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement h2 {
|
#ordersManagement h2 {
|
||||||
margin: 0.2em 0 0 0;
|
margin: 0.2em 0 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement>div {
|
#ordersManagement>div {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement .command {
|
#ordersManagement .order {
|
||||||
box-shadow: 0.5em 0.5em 0.5em rgba(0, 0, 255, .2);
|
box-shadow: 0.5em 0.5em 0.5em rgba(0, 0, 255, .2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement .command .title, #commandsManagement .sandwich {
|
#ordersManagement .order .title, #ordersManagement .sandwich {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#commandsManagement input[value="x"] {
|
#ordersManagement input[value="x"] {
|
||||||
border: none;
|
border: none;
|
||||||
background-color: unset;
|
background-color: unset;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
let express = require("express");
|
|
||||||
let router = express.Router();
|
|
||||||
let sessionCheck = require("../../middlewares/sessionCheck");
|
|
||||||
let models = require("../../models");
|
|
||||||
|
|
||||||
|
|
||||||
router.get("/", sessionCheck(3), async (req, res) => {
|
|
||||||
res.render("admin/commands", {
|
|
||||||
title: "SOD - Commands administration",
|
|
||||||
user: req.session.user,
|
|
||||||
commands: await models.Command.findAll({include: models.Sandwich, order: ["date"]})
|
|
||||||
});
|
|
||||||
}).post("/command/delete", sessionCheck(3), async (req, res) => {
|
|
||||||
if (!req.body.id)
|
|
||||||
res.render("error", {message: "Fail to remove command !", error: {status: "Missing args"}});
|
|
||||||
try {
|
|
||||||
await (await models.Command.findByPk(req.body.id)).destroy();
|
|
||||||
res.redirect("/admin/commands");
|
|
||||||
} catch (e) {
|
|
||||||
res.render("error", {message: "Fail to remove command !", error: {}});
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}).post("/sandwich/delete", sessionCheck(3), async (req, res) => {
|
|
||||||
if (!req.body.id)
|
|
||||||
res.render("error", {message: "Fail to remove sandwich !", error: {status: "Missing args"}});
|
|
||||||
try {
|
|
||||||
let sandwich = await models.SandwichCommand.findByPk(req.body.id);
|
|
||||||
let command = await models.Command.findByPk(sandwich.CommandId, {include: models.Sandwich});
|
|
||||||
await sandwich.destroy();
|
|
||||||
await command.reload();
|
|
||||||
if (!command.Sandwiches.length)
|
|
||||||
await command.destroy();
|
|
||||||
res.redirect("/admin/commands");
|
|
||||||
} catch (e) {
|
|
||||||
res.render("error", {message: "Fail to remove sandwich !", error: {}});
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
40
routes/admin/orders.js
Normal file
40
routes/admin/orders.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
let express = require("express");
|
||||||
|
let router = express.Router();
|
||||||
|
let sessionCheck = require("../../middlewares/sessionCheck");
|
||||||
|
let models = require("../../models");
|
||||||
|
|
||||||
|
|
||||||
|
router.get("/", sessionCheck(3), async (req, res) => {
|
||||||
|
res.render("admin/orders", {
|
||||||
|
title: "SOD - Orders administration",
|
||||||
|
user: req.session.user,
|
||||||
|
orders: await models.Order.findAll({include: models.Sandwich, order: ["date"]})
|
||||||
|
});
|
||||||
|
}).post("/order/delete", sessionCheck(3), async (req, res) => {
|
||||||
|
if (!req.body.id)
|
||||||
|
res.render("error", {message: "Fail to remove order !", error: {status: "Missing args"}});
|
||||||
|
try {
|
||||||
|
await (await models.Order.findByPk(req.body.id)).destroy();
|
||||||
|
res.redirect("/admin/orders");
|
||||||
|
} catch (e) {
|
||||||
|
res.render("error", {message: "Fail to remove order !", error: {}});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}).post("/sandwich/delete", sessionCheck(3), async (req, res) => {
|
||||||
|
if (!req.body.id)
|
||||||
|
res.render("error", {message: "Fail to remove sandwich !", error: {status: "Missing args"}});
|
||||||
|
try {
|
||||||
|
let sandwich = await models.SandwichOrder.findByPk(req.body.id);
|
||||||
|
let order = await models.Order.findByPk(sandwich.OrderId, {include: models.Sandwich});
|
||||||
|
await sandwich.destroy();
|
||||||
|
await order.reload();
|
||||||
|
if (!order.Sandwiches.length)
|
||||||
|
await order.destroy();
|
||||||
|
res.redirect("/admin/orders");
|
||||||
|
} catch (e) {
|
||||||
|
res.render("error", {message: "Fail to remove sandwich !", error: {}});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
|
@ -1,29 +0,0 @@
|
||||||
let express = require("express");
|
|
||||||
let router = express.Router();
|
|
||||||
let sessionCheck = require("../middlewares/sessionCheck");
|
|
||||||
let models = require("../models");
|
|
||||||
|
|
||||||
|
|
||||||
router.get("/", sessionCheck(2), async (req, res) => {
|
|
||||||
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
|
|
||||||
|
|
||||||
let commands = {};
|
|
||||||
for (let i of await models.SandwichCommand.findAll({where: {date: date}})) {
|
|
||||||
i.Command = await models.Command.findByPk(i.CommandId);
|
|
||||||
i.Sandwich = await models.Sandwich.findByPk(i.SandwichName);
|
|
||||||
let name = i.Command.firstName + " " + i.Command.lastName;
|
|
||||||
|
|
||||||
if (!(i.Command.DepartmentName in commands))
|
|
||||||
commands[i.Command.DepartmentName] = {};
|
|
||||||
|
|
||||||
if (!(name in commands[i.Command.DepartmentName]))
|
|
||||||
commands[i.Command.DepartmentName][name] = {};
|
|
||||||
|
|
||||||
if (!(i.Command.id in commands[i.Command.DepartmentName][name]))
|
|
||||||
commands[i.Command.DepartmentName][name][i.Command.id] = [];
|
|
||||||
commands[i.Command.DepartmentName][name][i.Command.id].push(i);
|
|
||||||
}
|
|
||||||
res.render("commands", {title: "SOD - Commands", user: req.session.user, commands: commands, date: date});
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
|
@ -5,13 +5,13 @@ let models = require("../models");
|
||||||
|
|
||||||
router.post("/", async (req, res) => {
|
router.post("/", async (req, res) => {
|
||||||
if (!req.body.department || !req.body.firstName || !req.body.lastName || !req.body.sandwich1 || !req.body.date1) {
|
if (!req.body.department || !req.body.firstName || !req.body.lastName || !req.body.sandwich1 || !req.body.date1) {
|
||||||
res.render("error", {message: "Invalid command !", "error": {status: "Missing arguments"}});
|
res.render("error", {message: "Invalid order !", "error": {status: "Missing arguments"}});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let department = await models.Department.findByPk(req.body.department);
|
let department = await models.Department.findByPk(req.body.department);
|
||||||
if (!department) {
|
if (!department) {
|
||||||
res.render("error", {message: "Invalid command !", error: {status: "Invalid department"}});
|
res.render("error", {message: "Invalid order !", error: {status: "Invalid department"}});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ router.post("/", async (req, res) => {
|
||||||
let price = 0;
|
let price = 0;
|
||||||
for (let i = 1; req.body["sandwich" + i] !== undefined; i++) {
|
for (let i = 1; req.body["sandwich" + i] !== undefined; i++) {
|
||||||
if (req.body["date" + i] === undefined) {
|
if (req.body["date" + i] === undefined) {
|
||||||
res.render("error", {message: "Invalid command !", error: {status: "Sandwich without date"}});
|
res.render("error", {message: "Invalid order !", error: {status: "Sandwich without date"}});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sandwich = await models.Sandwich.findByPk(req.body["sandwich" + i]);
|
let sandwich = await models.Sandwich.findByPk(req.body["sandwich" + i]);
|
||||||
if (!sandwich) {
|
if (!sandwich) {
|
||||||
res.render("error", {
|
res.render("error", {
|
||||||
message: "Invalid command !",
|
message: "Invalid order !",
|
||||||
error: {status: "Invalid sandwich: "+req.body["sandwich" + i]}
|
error: {status: "Invalid sandwich: "+req.body["sandwich" + i]}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -35,21 +35,21 @@ router.post("/", async (req, res) => {
|
||||||
price += sandwich.price;
|
price += sandwich.price;
|
||||||
}
|
}
|
||||||
|
|
||||||
let command = await models.Command.create({
|
let order = await models.Order.create({
|
||||||
firstName: req.body.firstName,
|
firstName: req.body.firstName,
|
||||||
lastName: req.body.lastName,
|
lastName: req.body.lastName,
|
||||||
price: price
|
price: price
|
||||||
});
|
});
|
||||||
let user = await models.User.findOne({where: {firstName: req.body.firstName, lastName: req.body.lastName}});
|
let user = await models.User.findOne({where: {firstName: req.body.firstName, lastName: req.body.lastName}});
|
||||||
if (user)
|
if (user)
|
||||||
await command.setUser(user);
|
await order.setUser(user);
|
||||||
await command.setDepartment(department);
|
await order.setDepartment(department);
|
||||||
for (let data of sandwiches)
|
for (let data of sandwiches)
|
||||||
try {
|
try {
|
||||||
await models.SandwichCommand.create({CommandId: command.id, SandwichName: data[0], date: data[1]});
|
await models.SandwichOrder.create({OrderId: order.id, SandwichName: data[0], date: data[1]});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await command.destroy();
|
await order.destroy();
|
||||||
res.render("error", {message: "Invalid command !", error: {status: "Invalid date"}});
|
res.render("error", {message: "Invalid order !", error: {status: "Invalid date"}});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
res.send("Ok");
|
res.send("Ok");
|
29
routes/orders.js
Normal file
29
routes/orders.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
let express = require("express");
|
||||||
|
let router = express.Router();
|
||||||
|
let sessionCheck = require("../middlewares/sessionCheck");
|
||||||
|
let models = require("../models");
|
||||||
|
|
||||||
|
|
||||||
|
router.get("/", sessionCheck(2), async (req, res) => {
|
||||||
|
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
|
||||||
|
|
||||||
|
let orders = {};
|
||||||
|
for (let i of await models.SandwichOrder.findAll({where: {date: date}})) {
|
||||||
|
i.Order = await models.Order.findByPk(i.OrderId);
|
||||||
|
i.Sandwich = await models.Sandwich.findByPk(i.SandwichName);
|
||||||
|
let name = i.Order.firstName + " " + i.Order.lastName;
|
||||||
|
|
||||||
|
if (!(i.Order.DepartmentName in orders))
|
||||||
|
orders[i.Order.DepartmentName] = {};
|
||||||
|
|
||||||
|
if (!(name in orders[i.Order.DepartmentName]))
|
||||||
|
orders[i.Order.DepartmentName][name] = {};
|
||||||
|
|
||||||
|
if (!(i.Order.id in orders[i.Order.DepartmentName][name]))
|
||||||
|
orders[i.Order.DepartmentName][name][i.Order.id] = [];
|
||||||
|
orders[i.Order.DepartmentName][name][i.Order.id].push(i);
|
||||||
|
}
|
||||||
|
res.render("orders", {title: "SOD - Orders", user: req.session.user, orders: orders, date: date});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
|
@ -8,7 +8,7 @@ router.get("/", sessionCheck(0), async (req, res) => {
|
||||||
title: "SOD - Profile",
|
title: "SOD - Profile",
|
||||||
user: req.session.user,
|
user: req.session.user,
|
||||||
departments: await models.Department.findAll(),
|
departments: await models.Department.findAll(),
|
||||||
commands: await models.Command.findAll({
|
orders: await models.Order.findAll({
|
||||||
where: {UserUsername: req.session.user.username},
|
where: {UserUsername: req.session.user.username},
|
||||||
include: models.Sandwich,
|
include: models.Sandwich,
|
||||||
order: ["date"]
|
order: ["date"]
|
||||||
|
@ -39,7 +39,7 @@ router.get("/", sessionCheck(0), async (req, res) => {
|
||||||
else {
|
else {
|
||||||
user.firstName = req.body.firstName;
|
user.firstName = req.body.firstName;
|
||||||
user.lastName = req.body.lastName;
|
user.lastName = req.body.lastName;
|
||||||
for (let c of await models.Command.findAll({where: {
|
for (let c of await models.Order.findAll({where: {
|
||||||
firstName: req.session.user.firstName,
|
firstName: req.session.user.firstName,
|
||||||
lastName: req.session.user.lastName}})) {
|
lastName: req.session.user.lastName}})) {
|
||||||
c.firstName = user.firstName;
|
c.firstName = user.firstName;
|
||||||
|
|
|
@ -40,7 +40,7 @@ router.get("/", async (req, res) => {
|
||||||
await user.setDepartment(department);
|
await user.setDepartment(department);
|
||||||
req.session.user = user;
|
req.session.user = user;
|
||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
for (let c of await models.Command.findAll({where: {
|
for (let c of await models.Order.findAll({where: {
|
||||||
firstName: user.firstName,
|
firstName: user.firstName,
|
||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
UserUsername: null
|
UserUsername: null
|
||||||
|
|
|
@ -11,7 +11,7 @@ router.get("/", sessionCheck(1), async (req, res) => {
|
||||||
res.render("sandwiches", {
|
res.render("sandwiches", {
|
||||||
title: "SOD - Sandwiches",
|
title: "SOD - Sandwiches",
|
||||||
user: req.session.user,
|
user: req.session.user,
|
||||||
sandwiches: await models.SandwichCommand.findAll({
|
sandwiches: await models.SandwichOrder.findAll({
|
||||||
attributes: ["SandwichName", [sequelize.fn("COUNT", sequelize.col("SandwichName")), "number"]],
|
attributes: ["SandwichName", [sequelize.fn("COUNT", sequelize.col("SandwichName")), "number"]],
|
||||||
where: {date: date},
|
where: {date: date},
|
||||||
group: "SandwichName"
|
group: "SandwichName"
|
||||||
|
|
|
@ -174,7 +174,7 @@ describe("Database User test", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Database Command tests", () => {
|
describe("Database Order tests", () => {
|
||||||
let models;
|
let models;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -188,15 +188,15 @@ describe("Database Command tests", () => {
|
||||||
await wipeDatabase(models);
|
await wipeDatabase(models);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Command creation", async () => {
|
it("Order creation", async () => {
|
||||||
expect(await models.Command.create({
|
expect(await models.Order.create({
|
||||||
firstName: "Test",
|
firstName: "Test",
|
||||||
lastName: "Test",
|
lastName: "Test",
|
||||||
price: 1.5
|
price: 1.5
|
||||||
})).to.be.instanceOf(models.Command);
|
})).to.be.instanceOf(models.Order);
|
||||||
});
|
});
|
||||||
it("Command associations", async () => {
|
it("Order associations", async () => {
|
||||||
let testCommand = await models.Command.create({firstName: "Test", lastName: "Test", price: 1.5, },
|
let testOrder = await models.Order.create({firstName: "Test", lastName: "Test", price: 1.5, },
|
||||||
{include: [models.Department, models.Sandwich, models.User]});
|
{include: [models.Department, models.Sandwich, models.User]});
|
||||||
let testDepartment = await models.Department.create({name: "TestDepartment"});
|
let testDepartment = await models.Department.create({name: "TestDepartment"});
|
||||||
let testSandwich = await models.Sandwich.create({name: "TestSandwich", price: 1.5});
|
let testSandwich = await models.Sandwich.create({name: "TestSandwich", price: 1.5});
|
||||||
|
@ -207,19 +207,19 @@ describe("Database Command tests", () => {
|
||||||
lastName: "Test",
|
lastName: "Test",
|
||||||
passwordHash: "test"});
|
passwordHash: "test"});
|
||||||
|
|
||||||
await testCommand.setDepartment(testDepartment);
|
await testOrder.setDepartment(testDepartment);
|
||||||
await testCommand.reload();
|
await testOrder.reload();
|
||||||
expect(testCommand.Department).to.be.instanceOf(models.Department);
|
expect(testOrder.Department).to.be.instanceOf(models.Department);
|
||||||
expect(testCommand.Department.name).to.be.equal(testDepartment.name);
|
expect(testOrder.Department.name).to.be.equal(testDepartment.name);
|
||||||
|
|
||||||
await testCommand.addSandwiches(testSandwich);
|
await testOrder.addSandwiches(testSandwich);
|
||||||
await testCommand.reload();
|
await testOrder.reload();
|
||||||
expect(testCommand.Sandwiches[0]).to.be.instanceOf(models.Sandwich);
|
expect(testOrder.Sandwiches[0]).to.be.instanceOf(models.Sandwich);
|
||||||
expect(testCommand.Sandwiches[0].name).to.be.equal(testSandwich.name);
|
expect(testOrder.Sandwiches[0].name).to.be.equal(testSandwich.name);
|
||||||
|
|
||||||
await testCommand.setUser(testUser);
|
await testOrder.setUser(testUser);
|
||||||
await testCommand.reload();
|
await testOrder.reload();
|
||||||
expect(testCommand.User).to.be.instanceOf(models.User);
|
expect(testOrder.User).to.be.instanceOf(models.User);
|
||||||
expect(testCommand.User.username).to.be.equal(testUser.username);
|
expect(testOrder.User.username).to.be.equal(testUser.username);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -80,9 +80,9 @@ describe("Public pages test", () => {
|
||||||
.get("/sandwiches")
|
.get("/sandwiches")
|
||||||
.expect(302, done);
|
.expect(302, done);
|
||||||
});
|
});
|
||||||
it("Response to /commands", (done) => {
|
it("Response to /orders", (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.get("/commands")
|
.get("/orders")
|
||||||
.expect(302, done);
|
.expect(302, done);
|
||||||
});
|
});
|
||||||
it("Response to /admin", (done) => {
|
it("Response to /admin", (done) => {
|
||||||
|
@ -90,9 +90,9 @@ describe("Public pages test", () => {
|
||||||
.get("/admin")
|
.get("/admin")
|
||||||
.expect(302, done);
|
.expect(302, done);
|
||||||
});
|
});
|
||||||
it("Response to /admin/commands", (done) => {
|
it("Response to /admin/orders", (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.get("/admin/commands")
|
.get("/admin/orders")
|
||||||
.expect(302, done);
|
.expect(302, done);
|
||||||
});
|
});
|
||||||
it("404 everything else", (done) => {
|
it("404 everything else", (done) => {
|
||||||
|
@ -169,9 +169,9 @@ for (let [p, a] of Object.entries({0: [403, 403, 403, 403], 1: [200, 403, 403, 4
|
||||||
.get("/sandwiches")
|
.get("/sandwiches")
|
||||||
.expect(a[0]);
|
.expect(a[0]);
|
||||||
});
|
});
|
||||||
it("Commands page", async () => {
|
it("Orders page", async () => {
|
||||||
await (await getLoginAgent(app))
|
await (await getLoginAgent(app))
|
||||||
.get("/commands")
|
.get("/orders")
|
||||||
.expect(a[1]);
|
.expect(a[1]);
|
||||||
});
|
});
|
||||||
it("Admin page", async () => {
|
it("Admin page", async () => {
|
||||||
|
@ -179,9 +179,9 @@ for (let [p, a] of Object.entries({0: [403, 403, 403, 403], 1: [200, 403, 403, 4
|
||||||
.get("/admin")
|
.get("/admin")
|
||||||
.expect(a[2]);
|
.expect(a[2]);
|
||||||
});
|
});
|
||||||
it("Commands administration page", async () => {
|
it("Orders administration page", async () => {
|
||||||
await (await getLoginAgent(app))
|
await (await getLoginAgent(app))
|
||||||
.get("/admin/commands")
|
.get("/admin/orders")
|
||||||
.expect(a[3]);
|
.expect(a[3]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
extends ../layout
|
|
||||||
|
|
||||||
block content
|
|
||||||
div.card#commandsManagement
|
|
||||||
h1=__("admin.commandsManagement")
|
|
||||||
div
|
|
||||||
each command in commands
|
|
||||||
div.command
|
|
||||||
div.title
|
|
||||||
h2=command.id
|
|
||||||
form(action="/admin/commands/command/delete" method="POST")
|
|
||||||
input.hide(type="number" name="id" value=command.id)
|
|
||||||
input(type="submit" value="x")
|
|
||||||
h3 #{command.firstName} #{command.lastName}
|
|
||||||
each sandwich in command.Sandwiches
|
|
||||||
div.sandwich
|
|
||||||
p #{sandwich.name} - #{sandwich.SandwichCommand.date}
|
|
||||||
form(action="/admin/commands/sandwich/delete" method="POST")
|
|
||||||
input.hide(type="number" name="id" value=sandwich.SandwichCommand.id)
|
|
||||||
input(type="submit" value="x")
|
|
|
@ -4,12 +4,12 @@ block content
|
||||||
div.card
|
div.card
|
||||||
h1=__("admin.title")
|
h1=__("admin.title")
|
||||||
div
|
div
|
||||||
h2=__("admin.commandsManagement")
|
h2=__("admin.ordersManagement")
|
||||||
div.buttons
|
div.buttons
|
||||||
a(href="/admin/commands/date")
|
a(href="/admin/orders/date")
|
||||||
button=__("admin.ordersDate")
|
button=__("admin.ordersDate")
|
||||||
a(href="/admin/commands")
|
a(href="/admin/orders")
|
||||||
button=__("admin.manageCommands")
|
button=__("admin.manageOrders")
|
||||||
|
|
||||||
div
|
div
|
||||||
h2=__("admin.sandwichManagement")
|
h2=__("admin.sandwichManagement")
|
||||||
|
|
20
views/admin/orders.pug
Normal file
20
views/admin/orders.pug
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
extends ../layout
|
||||||
|
|
||||||
|
block content
|
||||||
|
div.card#ordersManagement
|
||||||
|
h1=__("admin.ordersManagement")
|
||||||
|
div
|
||||||
|
each order in orders
|
||||||
|
div.order
|
||||||
|
div.title
|
||||||
|
h2=order.id
|
||||||
|
form(action="/admin/orders/order/delete" method="POST")
|
||||||
|
input.hide(type="number" name="id" value=order.id)
|
||||||
|
input(type="submit" value="x")
|
||||||
|
h3 #{order.firstName} #{order.lastName}
|
||||||
|
each sandwich in order.Sandwiches
|
||||||
|
div.sandwich
|
||||||
|
p #{sandwich.name} - #{sandwich.SandwichOrder.date}
|
||||||
|
form(action="/admin/orders/sandwich/delete" method="POST")
|
||||||
|
input.hide(type="number" name="id" value=sandwich.SandwichOrder.id)
|
||||||
|
input(type="submit" value="x")
|
|
@ -4,7 +4,7 @@ block content
|
||||||
div.card
|
div.card
|
||||||
h1= title
|
h1= title
|
||||||
p=__("index.welcome")
|
p=__("index.welcome")
|
||||||
form#command(action="/command" method="POST")
|
form#order(action="/order" method="POST")
|
||||||
div.field
|
div.field
|
||||||
label(for="department")=__("department")+":"
|
label(for="department")=__("department")+":"
|
||||||
input#department(type="list" list="department-list" name="department" value=user ? user.DepartmentName : "" autocomplete="off" required)
|
input#department(type="list" list="department-list" name="department" value=user ? user.DepartmentName : "" autocomplete="off" required)
|
||||||
|
@ -19,8 +19,8 @@ block content
|
||||||
label(for="lastname")=__("lastName")+":"
|
label(for="lastname")=__("lastName")+":"
|
||||||
input#lastname(type="text" name="lastName" value=user ? user.lastName : "" required)
|
input#lastname(type="text" name="lastName" value=user ? user.lastName : "" required)
|
||||||
|
|
||||||
div#command1.command
|
div#order1.order
|
||||||
h2=__("command")+" 1"
|
h2=__("order")+" 1"
|
||||||
div.field
|
div.field
|
||||||
label(for="sandwich1")=__("index.sandwich")+":"
|
label(for="sandwich1")=__("index.sandwich")+":"
|
||||||
input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required)
|
input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required)
|
||||||
|
@ -28,9 +28,9 @@ block content
|
||||||
label(for="day1")=__("index.day")+":"
|
label(for="day1")=__("index.day")+":"
|
||||||
input#day1(type="date" name="date1" required)
|
input#day1(type="date" name="date1" required)
|
||||||
|
|
||||||
div#command-action
|
div#order-action
|
||||||
a#add-command +
|
a#add-order +
|
||||||
a#remove-command.hide -
|
a#remove-order.hide -
|
||||||
|
|
||||||
div.field
|
div.field
|
||||||
input#send(type="submit" value=__("index.pay"))
|
input#send(type="submit" value=__("index.pay"))
|
||||||
|
|
|
@ -14,7 +14,7 @@ html
|
||||||
a(href="/sandwiches")=__("sandwiches")
|
a(href="/sandwiches")=__("sandwiches")
|
||||||
if user.permissions >= 2
|
if user.permissions >= 2
|
||||||
p -
|
p -
|
||||||
a(href="/commands")=__("commands")
|
a(href="/orders")=__("orders")
|
||||||
if user.permissions >= 3
|
if user.permissions >= 3
|
||||||
p -
|
p -
|
||||||
a(href="/admin")=__("admin.title")
|
a(href="/admin")=__("admin.title")
|
||||||
|
|
|
@ -5,18 +5,18 @@ block content
|
||||||
label(for="date")=__("date")
|
label(for="date")=__("date")
|
||||||
input#date(type="date" value=date)
|
input#date(type="date" value=date)
|
||||||
div#orders.card
|
div#orders.card
|
||||||
h1=__("commands")
|
h1=__("orders")
|
||||||
each user, department in commands
|
each user, department in orders
|
||||||
div.department
|
div.department
|
||||||
h2= department
|
h2= department
|
||||||
each command, name in user
|
each orders, name in user
|
||||||
div.user
|
div.user
|
||||||
h3= name
|
h3= name
|
||||||
each order, id in command
|
each order, id in orders
|
||||||
div.order
|
div.order
|
||||||
h4 #{__("command")} N°#{id}
|
h4 #{__("order")} N°#{id}
|
||||||
each sandwich in order
|
each sandwich in order
|
||||||
div.sandwich
|
div.sandwich
|
||||||
h4= sandwich.Sandwich.name
|
h4= sandwich.Sandwich.name
|
||||||
|
|
||||||
script(src="/javascripts/commands.js")
|
script(src="/javascripts/orders.js")
|
|
@ -30,10 +30,10 @@ block content
|
||||||
each department in departments
|
each department in departments
|
||||||
option(value=department.name)
|
option(value=department.name)
|
||||||
|
|
||||||
div.card#userCommandList
|
div.card#userOrderList
|
||||||
h1=__("commands")
|
h1=__("orders")
|
||||||
each command in commands
|
each order in orders
|
||||||
div
|
div
|
||||||
h2=command.id
|
h2=order.id
|
||||||
each sandwich in command.Sandwiches
|
each sandwich in order.Sandwiches
|
||||||
p #{sandwich.name} - #{sandwich.SandwichCommand.date}
|
p #{sandwich.name} - #{sandwich.SandwichOrder.date}
|
||||||
|
|
Reference in a new issue