diff --git a/routes/admin/orders/date.js b/routes/admin/orders/date.js index ebd829b..765076b 100644 --- a/routes/admin/orders/date.js +++ b/routes/admin/orders/date.js @@ -11,10 +11,12 @@ router.get("/", sessionCheck(3), async (req, res) => { if ((!firstDate || !firstDate.value) || (!lastDate || !lastDate.value)) [firstDate, lastDate] = [undefined, undefined]; + else + [firstDate, lastDate] = [firstDate.value, lastDate.value]; res.render("admin/orders/date", { title: "SOD - Orders administration", - date: {firstDate: firstDate.value, lastDate: lastDate.value} + date: {firstDate: firstDate, lastDate: lastDate} }); }).post("/", sessionCheck(3), async (req, res) => { if (!req.body.firstDate || ! req.body.lastDate) diff --git a/routes/index.js b/routes/index.js index 902d16b..9b9e9a8 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,10 +4,13 @@ let models = require("../models"); router.get("/", async (req, res) => { let now = new Date(); - let firstDate = await models.Data.findByPk("firstDate"); + let [firstDate, lastDate] = [await models.Data.findByPk("firstDate"), + await models.Data.findByPk("lastDate")]; - if (firstDate && firstDate.value) { + if (firstDate && lastDate && firstDate.value && lastDate.value) { + lastDate = lastDate.value; firstDate = new Date(firstDate.value); + if (firstDate.getTime() < now.getTime()) firstDate = now; } else @@ -21,7 +24,7 @@ router.get("/", async (req, res) => { sandwiches: await models.Sandwich.findAll(), date: { firstDate: firstDate, - lastDate: await models.Data.findByPk("lastDate") + lastDate: lastDate } }); }); diff --git a/views/index.pug b/views/index.pug index 352aea7..f698338 100644 --- a/views/index.pug +++ b/views/index.pug @@ -26,7 +26,7 @@ block content input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required) div.field label(for="day1")=__("index.day")+":" - input#day1(type="date" min=date ? date.firstDate : "" max=date ? date.lastDate.value : "" name="date1" required) + input#day1(type="date" min=date.firstDate ? date.firstDate : "" max=date.lastDate ? date.lastDate : "" name="date1" required) div#order-action a#add-order +