Switch give state from order to SandwichOrder
This commit is contained in:
parent
78c8def258
commit
73a9aae4e4
11 changed files with 36 additions and 25 deletions
|
@ -33,11 +33,6 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
},
|
|
||||||
give: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: false
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
|
|
|
@ -17,6 +17,11 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
type: DataTypes.DATEONLY,
|
type: DataTypes.DATEONLY,
|
||||||
defaultValue: DataTypes.NOW,
|
defaultValue: DataTypes.NOW,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
|
},
|
||||||
|
give: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
|
@ -21,7 +21,11 @@ document.getElementById("add-order").addEventListener("click", () => {
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="day${id}">${locals.day}</label>
|
<label for="day${id}">${locals.day}</label>
|
||||||
<input id="da${id}y" type="date" name="dates[${id}]" required>
|
<input id="day${id}" type="date" name="dates[${id}]" required>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="give${id}">${locals.day}</label>
|
||||||
|
<input id="give${id}" type="checkbox" name="give[${id}]">
|
||||||
</div>
|
</div>
|
||||||
</div>`);
|
</div>`);
|
||||||
document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"});
|
document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"});
|
||||||
|
|
|
@ -248,7 +248,7 @@ p.before-link a::before {
|
||||||
width: min-content;
|
width: min-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
input::-webkit-calendar-picker-indicator {
|
input[type="list"]::-webkit-calendar-picker-indicator {
|
||||||
display: none;/* remove default arrow */
|
display: none;/* remove default arrow */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,12 @@ router.get("/", sessionCheck(3), async (req, res) => {
|
||||||
|
|
||||||
let date = new Date(req.body.dates[s]);
|
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 {
|
try {
|
||||||
sandwiches.push([sandwich.name, date.toISOString().substring(0, 10)]);
|
sandwiches.push([sandwich.name, date.toISOString().substring(0, 10), give]);
|
||||||
} catch {
|
} catch {
|
||||||
return error(req, res, "Invalid order edit !", 400, "Invalid date");
|
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;
|
order.lastName = req.body.lastName;
|
||||||
if (req.body.paid !== order.paid)
|
if (req.body.paid !== order.paid)
|
||||||
order.paid = Boolean(req.body.paid);
|
order.paid = Boolean(req.body.paid);
|
||||||
if (req.body.give !== order.give)
|
|
||||||
order.give = Boolean(req.body.give);
|
|
||||||
|
|
||||||
await order.removeSandwiches(order.Sandwiches);
|
await order.removeSandwiches(order.Sandwiches);
|
||||||
for (let data of sandwiches)
|
for (let data of sandwiches)
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
await order.destroy();
|
await order.destroy();
|
||||||
error(req, res, "Invalid order !");
|
error(req, res, "Invalid order !");
|
||||||
|
|
|
@ -10,11 +10,11 @@ router.get("/", sessionCheck(2), async (req, res) => {
|
||||||
|
|
||||||
let orders = {};
|
let orders = {};
|
||||||
for (let o of await models.Order.findAll({
|
for (let o of await models.Order.findAll({
|
||||||
where: {paid: true, give: false},
|
where: {paid: true},
|
||||||
include: [{
|
include: [{
|
||||||
model: models.Sandwich,
|
model: models.Sandwich,
|
||||||
through: {
|
through: {
|
||||||
where: {date: date}
|
where: {date: date, give: false}
|
||||||
},
|
},
|
||||||
required: true
|
required: true
|
||||||
}]
|
}]
|
||||||
|
@ -34,9 +34,9 @@ router.get("/", sessionCheck(2), async (req, res) => {
|
||||||
if (!req.body.id)
|
if (!req.body.id)
|
||||||
return error(req, res, "Missing arg !", 400);
|
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)
|
if (!order)
|
||||||
return error(req, res, "Invalid command id !", 400);
|
return error(req, res, "Invalid order id !", 400);
|
||||||
|
|
||||||
order.give = true;
|
order.give = true;
|
||||||
await order.save();
|
await order.save();
|
||||||
|
|
|
@ -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 {
|
try {
|
||||||
sandwiches.push([sandwich.name, date.toISOString().substring(0, 10)]);
|
sandwiches.push([sandwich.name, date.toISOString().substring(0, 10), give]);
|
||||||
} catch {
|
} catch {
|
||||||
return error(req, res, "Invalid order !", 400, "Invalid date");
|
return error(req, res, "Invalid order !", 400, "Invalid date");
|
||||||
}
|
}
|
||||||
|
@ -56,7 +60,6 @@ module.exports = async (req, res, args, dateCheck = true) => {
|
||||||
firstName: args.firstName,
|
firstName: args.firstName,
|
||||||
lastName: args.lastName,
|
lastName: args.lastName,
|
||||||
paid: Boolean(args.paid),
|
paid: Boolean(args.paid),
|
||||||
give: Boolean(args.give),
|
|
||||||
price: price
|
price: price
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -66,7 +69,7 @@ module.exports = async (req, res, args, dateCheck = true) => {
|
||||||
|
|
||||||
for (let data of sandwiches)
|
for (let data of sandwiches)
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
await order.destroy();
|
await order.destroy();
|
||||||
error(req, res, "Invalid order !", 500);
|
error(req, res, "Invalid order !", 500);
|
||||||
|
|
|
@ -30,6 +30,9 @@ block content
|
||||||
div.field
|
div.field
|
||||||
label(for="day1")=__("index.day") + ":"
|
label(for="day1")=__("index.day") + ":"
|
||||||
input#day1(type="date" name="dates[1]" required)
|
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
|
div#order-action
|
||||||
a#add-order +
|
a#add-order +
|
||||||
|
@ -38,8 +41,6 @@ block content
|
||||||
div.field
|
div.field
|
||||||
label(for="paid")=__("admin.paid")
|
label(for="paid")=__("admin.paid")
|
||||||
input#paid(type="checkbox" name="paid")
|
input#paid(type="checkbox" name="paid")
|
||||||
label(for="given")=__("admin.given")
|
|
||||||
input#given(type="checkbox" name="give")
|
|
||||||
|
|
||||||
div.field
|
div.field
|
||||||
input#send(type="submit" value=__("admin.add"))
|
input#send(type="submit" value=__("admin.add"))
|
||||||
|
|
|
@ -34,6 +34,9 @@ block content
|
||||||
div.field
|
div.field
|
||||||
label(for="day"+i)=__("index.day") + ":"
|
label(for="day"+i)=__("index.day") + ":"
|
||||||
input(id="#day"+i type="date" name="dates["+i+"]" value=sandwich.SandwichOrder.date required)
|
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
|
div#order-action
|
||||||
a#add-order +
|
a#add-order +
|
||||||
|
@ -45,11 +48,9 @@ block content
|
||||||
div.field
|
div.field
|
||||||
label(for="paid")=__("admin.paid")
|
label(for="paid")=__("admin.paid")
|
||||||
input#paid(type="checkbox" name="paid" checked=order.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
|
div.field
|
||||||
input#send(type="submit" value=__("admin.add"))
|
input#send(type="submit" value=__("save"))
|
||||||
|
|
||||||
datalist#sandwich-list
|
datalist#sandwich-list
|
||||||
each sandwich in sandwiches
|
each sandwich in sandwiches
|
||||||
|
|
|
@ -2,6 +2,6 @@ mixin submit(value)
|
||||||
div.recaptcha.recaptcha-cb
|
div.recaptcha.recaptcha-cb
|
||||||
input(type="submit" value!=value)
|
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
|
span.list_arrow
|
||||||
input(id=id type="list" list=list name=name value=value autocomplete=autocomplete required=required)
|
input(id=id type="list" list=list name=name value=value autocomplete=autocomplete required=required)
|
||||||
|
|
|
@ -18,7 +18,7 @@ block content
|
||||||
each sandwich in order
|
each sandwich in order
|
||||||
div.sandwich
|
div.sandwich
|
||||||
form.give(method="POST" action="/orders/give")
|
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")
|
input.give(type="submit" value="v")
|
||||||
h4= sandwich.name
|
h4= sandwich.name
|
||||||
|
|
||||||
|
|
Reference in a new issue