Compare commits
No commits in common. "bbc3dbb047db72dc2beaba9a6a6259d93f0d7824" and "bae3d86f2f2dcfba074793bda539529a9587a48a" have entirely different histories.
bbc3dbb047
...
bae3d86f2f
|
@ -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,6 +23,7 @@ import CountTicketsByUserQueue from "../services/UserServices/CountTicketsByUser
|
|||
|
||||
import ShowQueuesByUser from "../services/UserServices/ShowQueuesByUser";
|
||||
|
||||
|
||||
// import { filter } from "bluebird";
|
||||
|
||||
import { getIO } from "../libs/socket";
|
||||
|
@ -38,125 +39,82 @@ 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
|
||||
});
|
||||
|
||||
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 usersProfile = await ListUserParamiterService({ profile: 'user' })
|
||||
|
||||
let dateTime = splitDateTime(
|
||||
new Date(format(new Date(), "yyyy-MM-dd HH:mm:ss", { locale: ptBR }))
|
||||
);
|
||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate });
|
||||
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 openByUserOnQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "open",
|
||||
clientChatStart: true
|
||||
});
|
||||
const openByUserOutQueue = await CountTicketsByUserQueue({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
status: "open",
|
||||
clientChatStart: false
|
||||
});
|
||||
let dateTime = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })))
|
||||
const onlineUsers = await ListUserOnlineOffline({ date: dateTime.fullDate })
|
||||
|
||||
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 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 })
|
||||
|
||||
// let openQueueInOut = openByUserOnQueue.concat(openByUserOutQueue)
|
||||
// let closedQueueInOut = closedByUserOnQueue.concat(closedUserOutQueue)
|
||||
|
||||
const queuesByUser = await ShowQueuesByUser({ profile: "user" });
|
||||
|
||||
let openCloseOnQueue = openByUserOnQueue.concat(closedByUserOnQueue);
|
||||
let openCloseOutQueue = openByUserOutQueue.concat(closedUserOutQueue);
|
||||
const queuesByUser = await ShowQueuesByUser({ profile: 'user' })
|
||||
|
||||
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];
|
||||
|
@ -164,97 +122,101 @@ export const reportUserService = async (
|
|||
// 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
|
||||
|
||||
user.openClosedOutQueue = openClosedOutQueue;
|
||||
|
||||
// OPEN, CLOSED TICKETS STARTED BY CLIENTS
|
||||
let openClosedInQueue = queuesByUser.filter(e => e.userId == user.id);
|
||||
let openClosedInQueue = queuesByUser.filter((e) => e.userId == user.id)
|
||||
|
||||
if (openClosedInQueue && openClosedInQueue.length > 0) {
|
||||
user.openClosedInQueue = openClosedInQueue;
|
||||
user.openClosedInQueue = openClosedInQueue
|
||||
}
|
||||
|
||||
index = onlineUsers.findIndex((e: any) => e.userId == user.id);
|
||||
|
||||
index = onlineUsers.findIndex((e: any) => e.userId == user.id)
|
||||
|
||||
if (index != -1) {
|
||||
user.statusOnline = onlineUsers[index];
|
||||
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 (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]}`;
|
||||
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> => {
|
||||
|
||||
|
||||
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", {
|
||||
|
@ -267,5 +229,10 @@ export const reportOnQueue = async (
|
|||
}
|
||||
});
|
||||
|
||||
return res.status(200).json({ message: "ok" });
|
||||
return res.status(200).json({ message: 'ok' })
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,15 +10,11 @@ import UpdateUserService from "../services/UserServices/UpdateUserService";
|
|||
import ShowUserService from "../services/UserServices/ShowUserService";
|
||||
import DeleteUserService from "../services/UserServices/DeleteUserService";
|
||||
|
||||
import ListUserParamiterService from "../services/UserServices/ListUserParamiterService";
|
||||
import ListUserParamiterService from "../services/UserServices/ListUserParamiterService"
|
||||
import User from "../models/User";
|
||||
|
||||
import {
|
||||
startWhoIsOnlineMonitor,
|
||||
stopWhoIsOnlineMonitor
|
||||
} from "../helpers/WhoIsOnlineMonitor";
|
||||
import UserOnlineTIme from "../models/UserOnlineTime";
|
||||
import ListUser from "../services/UserServices/ListUserParamiterService";
|
||||
import { startWhoIsOnlineMonitor, stopWhoIsOnlineMonitor } from "../helpers/WhoIsOnlineMonitor"
|
||||
import UserOnlineTIme from '../models/UserOnlineTime'
|
||||
|
||||
type IndexQuery = {
|
||||
searchParam: string;
|
||||
|
@ -35,12 +31,13 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
profile
|
||||
});
|
||||
|
||||
if (req.user.profile !== "master") {
|
||||
if (req.user.profile !== 'master') {
|
||||
|
||||
let auxUsers: Array<object> = [];
|
||||
|
||||
for (var user of users) {
|
||||
if (user.profile !== "master") {
|
||||
auxUsers.push(user);
|
||||
if (user.profile !== 'master') {
|
||||
auxUsers.push(user)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +46,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
return res.json({ users, count, hasMore });
|
||||
|
||||
|
||||
|
||||
// const { users, count, hasMore } = await ListUsersService({
|
||||
// searchParam,
|
||||
// pageNumber
|
||||
|
@ -70,23 +69,11 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
// return res.json({ users, count, hasMore });
|
||||
};
|
||||
|
||||
export const all = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { profile } = req.query as IndexQuery;
|
||||
|
||||
const users = await ListUser({
|
||||
profile
|
||||
});
|
||||
|
||||
return res.json({ users });
|
||||
};
|
||||
|
||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { email, password, name, profile, queueIds } = req.body;
|
||||
|
||||
if (
|
||||
req.url === "/signup" &&
|
||||
(await CheckSettingsHelper("userCreation")) === "disabled"
|
||||
) {
|
||||
if (req.url === "/signup" && (await CheckSettingsHelper("userCreation")) === "disabled") {
|
||||
throw new AppError("ERR_USER_CREATION_DISABLED", 403);
|
||||
} else if (req.url !== "/signup" && req.user.profile !== "master") {
|
||||
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||
|
@ -106,8 +93,9 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
user
|
||||
});
|
||||
|
||||
|
||||
// await stopWhoIsOnlineMonitor()
|
||||
await startWhoIsOnlineMonitor();
|
||||
await startWhoIsOnlineMonitor()
|
||||
|
||||
return res.status(200).json(user);
|
||||
};
|
||||
|
@ -120,18 +108,17 @@ export const show = async (req: Request, res: Response): Promise<Response> => {
|
|||
return res.status(200).json(user);
|
||||
};
|
||||
|
||||
export const logoutUser = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
|
||||
export const logoutUser = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { userId } = req.params;
|
||||
|
||||
await stopWhoIsOnlineMonitor();
|
||||
|
||||
await stopWhoIsOnlineMonitor()
|
||||
|
||||
let onlineTime = {
|
||||
userId: userId,
|
||||
status: "logout..."
|
||||
};
|
||||
status: 'logout...'
|
||||
}
|
||||
|
||||
const io = getIO();
|
||||
io.emit("onlineStatus", {
|
||||
|
@ -139,12 +126,13 @@ export const logoutUser = async (
|
|||
userOnlineTime: onlineTime
|
||||
});
|
||||
|
||||
await startWhoIsOnlineMonitor();
|
||||
await startWhoIsOnlineMonitor()
|
||||
//
|
||||
|
||||
return res.status(200).json({});
|
||||
};
|
||||
|
||||
|
||||
export const update = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
|
@ -177,23 +165,26 @@ export const remove = async (
|
|||
throw new AppError("ERR_NO_PERMISSION", 403);
|
||||
}
|
||||
|
||||
|
||||
await DeleteUserService(userId);
|
||||
|
||||
|
||||
const io = getIO();
|
||||
io.emit("user", {
|
||||
action: "delete",
|
||||
userId
|
||||
});
|
||||
|
||||
|
||||
//test del
|
||||
await stopWhoIsOnlineMonitor();
|
||||
await stopWhoIsOnlineMonitor()
|
||||
|
||||
io.emit("onlineStatus", {
|
||||
action: "delete",
|
||||
userOnlineTime: userId
|
||||
});
|
||||
|
||||
await startWhoIsOnlineMonitor();
|
||||
await startWhoIsOnlineMonitor()
|
||||
//
|
||||
|
||||
return res.status(200).json({ message: "User deleted" });
|
||||
|
|
|
@ -5,7 +5,6 @@ import * as UserController from "../controllers/UserController";
|
|||
|
||||
const userRoutes = Router();
|
||||
|
||||
userRoutes.get("/users/all", isAuth, UserController.all);
|
||||
|
||||
userRoutes.get("/users", isAuth, UserController.index);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import Queue from "../../models/Queue";
|
||||
import User from "../../models/User";
|
||||
|
@ -6,54 +7,65 @@ import UserQueue from "../../models/UserQueue";
|
|||
interface Request {
|
||||
userId?: string | number;
|
||||
profile?: string;
|
||||
raw?: boolean;
|
||||
}
|
||||
|
||||
const ListUser = async ({ profile, userId, raw }: Request): Promise<User[]> => {
|
||||
let where_clause = {};
|
||||
|
||||
const ListUser = async ({ profile, userId }: Request): Promise<User[]> => {
|
||||
|
||||
let where_clause = {}
|
||||
|
||||
if (userId && profile) {
|
||||
where_clause = {
|
||||
[Op.and]: [{ userId: userId }, { profile: profile }]
|
||||
};
|
||||
} else if (userId) {
|
||||
[Op.and]: [
|
||||
{ userId: userId },
|
||||
{ profile: profile }
|
||||
]
|
||||
}
|
||||
}
|
||||
else if (userId) {
|
||||
where_clause = {
|
||||
[Op.and]: [{ userId: userId }]
|
||||
};
|
||||
} else if (profile) {
|
||||
[Op.and]: [
|
||||
{ userId: userId },
|
||||
]
|
||||
}
|
||||
}
|
||||
else if (profile) {
|
||||
where_clause = {
|
||||
profile: profile
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const queryOptions: any = {
|
||||
|
||||
const users = await User.findAll({
|
||||
where: where_clause,
|
||||
raw,
|
||||
attributes: ["id", "name", "email"],
|
||||
order: [["id", "ASC"]]
|
||||
};
|
||||
raw: true,
|
||||
attributes: ['id', 'name', 'email'],
|
||||
|
||||
if (!raw) {
|
||||
queryOptions.include = [
|
||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
||||
];
|
||||
}
|
||||
|
||||
const users = await User.findAll(queryOptions);
|
||||
|
||||
// const users = await User.findAll({
|
||||
// where: where_clause,
|
||||
// raw,
|
||||
// attributes: ['id', 'name', 'email'],
|
||||
|
||||
// include: [
|
||||
// { model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
||||
// {
|
||||
// model: UserQueue,
|
||||
// separate: true,
|
||||
|
||||
// attributes: ['id',],
|
||||
|
||||
// order: [
|
||||
// ['createdAt', 'ASC']
|
||||
// ]
|
||||
// },
|
||||
// ],
|
||||
|
||||
// order: [["id", "ASC"]],
|
||||
// })
|
||||
|
||||
|
||||
order: [["id", "ASC"]],
|
||||
})
|
||||
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
export default ListUser;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
import React, { useState, useContext, useMemo, useRef, useEffect } from "react"
|
||||
import { useHistory } from "react-router-dom"
|
||||
import React, { useState, useContext, useMemo } from "react";
|
||||
import { useHistory } from "react-router-dom";
|
||||
|
||||
import Button from "@material-ui/core/Button"
|
||||
import Dialog from "@material-ui/core/Dialog"
|
||||
import Select from "@material-ui/core/Select"
|
||||
import FormControl from "@material-ui/core/FormControl"
|
||||
import InputLabel from "@material-ui/core/InputLabel"
|
||||
import MenuItem from "@material-ui/core/MenuItem"
|
||||
import { makeStyles } from "@material-ui/core"
|
||||
import Button from "@material-ui/core/Button";
|
||||
import Dialog from "@material-ui/core/Dialog";
|
||||
import Select from "@material-ui/core/Select";
|
||||
import FormControl from "@material-ui/core/FormControl";
|
||||
import InputLabel from "@material-ui/core/InputLabel";
|
||||
import MenuItem from "@material-ui/core/MenuItem";
|
||||
import { makeStyles } from "@material-ui/core";
|
||||
|
||||
import DialogActions from "@material-ui/core/DialogActions"
|
||||
import DialogContent from "@material-ui/core/DialogContent"
|
||||
import DialogTitle from "@material-ui/core/DialogTitle"
|
||||
import DialogActions from "@material-ui/core/DialogActions";
|
||||
import DialogContent from "@material-ui/core/DialogContent";
|
||||
import DialogTitle from "@material-ui/core/DialogTitle";
|
||||
|
||||
import { i18n } from "../../translate/i18n"
|
||||
import api from "../../services/api"
|
||||
import ButtonWithSpinner from "../ButtonWithSpinner"
|
||||
import toastError from "../../errors/toastError"
|
||||
import { i18n } from "../../translate/i18n";
|
||||
import api from "../../services/api";
|
||||
import ButtonWithSpinner from "../ButtonWithSpinner";
|
||||
import toastError from "../../errors/toastError";
|
||||
|
||||
import { WhatsAppsContext } from "../../context/WhatsApp/WhatsAppsContext"
|
||||
import { WhatsAppsContext } from "../../context/WhatsApp/WhatsAppsContext";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
maxWidth: {
|
||||
width: "100%",
|
||||
},
|
||||
}))
|
||||
}));
|
||||
|
||||
// Receive array of queues arrays
|
||||
// Return a new array with unique queues from all arrays has passed by the parameter
|
||||
|
@ -45,117 +45,49 @@ const queueArraysToOneArray = (array) => {
|
|||
|
||||
|
||||
const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
||||
const history = useHistory()
|
||||
const { whatsApps } = useContext(WhatsAppsContext)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [selectedQueue, setSelectedQueue] = useState('')
|
||||
const [selectedUser, setSelectedUser] = useState('')
|
||||
const classes = useStyles()
|
||||
|
||||
const [users, setUsers] = useState([])
|
||||
const [queues, setQueues] = useState([])
|
||||
const isRun = useRef(false)
|
||||
|
||||
|
||||
const _queues = useMemo(() => {
|
||||
const history = useHistory();
|
||||
const { whatsApps } = useContext(WhatsAppsContext);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedQueue, setSelectedQueue] = useState('');
|
||||
const classes = useStyles();
|
||||
const queues = useMemo(() => {
|
||||
if (!whatsApps) return []
|
||||
const whatsAppsQueues = whatsApps.map(({ queues }) => queues)
|
||||
//const whatsAppsQueues = whatsApps.filter(({ status }) => status === "CONNECTED" ).map(({ queues }) => queues)
|
||||
const uniqueQueuesAvailable = queueArraysToOneArray(whatsAppsQueues)
|
||||
|
||||
return uniqueQueuesAvailable
|
||||
}, [whatsApps])
|
||||
const [itemHover, setItemHover] = useState(-1)
|
||||
|
||||
useEffect(() => {
|
||||
if (isRun.current) return
|
||||
setQueues(_queues)
|
||||
|
||||
isRun.current = true
|
||||
}, [whatsApps])
|
||||
|
||||
useEffect(() => {
|
||||
console.log('==========> selectedUser: ', selectedUser)
|
||||
|
||||
if (selectedUser) {
|
||||
|
||||
let { queues } = users.find(u => +u.id == +selectedUser)
|
||||
const userQueues = queues.map((q) => {
|
||||
const { id, color, name } = q
|
||||
return { id, color, name }
|
||||
})
|
||||
|
||||
setQueues(userQueues)
|
||||
setSelectedQueue('')
|
||||
}
|
||||
else {
|
||||
setQueues(_queues)
|
||||
setSelectedUser('')
|
||||
}
|
||||
}, [selectedUser])
|
||||
|
||||
const handleClose = () => {
|
||||
onClose()
|
||||
}
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleSaveTicket = async e => {
|
||||
e.preventDefault()
|
||||
if (!ticketid) return
|
||||
if (!selectedQueue) return
|
||||
setLoading(true)
|
||||
e.preventDefault();
|
||||
if (!ticketid) return;
|
||||
if (!selectedQueue) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
let data = {}
|
||||
let data = {};
|
||||
|
||||
if (selectedQueue && selectedQueue !== null) {
|
||||
data.queueId = selectedQueue
|
||||
}
|
||||
|
||||
|
||||
if (selectedUser) {
|
||||
data.userId = selectedUser
|
||||
}
|
||||
else {
|
||||
// test del PARA APARECER NA FILA DE OUTRO ATENDENTE E O MESMO CLICAR EM ACEITAR AO INVES DE ENVIAR PARA ATENDENDO
|
||||
data.status = 'pending'
|
||||
data.transfer = true
|
||||
}
|
||||
|
||||
await api.put(`/tickets/${ticketid}`, data)
|
||||
await api.put(`/tickets/${ticketid}`, data);
|
||||
|
||||
setLoading(false)
|
||||
history.push(`/tickets`)
|
||||
setLoading(false);
|
||||
history.push(`/tickets`);
|
||||
} catch (err) {
|
||||
setLoading(false)
|
||||
toastError(err)
|
||||
setLoading(false);
|
||||
toastError(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
|
||||
const { data } = await api.get("/users/all", {
|
||||
params: { profile: 'user' },
|
||||
})
|
||||
|
||||
setUsers(data.users)
|
||||
|
||||
console.log('data.users: ', data.users)
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
fetchUsers()
|
||||
|
||||
}, 500)
|
||||
return () => clearTimeout(delayDebounceFn)
|
||||
}, [])
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={modalOpen} onClose={handleClose} maxWidth="lg" scroll="paper">
|
||||
|
@ -166,7 +98,6 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||
<DialogContent dividers>
|
||||
<FormControl variant="outlined" className={classes.maxWidth}>
|
||||
<InputLabel>{i18n.t("transferTicketModal.fieldQueueLabel")}</InputLabel>
|
||||
|
||||
<Select
|
||||
value={selectedQueue}
|
||||
onChange={(e) => setSelectedQueue(e.target.value)}
|
||||
|
@ -187,26 +118,6 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
|
||||
<br />
|
||||
|
||||
<Select
|
||||
value={selectedUser}
|
||||
onChange={e => setSelectedUser(e.target.value)}
|
||||
label={'Transfeir para usuario'}
|
||||
>
|
||||
<MenuItem style={{ background: "white", }} value={''}> </MenuItem>
|
||||
{users.map((user) => (
|
||||
<MenuItem
|
||||
key={user.id}
|
||||
value={user.id}
|
||||
>{user.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
|
||||
</FormControl>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
|
@ -229,7 +140,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||
</DialogActions>
|
||||
</form>
|
||||
</Dialog >
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default TransferTicketModal
|
||||
export default TransferTicketModal;
|
Loading…
Reference in New Issue