diff --git a/backend/.env.example b/backend/.env.example deleted file mode 100644 index d3ad7a6..0000000 --- a/backend/.env.example +++ /dev/null @@ -1,14 +0,0 @@ -NODE_ENV= -BACKEND_URL=http://localhost -FRONTEND_URL=http://localhost:3000 -PROXY_PORT=8080 -PORT=8080 - -DB_DIALECT= -DB_HOST= -DB_USER= -DB_PASS= -DB_NAME= - -JWT_SECRET= -JWT_REFRESH_SECRET= diff --git a/backend/src/controllers/ReportController.ts b/backend/src/controllers/ReportController.ts index 664bfde..bced8df 100644 --- a/backend/src/controllers/ReportController.ts +++ b/backend/src/controllers/ReportController.ts @@ -34,6 +34,7 @@ type IndexQuery = { startDate: string; endDate: string; pageNumber: string; + userQueues: []; }; type ReportOnQueue = { @@ -52,12 +53,11 @@ export const reportUserByDateStartDateEnd = async (req: Request, res: Response): throw new AppError("ERR_NO_PERMISSION", 403); } - const { userId, startDate, endDate, pageNumber } = req.query as IndexQuery + const { userId, startDate, endDate, pageNumber, userQueues } = req.query as IndexQuery console.log("userId, startDate, endDate, pageNumber: ", userId, startDate, endDate, pageNumber); const { tickets, count, hasMore } = await ShowTicketReport({ userId, startDate, endDate, pageNumber }); - // console.log('kkkkkkkkkkkkkkkkkk tickets: ', JSON.stringify(tickets, null, 6)) return res.status(200).json({ tickets, count, hasMore }); diff --git a/backend/src/controllers/UserController.ts b/backend/src/controllers/UserController.ts index c1c558c..88d461d 100644 --- a/backend/src/controllers/UserController.ts +++ b/backend/src/controllers/UserController.ts @@ -60,7 +60,7 @@ export const index = async (req: Request, res: Response): Promise => { auxUsers.push(user); } } - + return res.json({ users: auxUsers, count, hasMore }); } @@ -134,7 +134,7 @@ export const all = async (req: Request, res: Response): Promise => { }; export const store = async (req: Request, res: Response): Promise => { - const { email, password, name, profile, queueIds } = req.body; + const { email, password, name, profile, positionCompany, queueIds } = req.body; if ( req.url === "/signup" && @@ -149,6 +149,7 @@ export const store = async (req: Request, res: Response): Promise => { email, password, name, + positionCompany, profile, queueIds }); diff --git a/backend/src/helpers/SchedulingNotifySendMessage.ts b/backend/src/helpers/SchedulingNotifySendMessage.ts index 93326a2..78399d7 100644 --- a/backend/src/helpers/SchedulingNotifySendMessage.ts +++ b/backend/src/helpers/SchedulingNotifySendMessage.ts @@ -11,6 +11,7 @@ import { convertBytes } from "./ConvertBytes"; import { deleteScheduleByTicketIdCache } from "./SchedulingNotifyCache"; import SchedulingNotify from "../models/SchedulingNotify"; import Ticket from "../models/Ticket"; +import User from "../models/User"; import { Sequelize, Op } from "sequelize"; @@ -57,20 +58,29 @@ const monitor = async () => { status: { [Op.in]: ['open', 'pending'] } } }) - + await deleteScheduleByTicketIdCache(schedulingNotifies[i].ticketId) await DeleteSchedulingNotifyService(schedulingNotifies[i].id) if (_ticket) continue - + if (ticket.dataValues.status == 'closed') { - await ticket.update({ status: 'pending' }) + await ticket.update({ status: 'open' }) } + const userId: number = ticket.getDataValue('userId'); + let userN = ''; + if(userId){ + const useer = await User.findByPk(userId); + if(useer){ + const userName: string = useer.getDataValue('name'); + userN = `*${userName}:* \n`; + } + } await new Promise(f => setTimeout(f, 3000)); await SendWhatsAppMessage({ - body: schedulingNotifies[i].message, ticket + body: userN+schedulingNotifies[i].message, ticket }); @@ -80,33 +90,33 @@ const monitor = async () => { } - exec("df -h /", (error: any, stdout: any, stderr: any) => { + // exec("df -h /", (error: any, stdout: any, stderr: any) => { - if (error) { - console.log(`exec error: ${error.message}`); - return; - } - if (stderr) { - console.log(`exec stderr: ${stderr}`); - return; - } + // if (error) { + // console.log(`exec error: ${error.message}`); + // return; + // } + // if (stderr) { + // console.log(`exec stderr: ${stderr}`); + // return; + // } - stdout = stdout.split(/\r?\n/) - stdout = stdout[1].trim().split(/\s+/) + // stdout = stdout.split(/\r?\n/) + // stdout = stdout[1].trim().split(/\s+/) - // DISK SPACE MONITORING - const io = getIO(); - io.emit("diskSpaceMonit", { - action: "update", - diskSpace: { - size: stdout[1], - used: stdout[2], - available: stdout[3], - use: stdout[4] - } - }); + // // DISK SPACE MONITORING + // const io = getIO(); + // io.emit("diskSpaceMonit", { + // action: "update", + // diskSpace: { + // size: stdout[1], + // used: stdout[2], + // available: stdout[3], + // use: stdout[4] + // } + // }); - }); + // }); diff --git a/backend/src/helpers/SerializeUser.ts b/backend/src/helpers/SerializeUser.ts index 3802500..8f7250b 100644 --- a/backend/src/helpers/SerializeUser.ts +++ b/backend/src/helpers/SerializeUser.ts @@ -4,6 +4,7 @@ import User from "../models/User"; interface SerializedUser { id: number; name: string; + positionCompany: string; email: string; profile: string; queues: Queue[]; @@ -13,6 +14,7 @@ export const SerializeUser = (user: User): SerializedUser => { return { id: user.id, name: user.name, + positionCompany: user.positionCompany, email: user.email, profile: user.profile, queues: user.queues diff --git a/backend/src/models/User.ts b/backend/src/models/User.ts index 63ab78f..fb2109e 100644 --- a/backend/src/models/User.ts +++ b/backend/src/models/User.ts @@ -41,7 +41,10 @@ class User extends Model { @Default(0) @Column tokenVersion: number; - + + @Column + positionCompany: string; + @Default("admin") @Column profile: string; @@ -51,7 +54,6 @@ class User extends Model { @UpdatedAt updatedAt: Date; - @HasMany(() => Ticket) tickets: Ticket[]; diff --git a/backend/src/services/UserServices/AuthUserService.ts b/backend/src/services/UserServices/AuthUserService.ts index f198a7c..b1cac22 100644 --- a/backend/src/services/UserServices/AuthUserService.ts +++ b/backend/src/services/UserServices/AuthUserService.ts @@ -10,6 +10,7 @@ import Queue from "../../models/Queue"; interface SerializedUser { id: number; name: string; + positionCompany: string; email: string; profile: string; queues: Queue[]; diff --git a/backend/src/services/UserServices/CreateUserService.ts b/backend/src/services/UserServices/CreateUserService.ts index 69d7c0d..5c6badb 100644 --- a/backend/src/services/UserServices/CreateUserService.ts +++ b/backend/src/services/UserServices/CreateUserService.ts @@ -8,6 +8,7 @@ interface Request { email: string; password: string; name: string; + positionCompany?: string; queueIds?: number[]; profile?: string; } @@ -15,6 +16,7 @@ interface Request { interface Response { email: string; name: string; + positionCompany: string; id: number; profile: string; } @@ -23,6 +25,7 @@ const CreateUserService = async ({ email, password, name, + positionCompany, queueIds = [], profile = "master" }: Request): Promise => { @@ -70,6 +73,7 @@ const CreateUserService = async ({ email, password, name, + positionCompany, profile }, { include: ["queues"] } diff --git a/backend/src/services/UserServices/ListUserParamiterService.ts b/backend/src/services/UserServices/ListUserParamiterService.ts index 0b0c1af..ebb610b 100644 --- a/backend/src/services/UserServices/ListUserParamiterService.ts +++ b/backend/src/services/UserServices/ListUserParamiterService.ts @@ -40,7 +40,7 @@ const ListUser = async ({ profile, userId, raw, userIds, profiles }: Request): P const users = await User.findAll({ where: where_clause, raw, - attributes: ["id", "name", "email"], + attributes: ["id", "name", "email", "positionCompany"], include: [ { model: Queue, as: "queues", attributes: ["id", "name", "color"] } diff --git a/backend/src/services/UserServices/ListUsersService.ts b/backend/src/services/UserServices/ListUsersService.ts index 5c556f0..5f2b07a 100644 --- a/backend/src/services/UserServices/ListUsersService.ts +++ b/backend/src/services/UserServices/ListUsersService.ts @@ -63,7 +63,7 @@ const ListUsersService = async ({ const { count, rows: users } = await User.findAndCountAll({ where: whereCondition, - attributes: ["name", "id", "email", "profile", "createdAt"], + attributes: ["name", "id", "email","positionCompany", "profile", "createdAt"], limit, offset, order: [["createdAt", "DESC"]], diff --git a/frontend/.env.example b/frontend/.env.example deleted file mode 100644 index f890a22..0000000 --- a/frontend/.env.example +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_BACKEND_URL = http://localhost:8080/ \ No newline at end of file diff --git a/frontend/src/components/UserModal/index.js b/frontend/src/components/UserModal/index.js index 3296e48..860cb2a 100644 --- a/frontend/src/components/UserModal/index.js +++ b/frontend/src/components/UserModal/index.js @@ -84,6 +84,7 @@ const UserModal = ({ open, onClose, userId }) => { name: "", email: "", password: "", + position: "", profile: "user", }; @@ -220,10 +221,9 @@ const UserModal = ({ open, onClose, userId }) => { fullWidth /> -
{ margin="dense" fullWidth /> +
+ { />
+ { const { user: userA } = useContext(AuthContext) - //-------- const [searchParam] = useState("") @@ -316,21 +328,28 @@ const Report = () => { setLoading(true) const fetchQueries = async () => { try { - if (reportOption === '1') { // const { data } = await api.get("/reports/", { params: { userId: userId ? userId : 0, startDate: convertAndFormatDate(startDate), endDate: convertAndFormatDate(endDate), pageNumber: pageNumberTickets }, }) - const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets }, }) - + const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets }, userQueues: userA.queues}) + let ticketsQueue = data.tickets; + let userQueues = userA.queues; + let filterQueuesTickets = []; + if(userQueues.length > 1){ + filterQueuesTickets = ticketsQueue.filter(ticket => userQueues.some(queue => queue.name === ticket.queue.name)); + }else if(userQueues.length > 0) { + filterQueuesTickets = ticketsQueue.filter(ticket => ticket.queue.name === userQueues[0].name); + } + data.tickets = filterQueuesTickets; dispatchQ({ type: "LOAD_QUERY", payload: data.tickets }) setHasMore(data.hasMore) setTotalCountTickets(data.count) setLoading(false) - + } else if (reportOption === '2') { @@ -684,7 +703,7 @@ const Report = () => { <> { {i18n.t("users.table.profile")} - + + Cargo + {i18n.t("users.table.actions")} @@ -281,6 +283,7 @@ const Users = () => { {user.name} {user.email} {user.profile} + {user.positionCompany}