feat: simple dashboard with current day tickets

This commit is contained in:
canove
2020-07-29 16:22:05 -03:00
parent 83b23529c5
commit a443c82c71
9 changed files with 364 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
const Sequelize = require("sequelize");
const { startOfDay, endOfDay, parseISO } = require("date-fns");
const Ticket = require("../models/Ticket");
const Contact = require("../models/Contact");
@@ -6,19 +7,31 @@ const Contact = require("../models/Contact");
const { getIO } = require("../libs/socket");
exports.index = async (req, res) => {
const { status = "" } = req.query;
const { status = "", date = "" } = req.query;
let whereCondition;
if (!status || status === "open") {
whereCondition = ["pending", "open"];
} else {
whereCondition = [status];
let whereCondition = {};
if (status === "open") {
whereCondition = {
...whereCondition,
status: { [Sequelize.Op.or]: ["pending", "open"] },
};
} else if (status === "closed") {
whereCondition = { ...whereCondition, status: "closed" };
}
if (date) {
whereCondition = {
...whereCondition,
createdAt: {
[Sequelize.Op.between]: [
startOfDay(parseISO(date)),
endOfDay(parseISO(date)),
],
},
};
}
const tickets = await Ticket.findAll({
where: {
status: { [Sequelize.Op.or]: whereCondition },
},
where: whereCondition,
include: [
{
model: Contact,