diff --git a/models/order.js b/models/order.js index 5c2944f..08d36cc 100644 --- a/models/order.js +++ b/models/order.js @@ -33,11 +33,6 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false - }, - give: { - type: DataTypes.BOOLEAN, - allowNull: false, - defaultValue: false } }, { sequelize, diff --git a/models/sandwichCommand.js b/models/sandwichOrder.js similarity index 83% rename from models/sandwichCommand.js rename to models/sandwichOrder.js index 909da0a..7fd6fe7 100644 --- a/models/sandwichCommand.js +++ b/models/sandwichOrder.js @@ -17,6 +17,11 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.DATEONLY, defaultValue: DataTypes.NOW, allowNull: false + }, + give: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false } }, { sequelize, diff --git a/public/javascripts/admin/orders/add.js b/public/javascripts/admin/orders/add.js index 7b201e0..7955e1d 100644 --- a/public/javascripts/admin/orders/add.js +++ b/public/javascripts/admin/orders/add.js @@ -21,7 +21,11 @@ document.getElementById("add-order").addEventListener("click", () => {
- + +
+
+ +
`); document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"}); diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 3270631..161d141 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -248,7 +248,7 @@ p.before-link a::before { width: min-content; } -input::-webkit-calendar-picker-indicator { +input[type="list"]::-webkit-calendar-picker-indicator { display: none;/* remove default arrow */ } diff --git a/routes/admin/orders/edit.js b/routes/admin/orders/edit.js index 56127f9..7d1d810 100644 --- a/routes/admin/orders/edit.js +++ b/routes/admin/orders/edit.js @@ -56,8 +56,12 @@ router.get("/", sessionCheck(3), async (req, res) => { let date = new Date(req.body.dates[s]); + let give = false; + if (req.body.give && req.body.give[s]) + give = req.body.give[s]; + try { - sandwiches.push([sandwich.name, date.toISOString().substring(0, 10)]); + sandwiches.push([sandwich.name, date.toISOString().substring(0, 10), give]); } catch { return error(req, res, "Invalid order edit !", 400, "Invalid date"); } @@ -73,13 +77,11 @@ router.get("/", sessionCheck(3), async (req, res) => { order.lastName = req.body.lastName; if (req.body.paid !== order.paid) order.paid = Boolean(req.body.paid); - if (req.body.give !== order.give) - order.give = Boolean(req.body.give); await order.removeSandwiches(order.Sandwiches); for (let data of sandwiches) try { - await models.SandwichOrder.create({OrderId: order.id, SandwichName: data[0], date: data[1]}); + await models.SandwichOrder.create({OrderId: order.id, SandwichName: data[0], date: data[1], give: data[2]}); } catch (e) { await order.destroy(); error(req, res, "Invalid order !"); diff --git a/routes/orders.js b/routes/orders.js index 468d5bb..e56f90d 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -10,11 +10,11 @@ router.get("/", sessionCheck(2), async (req, res) => { let orders = {}; for (let o of await models.Order.findAll({ - where: {paid: true, give: false}, + where: {paid: true}, include: [{ model: models.Sandwich, through: { - where: {date: date} + where: {date: date, give: false} }, required: true }] @@ -34,9 +34,9 @@ router.get("/", sessionCheck(2), async (req, res) => { if (!req.body.id) return error(req, res, "Missing arg !", 400); - let order = await models.Order.findByPk(req.body.id, {where: {paid: true, give: false}}); + let order = await models.SandwichOrder.findByPk(req.body.id, {where: {give: false}}); if (!order) - return error(req, res, "Invalid command id !", 400); + return error(req, res, "Invalid order id !", 400); order.give = true; await order.save(); diff --git a/routes/utils/addOrder.js b/routes/utils/addOrder.js index 9b80974..6b7214f 100644 --- a/routes/utils/addOrder.js +++ b/routes/utils/addOrder.js @@ -44,8 +44,12 @@ module.exports = async (req, res, args, dateCheck = true) => { } } + let give = false; + if (args.give && args.give[s]) + give = args.give[s]; + try { - sandwiches.push([sandwich.name, date.toISOString().substring(0, 10)]); + sandwiches.push([sandwich.name, date.toISOString().substring(0, 10), give]); } catch { return error(req, res, "Invalid order !", 400, "Invalid date"); } @@ -56,7 +60,6 @@ module.exports = async (req, res, args, dateCheck = true) => { firstName: args.firstName, lastName: args.lastName, paid: Boolean(args.paid), - give: Boolean(args.give), price: price }); @@ -66,7 +69,7 @@ module.exports = async (req, res, args, dateCheck = true) => { for (let data of sandwiches) try { - await models.SandwichOrder.create({OrderId: order.id, SandwichName: data[0], date: data[1]}); + await models.SandwichOrder.create({OrderId: order.id, SandwichName: data[0], date: data[1], give: data[2]}); } catch (e) { await order.destroy(); error(req, res, "Invalid order !", 500); diff --git a/views/admin/orders/add.pug b/views/admin/orders/add.pug index 2142773..314affc 100644 --- a/views/admin/orders/add.pug +++ b/views/admin/orders/add.pug @@ -30,6 +30,9 @@ block content div.field label(for="day1")=__("index.day") + ":" input#day1(type="date" name="dates[1]" required) + div.field + label(for="given1")=__("admin.given") + input#given1(type="checkbox" name="give[1]") div#order-action a#add-order + @@ -38,8 +41,6 @@ block content div.field label(for="paid")=__("admin.paid") input#paid(type="checkbox" name="paid") - label(for="given")=__("admin.given") - input#given(type="checkbox" name="give") div.field input#send(type="submit" value=__("admin.add")) diff --git a/views/admin/orders/edit.pug b/views/admin/orders/edit.pug index 5893736..33a45b2 100644 --- a/views/admin/orders/edit.pug +++ b/views/admin/orders/edit.pug @@ -34,6 +34,9 @@ block content div.field label(for="day"+i)=__("index.day") + ":" input(id="#day"+i type="date" name="dates["+i+"]" value=sandwich.SandwichOrder.date required) + div.field + label(for="given"+i)=__("admin.given") + input(id="given"+i type="checkbox" name="give["+i+"]" checked=sandwich.SandwichOrder.give) div#order-action a#add-order + @@ -45,11 +48,9 @@ block content div.field label(for="paid")=__("admin.paid") input#paid(type="checkbox" name="paid" checked=order.paid) - label(for="given")=__("admin.given") - input#given(type="checkbox" name="give" checked=order.give) div.field - input#send(type="submit" value=__("admin.add")) + input#send(type="submit" value=__("save")) datalist#sandwich-list each sandwich in sandwiches diff --git a/views/mixin.pug b/views/mixin.pug index 07a6dc2..2fa7ff4 100644 --- a/views/mixin.pug +++ b/views/mixin.pug @@ -2,6 +2,6 @@ mixin submit(value) div.recaptcha.recaptcha-cb input(type="submit" value!=value) -mixin list(id, list, name, value="", autocomplete="on", required="false") +mixin list(id, list, name, value="", autocomplete="on", required=false) span.list_arrow input(id=id type="list" list=list name=name value=value autocomplete=autocomplete required=required) diff --git a/views/orders.pug b/views/orders.pug index 95c5a19..8581691 100644 --- a/views/orders.pug +++ b/views/orders.pug @@ -18,7 +18,7 @@ block content each sandwich in order div.sandwich form.give(method="POST" action="/orders/give") - input(type="hidden" name="id" value=id) + input(type="hidden" name="id" value=sandwich.SandwichOrder.id) input.give(type="submit" value="v") h4= sandwich.name