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))
[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)

View file

@ -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
}
});
});

View file

@ -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 +