Compare commits
5 Commits
051e1b3b2a
...
0d32fe8fbb
Author | SHA1 | Date |
---|---|---|
adriano | 0d32fe8fbb | |
adriano | dcf471fa42 | |
adriano | fd5d9829e4 | |
adriano | c57811c9f6 | |
adriano | 088274cafd |
|
@ -64,7 +64,7 @@ export const reportUserService = async (req: Request, res: Response): Promise<Re
|
|||
const { userId, startDate, endDate } = req.query as IndexQuery
|
||||
|
||||
|
||||
let usersProfile = await ListUserParamiterService({ profile: 'user' })
|
||||
let usersProfile = await ListUserParamiterService({ profile: 'user', raw:true })
|
||||
|
||||
const sumUserOlineTime = await ShowUserServiceReport({ startDate, endDate, userId });
|
||||
const closedByUser = await ShowUserServiceReport({ startDate, endDate, ticketStatus: 'closed', userId });
|
||||
|
|
|
@ -236,6 +236,7 @@ export const update = async (
|
|||
|
||||
ticket2 = ticket;
|
||||
} else {
|
||||
|
||||
// Para aparecer pendente para todos usuarios que estao na fila
|
||||
if (req.body.transfer) {
|
||||
req.body.userId = null;
|
||||
|
|
|
@ -10,11 +10,15 @@ 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 {
|
||||
startWhoIsOnlineMonitor,
|
||||
stopWhoIsOnlineMonitor
|
||||
} from "../helpers/WhoIsOnlineMonitor";
|
||||
import UserOnlineTIme from "../models/UserOnlineTime";
|
||||
import ListUser from "../services/UserServices/ListUserParamiterService";
|
||||
|
||||
type IndexQuery = {
|
||||
searchParam: string;
|
||||
|
@ -31,13 +35,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +49,6 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
|
||||
return res.json({ users, count, hasMore });
|
||||
|
||||
|
||||
|
||||
// const { users, count, hasMore } = await ListUsersService({
|
||||
// searchParam,
|
||||
// pageNumber
|
||||
|
@ -69,11 +70,23 @@ 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);
|
||||
|
@ -93,9 +106,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
user
|
||||
});
|
||||
|
||||
|
||||
// await stopWhoIsOnlineMonitor()
|
||||
await startWhoIsOnlineMonitor()
|
||||
await startWhoIsOnlineMonitor();
|
||||
|
||||
return res.status(200).json(user);
|
||||
};
|
||||
|
@ -108,17 +120,18 @@ 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", {
|
||||
|
@ -126,13 +139,12 @@ export const logoutUser = async (req: Request, res: Response): Promise<Response>
|
|||
userOnlineTime: onlineTime
|
||||
});
|
||||
|
||||
await startWhoIsOnlineMonitor()
|
||||
await startWhoIsOnlineMonitor();
|
||||
//
|
||||
|
||||
return res.status(200).json({});
|
||||
};
|
||||
|
||||
|
||||
export const update = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
|
@ -165,26 +177,23 @@ 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" });
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import { QueryInterface, DataTypes } from "sequelize";
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface: QueryInterface) => {
|
||||
return queryInterface.changeColumn("SettingTickets", "message", {
|
||||
type: DataTypes.STRING(3000),
|
||||
allowNull: true
|
||||
});
|
||||
},
|
||||
|
||||
down: (queryInterface: QueryInterface) => {
|
||||
return queryInterface.changeColumn("SettingTickets", "message", {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
});
|
||||
}
|
||||
};
|
|
@ -6,6 +6,8 @@ import * as UserController from "../controllers/UserController";
|
|||
const userRoutes = Router();
|
||||
|
||||
|
||||
userRoutes.get("/users/all", isAuth, UserController.all);
|
||||
|
||||
userRoutes.get("/users", isAuth, UserController.index);
|
||||
|
||||
userRoutes.post("/users", isAuth, UserController.store);
|
||||
|
|
|
@ -7,10 +7,11 @@ import UserQueue from "../../models/UserQueue";
|
|||
interface Request {
|
||||
userId?: string | number;
|
||||
profile?: string;
|
||||
raw?:boolean
|
||||
}
|
||||
|
||||
|
||||
const ListUser = async ({ profile, userId }: Request): Promise<User[]> => {
|
||||
const ListUser = async ({ profile, userId, raw}: Request): Promise<User[]> => {
|
||||
|
||||
let where_clause = {}
|
||||
|
||||
|
@ -36,29 +37,34 @@ const ListUser = async ({ profile, userId }: Request): Promise<User[]> => {
|
|||
}
|
||||
|
||||
|
||||
const users = await User.findAll({
|
||||
const queryOptions:any = {
|
||||
where: where_clause,
|
||||
raw: true,
|
||||
attributes: ['id', 'name', 'email'],
|
||||
raw,
|
||||
attributes: ["id", "name", "email"],
|
||||
order: [["id", "ASC"]]
|
||||
};
|
||||
|
||||
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: UserQueue,
|
||||
// separate: true,
|
||||
|
||||
// attributes: ['id',],
|
||||
|
||||
// order: [
|
||||
// ['createdAt', 'ASC']
|
||||
// ]
|
||||
// },
|
||||
// { model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
||||
// ],
|
||||
|
||||
|
||||
|
||||
order: [["id", "ASC"]],
|
||||
})
|
||||
// order: [["id", "ASC"]],
|
||||
// })
|
||||
|
||||
|
||||
return users;
|
||||
|
|
|
@ -290,6 +290,15 @@ const verifyQueue = async (
|
|||
}
|
||||
//
|
||||
|
||||
const outService = await outOfService();
|
||||
|
||||
if (outService.length > 0) {
|
||||
const { type, msg: msgOutService } = outService[0];
|
||||
console.log(`${type} message ignored on queue`);
|
||||
botSendMessage(ticket, msgOutService);
|
||||
return;
|
||||
}
|
||||
|
||||
let body = "";
|
||||
|
||||
if (botOptions.length > 0) {
|
||||
|
@ -438,7 +447,7 @@ const _clear_lst = () => {
|
|||
};
|
||||
|
||||
const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
||||
if (!msg.fromMe) {
|
||||
// if (!msg.fromMe) {
|
||||
_clear_lst();
|
||||
|
||||
let index = lst.findIndex((x: any) => x.id == msg.id.id);
|
||||
|
@ -459,7 +468,7 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
|||
|
||||
// console.log('LIST OF ID MESSAGE lst: ', lst)
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
if (!isValidMsg(msg)) {
|
||||
return;
|
||||
|
@ -628,43 +637,18 @@ const handleMessage = async (msg: any, wbot: any): Promise<void> => {
|
|||
ticketHasQueue = true;
|
||||
}
|
||||
|
||||
if (ticketHasQueue) {
|
||||
// MESSAGE TO HOLIDAY
|
||||
const holiday: any = await isHoliday();
|
||||
if (ticketHasQueue && ticket.status != "open") {
|
||||
const outService = await outOfService();
|
||||
|
||||
if (holiday && holiday.set) {
|
||||
if (msg.fromMe && holiday.msg == msg.body) {
|
||||
console.log("HOLIDAY MESSAGE IGNORED");
|
||||
if (outService.length > 0) {
|
||||
const { type, msg: msgOutService } = outService[0];
|
||||
|
||||
if (msg.fromMe && msgOutService == msg.body) {
|
||||
console.log(`${type} message ignored`);
|
||||
return;
|
||||
}
|
||||
|
||||
botSendMessage(ticket, holiday.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// MESSAGES TO SATURDAY OR SUNDAY
|
||||
const weekend: any = await isWeekend();
|
||||
|
||||
if (weekend && weekend.set) {
|
||||
if (msg.fromMe && weekend.msg == msg.body) {
|
||||
console.log("WEEKEND MESSAGE IGNORED");
|
||||
return;
|
||||
}
|
||||
|
||||
botSendMessage(ticket, weekend.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// MESSAGE TO BUSINESS TIME
|
||||
const businessTime = await isOutBusinessTime();
|
||||
|
||||
if (businessTime && businessTime.set) {
|
||||
if (msg.fromMe && businessTime.msg == msg.body) {
|
||||
console.log("BUSINESS TIME MESSAGE IGNORED");
|
||||
return;
|
||||
}
|
||||
|
||||
botSendMessage(ticket, businessTime.msg);
|
||||
botSendMessage(ticket, msgOutService);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -723,4 +707,31 @@ const wbotMessageListener = (wbot: Session): void => {
|
|||
});
|
||||
};
|
||||
|
||||
const outOfService = async () => {
|
||||
// MESSAGE TO HOLIDAY
|
||||
const holiday: any = await isHoliday();
|
||||
|
||||
let objs: any = [];
|
||||
|
||||
if (holiday && holiday.set) {
|
||||
objs.push({ type: "holiday", msg: holiday.msg });
|
||||
}
|
||||
|
||||
// MESSAGES TO SATURDAY OR SUNDAY
|
||||
const weekend: any = await isWeekend();
|
||||
|
||||
if (weekend && weekend.set) {
|
||||
objs.push({ type: "weekend", msg: weekend.msg });
|
||||
}
|
||||
|
||||
// MESSAGE TO BUSINESS TIME
|
||||
const businessTime = await isOutBusinessTime();
|
||||
|
||||
if (businessTime && businessTime.set) {
|
||||
objs.push({ type: "businessTime", msg: businessTime.msg });
|
||||
}
|
||||
|
||||
return objs;
|
||||
};
|
||||
|
||||
export { wbotMessageListener, handleMessage, handleMsgAck, lst };
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
import React, { useState, useContext, useMemo } from "react";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import React, { useState, useContext, useMemo, useRef, useEffect } 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,49 +45,117 @@ 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 classes = useStyles();
|
||||
const queues = useMemo(() => {
|
||||
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(() => {
|
||||
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);
|
||||
|
||||
setLoading(false);
|
||||
history.push(`/tickets`);
|
||||
} catch (err) {
|
||||
setLoading(false);
|
||||
toastError(err);
|
||||
}
|
||||
};
|
||||
|
||||
await api.put(`/tickets/${ticketid}`, data)
|
||||
|
||||
setLoading(false)
|
||||
history.push(`/tickets`)
|
||||
} catch (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">
|
||||
|
@ -98,6 +166,7 @@ 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)}
|
||||
|
@ -118,6 +187,26 @@ 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>
|
||||
|
@ -140,7 +229,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||
</DialogActions>
|
||||
</form>
|
||||
</Dialog >
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
export default TransferTicketModal;
|
||||
export default TransferTicketModal
|
Loading…
Reference in New Issue