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

@@ -17,6 +17,7 @@
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"date-fns": "^2.15.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",

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,

View File

@@ -518,6 +518,11 @@ d@1, d@^1.0.1:
es5-ext "^0.10.50"
type "^1.0.1"
date-fns@^2.15.0:
version "2.15.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.15.0.tgz#424de6b3778e4e69d3ff27046ec136af58ae5d5f"
integrity sha512-ZCPzAMJZn3rNUvvQIMlXhDr4A+Ar07eLeGsGREoWU19a3Pqf5oYa+ccd+B3F6XVtQY6HANMFdOQ8A+ipFnvJdQ==
debug@2.6.9, debug@^2.2.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"