Archived
1
0
Fork 0

Fix dates check and management when nothing is set in database

This commit is contained in:
Ethanell 2020-08-25 14:19:20 +02:00
parent 4cc884d03b
commit b9ba035fa3
3 changed files with 10 additions and 5 deletions

View file

@ -11,10 +11,12 @@ router.get("/", sessionCheck(3), async (req, res) => {
if ((!firstDate || !firstDate.value) || (!lastDate || !lastDate.value)) if ((!firstDate || !firstDate.value) || (!lastDate || !lastDate.value))
[firstDate, lastDate] = [undefined, undefined]; [firstDate, lastDate] = [undefined, undefined];
else
[firstDate, lastDate] = [firstDate.value, lastDate.value];
res.render("admin/orders/date", { res.render("admin/orders/date", {
title: "SOD - Orders administration", title: "SOD - Orders administration",
date: {firstDate: firstDate.value, lastDate: lastDate.value} date: {firstDate: firstDate, lastDate: lastDate}
}); });
}).post("/", sessionCheck(3), async (req, res) => { }).post("/", sessionCheck(3), async (req, res) => {
if (!req.body.firstDate || ! req.body.lastDate) if (!req.body.firstDate || ! req.body.lastDate)

View file

@ -4,10 +4,13 @@ let models = require("../models");
router.get("/", async (req, res) => { router.get("/", async (req, res) => {
let now = new Date(); 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); firstDate = new Date(firstDate.value);
if (firstDate.getTime() < now.getTime()) if (firstDate.getTime() < now.getTime())
firstDate = now; firstDate = now;
} else } else
@ -21,7 +24,7 @@ router.get("/", async (req, res) => {
sandwiches: await models.Sandwich.findAll(), sandwiches: await models.Sandwich.findAll(),
date: { date: {
firstDate: firstDate, firstDate: firstDate,
lastDate: await models.Data.findByPk("lastDate") lastDate: lastDate
} }
}); });
}); });

View file

@ -26,7 +26,7 @@ block content
input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required) input#sandwich1(type="list" list="sandwich-list" name="sandwich1" autocomplete="off" required)
div.field div.field
label(for="day1")=__("index.day")+":" 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 div#order-action
a#add-order + a#add-order +