feat(backend) passando parametro para retornar os resultados raw
parent
b15fd47c8b
commit
bbc3dbb047
|
@ -11,8 +11,8 @@ import Queue from "../models/Queue";
|
|||
import UserOnlineTime from "../models/UserOnlineTime";
|
||||
|
||||
import { Op, Sequelize, literal } from "sequelize";
|
||||
import format from 'date-fns/format';
|
||||
import ptBR from 'date-fns/locale/pt-BR';
|
||||
import format from "date-fns/format";
|
||||
import ptBR from "date-fns/locale/pt-BR";
|
||||
import { splitDateTime } from "../helpers/SplitDateTime";
|
||||
import ListUserOnlineOffline from "../services/UserServices/ListUsersOnlineOfflineService";
|
||||
import ListUserParamiterService from "../services/UserServices/ListUserParamiterService";
|
||||
|
@ -23,7 +23,6 @@ import CountTicketsByUserQueue from "../services/UserServices/CountTicketsByUser
|
|||
|
||||
import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser";
|
||||
|
||||
|
||||
// import { filter } from "bluebird";
|
||||
|
||||
import { getIO } from "../libs/socket";
|
||||
|
@ -39,82 +38,125 @@ type IndexQuery = {
|
|||
type ReportOnQueue = {
|
||||
userId: string;
|
||||
identifier: string;
|
||||
}
|
||||
|
||||
|
||||
export const reportUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
||||
};
|
||||
|
||||
export const reportUserByDateStartDateEnd = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
if (req.user.profile !== "master" && req.user.profile !== "admin") {
|
||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||
}
|
||||
|
||||
const { userId, startDate, endDate, pageNumber } = req.query as IndexQuery
|
||||
const { userId, startDate, endDate, pageNumber } = req.query as IndexQuery;
|
||||
|
||||
const { tickets, count, hasMore } = await ShowTicketReport({ userId, startDate, endDate, pageNumber });
|
||||
const { tickets, count, hasMore } = await ShowTicketReport({
|
||||
userId,
|
||||
startDate,
|
||||
endDate,
|
||||
pageNumber
|
||||
});
|
||||
|
||||
return res.status(200).json({ tickets, count, hasMore });
|
||||
};
|
||||
|
||||
|
||||
export const reportUserService = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
export const reportUserService = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
if (req.user.profile !== "master" && req.user.profile !== "admin") {
|
||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||
}
|
||||
const { userId, startDate, endDate } = req.query as IndexQuery
|
||||
const { userId, startDate, endDate } = req.query as IndexQuery;
|
||||
|
||||
let usersProfile = await ListUserParamiterService({
|
||||
profile: "user",
|
||||
raw: true
|
||||
});
|
||||
|
||||
let usersProfile = await ListUserParamiterService({ profile: 'user' })
|
||||
const sumUserOlineTime = await ShowUserServiceReport({
|
||||
startDate,
|
||||
endDate,
|
||||
userId
|
||||
});
|
||||
const closedByUser = await ShowUserServiceReport({
|
||||
startDate,
|
||||
endDate,
|
||||
ticketStatus: "closed",
|
||||
userId
|
||||
});
|
||||
const openByUser = await ShowUserServiceReport({
|
||||
startDate,
|
||||
endDate,
|
||||
ticketStatus: "open",
|
||||
userId
|
||||
});
|
||||
|
||||
const sumUserOlineTime = await ShowUserServiceReport({ startDate, endDate, userId });
|
||||
const closedByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'closed', userId });
|
||||
const openByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'open', userId });
|
||||
let dateTime = splitDateTime(
|
||||
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
||||
);
|
||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate });
|
||||
|
||||
let dateTime = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate })
|
||||
const openByUserOnQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "open",
|
||||
clientChatStart: true
|
||||
});
|
||||
const openByUserOutQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "open",
|
||||
clientChatStart: false
|
||||
});
|
||||
|
||||
const openByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: true })
|
||||
const openByUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'open', clientChatStart: false })
|
||||
|
||||
const closedByUserOnQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: true })
|
||||
const closedUserOutQueue = await CountTicketsByUserQueue({ startDate: startDate, endDate: endDate, status: 'closed', clientChatStart: false })
|
||||
const closedByUserOnQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "closed",
|
||||
clientChatStart: true
|
||||
});
|
||||
const closedUserOutQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "closed",
|
||||
clientChatStart: false
|
||||
});
|
||||
|
||||
// let openQueueInOut = openByUserOnQueue.concat(openByUserOutQueue)
|
||||
// let closedQueueInOut = closedByUserOnQueue.concat(closedUserOutQueue)
|
||||
|
||||
const queuesByUser = await ShowQueuesByUser({ profile: "user" });
|
||||
|
||||
const queuesByUser = await ShowQueuesByUser({ profile: 'user' })
|
||||
|
||||
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue)
|
||||
let openCloseOutQueue = openByUserOutQueue.concat(closedUserOutQueue)
|
||||
|
||||
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue);
|
||||
let openCloseOutQueue = openByUserOutQueue.concat(closedUserOutQueue);
|
||||
|
||||
// console.log('onlineUsers: ',JSON.parse(JSON.stringify(onlineUsers)))
|
||||
// console.log('sumUserOlineTime: ', JSON.parse(JSON.stringify(sumUserOlineTime)))
|
||||
|
||||
for (let i = 0; i < queuesByUser.length; i++) {
|
||||
|
||||
queuesByUser[i].countOpen = 0
|
||||
queuesByUser[i].countClosed = 0
|
||||
queuesByUser[i].countOpen = 0;
|
||||
queuesByUser[i].countClosed = 0;
|
||||
|
||||
for (let x = 0; x < openCloseOnQueue.length; x++) {
|
||||
if ((queuesByUser[i].userId == openCloseOnQueue[x].userId) &&
|
||||
(queuesByUser[i].queueId == openCloseOnQueue[x].queueId && openCloseOnQueue[x].status == 'open')) {
|
||||
queuesByUser[i].countOpen = openCloseOnQueue[x].totAttendance
|
||||
}
|
||||
else if ((queuesByUser[i].userId == openCloseOnQueue[x].userId) &&
|
||||
(queuesByUser[i].queueId == openCloseOnQueue[x].queueId && openCloseOnQueue[x].status == 'closed')) {
|
||||
queuesByUser[i].countClosed = openCloseOnQueue[x].totAttendance
|
||||
}
|
||||
|
||||
if (
|
||||
queuesByUser[i].userId == openCloseOnQueue[x].userId &&
|
||||
queuesByUser[i].queueId == openCloseOnQueue[x].queueId &&
|
||||
openCloseOnQueue[x].status == "open"
|
||||
) {
|
||||
queuesByUser[i].countOpen = openCloseOnQueue[x].totAttendance;
|
||||
} else if (
|
||||
queuesByUser[i].userId == openCloseOnQueue[x].userId &&
|
||||
queuesByUser[i].queueId == openCloseOnQueue[x].queueId &&
|
||||
openCloseOnQueue[x].status == "closed"
|
||||
) {
|
||||
queuesByUser[i].countClosed = openCloseOnQueue[x].totAttendance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
usersProfile.map((user: any) => {
|
||||
|
||||
let index = sumUserOlineTime.findIndex((e: any) => e.userId == user.id)
|
||||
let index = sumUserOlineTime.findIndex((e: any) => e.userId == user.id);
|
||||
|
||||
if (index != -1) {
|
||||
user.sumOnlineTime = sumUserOlineTime[index];
|
||||
|
@ -122,101 +164,97 @@ export const reportUserService = async (req: Request, res: Response): Promise<Re
|
|||
// console.log('user.sumOlineTime: 'user.sumOnlineTime)
|
||||
}
|
||||
|
||||
index = closedByUser.findIndex((e: any) => e.userId == user.id)
|
||||
index = closedByUser.findIndex((e: any) => e.userId == user.id);
|
||||
|
||||
if (index != -1) {
|
||||
user.sumClosed = closedByUser[index];
|
||||
}
|
||||
|
||||
index = openByUser.findIndex((e: any) => e.userId == user.id)
|
||||
index = openByUser.findIndex((e: any) => e.userId == user.id);
|
||||
|
||||
if (index != -1) {
|
||||
user.sumOpen = openByUser[index]
|
||||
user.sumOpen = openByUser[index];
|
||||
}
|
||||
|
||||
|
||||
// OPEN, CLOSED TICKETS STARTED BY USERS
|
||||
let openClosedOutQueue = {}
|
||||
let open = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'open')
|
||||
let closed = openCloseOutQueue.filter((e) => e.userId == user.id && e.status == 'closed')
|
||||
let openClosedOutQueue = {};
|
||||
let open = openCloseOutQueue.filter(
|
||||
e => e.userId == user.id && e.status == "open"
|
||||
);
|
||||
let closed = openCloseOutQueue.filter(
|
||||
e => e.userId == user.id && e.status == "closed"
|
||||
);
|
||||
|
||||
openClosedOutQueue = {
|
||||
...openClosedOutQueue,
|
||||
userId: user.id,
|
||||
countOpen: open && open.length > 0 ? open[0].totAttendance : 0,
|
||||
countClosed: closed && closed.length > 0 ? closed[0].totAttendance : 0
|
||||
}
|
||||
|
||||
user.openClosedOutQueue = openClosedOutQueue
|
||||
|
||||
|
||||
// OPEN, CLOSED TICKETS STARTED BY CLIENTS
|
||||
let openClosedInQueue = queuesByUser.filter((e) => e.userId == user.id)
|
||||
|
||||
if (openClosedInQueue && openClosedInQueue.length > 0) {
|
||||
user.openClosedInQueue = openClosedInQueue
|
||||
}
|
||||
|
||||
|
||||
index = onlineUsers.findIndex((e: any) => e.userId == user.id)
|
||||
|
||||
if (index != -1) {
|
||||
user.statusOnline = onlineUsers[index]
|
||||
}
|
||||
|
||||
if (startDate.length > 0 && startDate.split('-').length == 3) {
|
||||
let date = startDate.split('-')
|
||||
user.startDate = `${date[2]}/${date[1]}/${date[0]}`
|
||||
}
|
||||
|
||||
if (endDate.length > 0 && endDate.split('-').length == 3) {
|
||||
let date = endDate.split('-')
|
||||
user.endDate = `${date[2]}/${date[1]}/${date[0]}`
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return res.status(200).json({usersProfile: usersProfile});
|
||||
|
||||
};
|
||||
|
||||
user.openClosedOutQueue = openClosedOutQueue;
|
||||
|
||||
// OPEN, CLOSED TICKETS STARTED BY CLIENTS
|
||||
let openClosedInQueue = queuesByUser.filter(e => e.userId == user.id);
|
||||
|
||||
export const reportMessagesUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
||||
if (openClosedInQueue && openClosedInQueue.length > 0) {
|
||||
user.openClosedInQueue = openClosedInQueue;
|
||||
}
|
||||
|
||||
index = onlineUsers.findIndex((e: any) => e.userId == user.id);
|
||||
|
||||
if (index != -1) {
|
||||
user.statusOnline = onlineUsers[index];
|
||||
}
|
||||
|
||||
if (startDate.length > 0 && startDate.split("-").length == 3) {
|
||||
let date = startDate.split("-");
|
||||
user.startDate = `${date[2]}/${date[1]}/${date[0]}`;
|
||||
}
|
||||
|
||||
if (endDate.length > 0 && endDate.split("-").length == 3) {
|
||||
let date = endDate.split("-");
|
||||
user.endDate = `${date[2]}/${date[1]}/${date[0]}`;
|
||||
}
|
||||
});
|
||||
|
||||
return res.status(200).json({ usersProfile: usersProfile });
|
||||
};
|
||||
|
||||
export const reportMessagesUserByDateStartDateEnd = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
if (req.user.profile !== "master" && req.user.profile !== "admin") {
|
||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||
}
|
||||
|
||||
const { userId, startDate, endDate } = req.query as IndexQuery
|
||||
const { userId, startDate, endDate } = req.query as IndexQuery;
|
||||
|
||||
let data_query_messages = await ShowMessageReport(userId, startDate, endDate);
|
||||
|
||||
for (var i = 0; i < data_query_messages.length; i++) {
|
||||
|
||||
if (data_query_messages[i].fromMe) {
|
||||
data_query_messages[i].fromMe = 'Atendente'
|
||||
}
|
||||
else {
|
||||
data_query_messages[i].fromMe = 'Cliente'
|
||||
data_query_messages[i].fromMe = "Atendente";
|
||||
} else {
|
||||
data_query_messages[i].fromMe = "Cliente";
|
||||
}
|
||||
|
||||
data_query_messages[i].id = (i + 1)
|
||||
data_query_messages[i].id = i + 1;
|
||||
|
||||
console.log('data_query_messages: ', data_query_messages[i])
|
||||
console.log("data_query_messages: ", data_query_messages[i]);
|
||||
}
|
||||
|
||||
return res.status(200).json(data_query_messages);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const reportOnQueue = async (req: Request, res: Response): Promise<Response> => {
|
||||
|
||||
export const reportOnQueue = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
// console.log(req.body)
|
||||
|
||||
const { adminId, identifier, queueStatus, file } = req.body
|
||||
const { adminId, identifier, queueStatus, file } = req.body;
|
||||
|
||||
const io = getIO();
|
||||
io.emit("queryOnQueueStatus", {
|
||||
|
@ -229,10 +267,5 @@ export const reportOnQueue = async (req: Request, res: Response): Promise<Respon
|
|||
}
|
||||
});
|
||||
|
||||
return res.status(200).json({ message: 'ok' })
|
||||
return res.status(200).json({ message: "ok" });
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue