2022-01-15 18:32:46 +00:00
|
|
|
//relatorio
|
|
|
|
|
|
|
|
import { Request, Response } from "express";
|
|
|
|
import AppError from "../errors/AppError";
|
|
|
|
import ShowTicketReport from "../services/TicketServices/ShowTicketReport";
|
2022-04-18 14:12:49 +00:00
|
|
|
import ShowMessageReport from "../services/MessageServices/ShowMessageReport";
|
2022-01-15 18:32:46 +00:00
|
|
|
|
2022-05-06 22:49:45 +00:00
|
|
|
import onlineUserService from "../services/UserServices/CreateOrUpdateOnlineUserService";
|
|
|
|
import User from "../models/User";
|
|
|
|
import Queue from "../models/Queue";
|
|
|
|
import UserOnlineTime from "../models/UserOnlineTime";
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
import { Op, Sequelize,literal } from "sequelize";
|
2022-05-06 22:49:45 +00:00
|
|
|
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";
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
import ShowUserServiceReport from "../services/UserServices/ShowUserServiceReport";
|
|
|
|
|
2022-01-15 18:32:46 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
type IndexQuery = {
|
|
|
|
userId: string;
|
|
|
|
startDate: string;
|
|
|
|
endDate: string;
|
2022-07-28 17:55:23 +00:00
|
|
|
pageNumber: string;
|
2022-01-25 14:24:05 +00:00
|
|
|
};
|
2022-01-15 18:32:46 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-05-06 22:49:45 +00:00
|
|
|
export const reportUserByDateStartDateEnd = async (req: Request, res: Response): Promise<Response> => {
|
2022-05-03 21:20:58 +00:00
|
|
|
|
2022-01-27 00:33:16 +00:00
|
|
|
if (req.user.profile !== "master" && req.user.profile !== "admin") {
|
|
|
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
const { userId, startDate, endDate, pageNumber } = req.query as IndexQuery
|
|
|
|
|
|
|
|
|
|
|
|
console.log('PAGE NUMBER: ', pageNumber)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
const { tickets, count, hasMore } = await ShowTicketReport({userId, startDate, endDate, pageNumber});
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// return res.status(200).json(data_query);
|
|
|
|
|
|
|
|
return res.status(200).json({ tickets, count, hasMore });
|
2022-01-15 18:32:46 +00:00
|
|
|
};
|
|
|
|
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
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
|
2022-05-16 04:03:16 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
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});
|
|
|
|
|
|
|
|
let dateTime = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
|
|
|
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate })
|
2022-05-16 04:03:16 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
usersProfile.map((user:any) => {
|
|
|
|
|
|
|
|
let index = sumUserOlineTime.findIndex((e:any) => e.userId == user.id)
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
user.sumOnlineTime = sumUserOlineTime[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
user.sumOpen = openByUser[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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]}`
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:03:16 +00:00
|
|
|
})
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
return res.status(200).json(usersProfile);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
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 data_query_messages = await ShowMessageReport(userId, startDate, endDate);
|
|
|
|
|
|
|
|
return res.status(200).json(data_query_messages);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-01-15 18:32:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|