Compare commits
No commits in common. "76929c41ec4b31efb31ab1fec62ab604a87b5504" and "b05cd7d1d6c65be8d4f140e7ac4020725966dbea" have entirely different histories.
76929c41ec
...
b05cd7d1d6
|
@ -263,6 +263,8 @@ export const reportMessagesUserByDateStartDateEnd = async (
|
|||
}
|
||||
|
||||
data_query_messages[i].id = i + 1;
|
||||
|
||||
console.log("data_query_messages: ", data_query_messages[i]);
|
||||
}
|
||||
|
||||
return res.status(200).json(data_query_messages);
|
||||
|
|
|
@ -18,7 +18,6 @@ import { startOfDay, endOfDay, parseISO, getDate } from "date-fns";
|
|||
import { string } from "yup/lib/locale";
|
||||
import Whatsapp from "../../models/Whatsapp";
|
||||
import Query from "mysql2/typings/mysql/lib/protocol/sequences/Query";
|
||||
import { te } from "date-fns/locale";
|
||||
|
||||
interface Request {
|
||||
userId: string | number;
|
||||
|
@ -44,56 +43,43 @@ const ShowTicketReport = async ({
|
|||
createdOrUpdated = "created",
|
||||
queueId
|
||||
}: Request): Promise<Response> => {
|
||||
// let where_clause: any = {};
|
||||
// let query = "";
|
||||
let where_clause: any = {};
|
||||
let query = "";
|
||||
|
||||
// if (userId !== "0") {
|
||||
// where_clause.userid = userId;
|
||||
// query = `AND t.userId = ${userId}`;
|
||||
// }
|
||||
|
||||
// if (queueId) {
|
||||
// where_clause.queueId = queueId;
|
||||
// query = `AND t.queueId = ${queueId}`;
|
||||
// }
|
||||
|
||||
const createdAtOrUpdatedAt =
|
||||
createdOrUpdated == "created" ? "createdAt" : "updatedAt";
|
||||
|
||||
let where_clause = {};
|
||||
if (userId !== "0") {
|
||||
where_clause.userid = userId;
|
||||
query = `AND t.userId = ${userId}`;
|
||||
}
|
||||
|
||||
if (queueId) {
|
||||
where_clause = {
|
||||
queueId: queueId,
|
||||
[createdAtOrUpdatedAt]: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
} else if (userId == "0") {
|
||||
where_clause = {
|
||||
[createdAtOrUpdatedAt]: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
} else if (userId != "0") {
|
||||
where_clause = {
|
||||
userid: userId,
|
||||
[createdAtOrUpdatedAt]: {
|
||||
[Op.gte]: startDate + " 00:00:00.000000",
|
||||
[Op.lte]: endDate + " 23:59:59.999999"
|
||||
}
|
||||
};
|
||||
where_clause.queueId = queueId;
|
||||
query = `AND t.queueId = ${queueId}`;
|
||||
}
|
||||
|
||||
const limit = 40;
|
||||
const offset = limit * (+pageNumber - 1);
|
||||
|
||||
const createdAtOrUpdatedAt =
|
||||
createdOrUpdated == "created" ? "createdAt" : "updatedAt";
|
||||
|
||||
const _ticketsId = await sequelize.query(
|
||||
`SELECT t.id
|
||||
FROM Tickets t
|
||||
INNER JOIN (
|
||||
SELECT DISTINCT ticketId
|
||||
FROM Messages
|
||||
WHERE ${createdAtOrUpdatedAt} >= '${startDate} 00:00:00' AND ${createdAtOrUpdatedAt} <= '${endDate} 23:59:59'
|
||||
) AS m ON m.ticketId = t.id ${query};`,
|
||||
{ type: QueryTypes.SELECT }
|
||||
);
|
||||
|
||||
let { count, rows: tickets }: any = await Ticket.findAndCountAll({
|
||||
where: where_clause,
|
||||
where: {
|
||||
id: { [Op.in]: _ticketsId.map((t: any) => t.id) }
|
||||
},
|
||||
limit,
|
||||
offset,
|
||||
|
||||
attributes: [
|
||||
"id",
|
||||
"status",
|
||||
|
@ -165,7 +151,9 @@ const ShowTicketReport = async ({
|
|||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
if (tickets.length > 0) {
|
||||
const ticketIds = tickets.map((t: any) => t.id);
|
||||
|
||||
if (ticketIds.length > 0) {
|
||||
const waiting_time: any = await sequelize.query(
|
||||
`SELECT t.id as ticketId, t.status, TIME_FORMAT(
|
||||
SEC_TO_TIME(
|
||||
|
@ -194,7 +182,7 @@ const ShowTicketReport = async ({
|
|||
JOIN Whatsapps w ON t.whatsappId = w.id
|
||||
JOIN Queues q ON q.id = t.queueId
|
||||
WHERE DATE(m.createdAt) BETWEEN '${startDate} 00:00:00.000000' AND '${endDate} 23:59:59.999999'
|
||||
AND t.id IN (${tickets.map((t: any) => t.id).join()})
|
||||
AND t.id IN (${ticketIds.join()})
|
||||
AND m.createdAt = (SELECT MIN(createdAt) FROM Messages WHERE ticketId = t.id)
|
||||
AND m.fromMe = 0
|
||||
AND t.status IN ('open', 'closed')
|
||||
|
|
|
@ -72,7 +72,7 @@ const PieChart = ({ data = dataExample }) => {
|
|||
return (
|
||||
<Box width="100%" height="100%" position="relative" display="flex">
|
||||
<Box sx={{ position: "absolute" }}>
|
||||
<Title>Tickets status de encerramento</Title>
|
||||
<Title>Tickets Status</Title>
|
||||
</Box>
|
||||
<Box
|
||||
component="ul"
|
||||
|
|
|
@ -258,7 +258,7 @@ const Dashboard = () => {
|
|||
const [usersOnlineInfo, dispatch] = useReducer(reducer, [])
|
||||
const [ticketStatusChange, setStatus] = useState()
|
||||
const [ticketsStatus, setTicktsStatus] = useState({ open: 0, openAll: 0, pending: 0, closed: 0 })
|
||||
const [ticketStatusChatEnd, setTicketStatusChatEnd] = useState([])
|
||||
|
||||
const { user } = useContext(AuthContext)
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -289,15 +289,10 @@ const Dashboard = () => {
|
|||
params: { userId: null, startDate: dateToday, endDate: dateToday },
|
||||
})
|
||||
|
||||
// console.log('data.data: ', data.usersProfile)
|
||||
|
||||
dispatch({ type: "RESET" })
|
||||
dispatch({ type: "LOAD_QUERY", payload: data.usersProfile })
|
||||
|
||||
const { data: ticketStatusChatEndData } = await api.get("/reports/count/statusChatEnd", {
|
||||
params: { startDate: '2024-03-21', endDate: '2024-03-28' },
|
||||
})
|
||||
|
||||
setTicketStatusChatEnd(ticketStatusChatEndData.reportStatusChatEnd)
|
||||
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
@ -511,7 +506,7 @@ const Dashboard = () => {
|
|||
</Grid>
|
||||
<Grid item xs={12} sm={12} md={6} lg={6}>
|
||||
<Paper className={classes.fixedHeightPaper} variant="outlined">
|
||||
<PieChart data={ticketStatusChatEnd} />
|
||||
<PieChart data={[]} />
|
||||
</Paper>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
Loading…
Reference in New Issue