mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
feat: update tickets list on transfer
This commit is contained in:
@@ -76,14 +76,14 @@ export const update = async (
|
|||||||
const { ticketId } = req.params;
|
const { ticketId } = req.params;
|
||||||
const ticketData: TicketData = req.body;
|
const ticketData: TicketData = req.body;
|
||||||
|
|
||||||
const { ticket, oldStatus, ticketUser } = await UpdateTicketService({
|
const { ticket, oldStatus, oldUserId } = await UpdateTicketService({
|
||||||
ticketData,
|
ticketData,
|
||||||
ticketId
|
ticketId
|
||||||
});
|
});
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|
||||||
if (ticket.status !== oldStatus) {
|
if (ticket.status !== oldStatus || ticket.user?.id !== oldUserId) {
|
||||||
io.to(oldStatus).emit("ticket", {
|
io.to(oldStatus).emit("ticket", {
|
||||||
action: "delete",
|
action: "delete",
|
||||||
ticketId: ticket.id
|
ticketId: ticket.id
|
||||||
@@ -92,8 +92,7 @@ export const update = async (
|
|||||||
|
|
||||||
io.to(ticket.status).to("notification").to(ticketId).emit("ticket", {
|
io.to(ticket.status).to("notification").to(ticketId).emit("ticket", {
|
||||||
action: "updateStatus",
|
action: "updateStatus",
|
||||||
ticket,
|
ticket
|
||||||
user: ticketUser
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json(ticket);
|
return res.status(200).json(ticket);
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ type IndexQuery = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const index = async (req: Request, res: Response): Promise<Response> => {
|
export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||||
if (req.user.profile !== "admin") {
|
|
||||||
throw new AppError("ERR_NO_PERMISSION", 403); // should be handled better.
|
|
||||||
}
|
|
||||||
const { searchParam, pageNumber } = req.query as IndexQuery;
|
const { searchParam, pageNumber } = req.query as IndexQuery;
|
||||||
|
|
||||||
const { users, count, hasMore } = await ListUsersService({
|
const { users, count, hasMore } = await ListUsersService({
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const UpdateDeletedUserOpenTicketsStatus = async (
|
|||||||
tickets.forEach(async t => {
|
tickets.forEach(async t => {
|
||||||
const ticketId = t.id.toString();
|
const ticketId = t.id.toString();
|
||||||
|
|
||||||
const { ticket, oldStatus, ticketUser } = await UpdateTicketService({
|
const { ticket, oldStatus } = await UpdateTicketService({
|
||||||
ticketData: { status: "pending" },
|
ticketData: { status: "pending" },
|
||||||
ticketId
|
ticketId
|
||||||
});
|
});
|
||||||
@@ -23,8 +23,7 @@ const UpdateDeletedUserOpenTicketsStatus = async (
|
|||||||
|
|
||||||
io.to(ticket.status).to(ticketId).emit("ticket", {
|
io.to(ticket.status).to(ticketId).emit("ticket", {
|
||||||
action: "updateStatus",
|
action: "updateStatus",
|
||||||
ticket,
|
ticket
|
||||||
user: ticketUser
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ interface Request {
|
|||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
ticket: Ticket;
|
ticket: Ticket;
|
||||||
ticketUser: User | null;
|
|
||||||
oldStatus: string;
|
oldStatus: string;
|
||||||
|
oldUserId: number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateTicketService = async ({
|
const UpdateTicketService = async ({
|
||||||
@@ -34,6 +34,11 @@ const UpdateTicketService = async ({
|
|||||||
model: Contact,
|
model: Contact,
|
||||||
as: "contact",
|
as: "contact",
|
||||||
attributes: ["id", "name", "number", "profilePicUrl"]
|
attributes: ["id", "name", "number", "profilePicUrl"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: User,
|
||||||
|
as: "user",
|
||||||
|
attributes: ["id", "name"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -45,6 +50,7 @@ const UpdateTicketService = async ({
|
|||||||
await SetTicketMessagesAsRead(ticket);
|
await SetTicketMessagesAsRead(ticket);
|
||||||
|
|
||||||
const oldStatus = ticket.status;
|
const oldStatus = ticket.status;
|
||||||
|
const oldUserId = ticket.user?.id;
|
||||||
|
|
||||||
if (oldStatus === "closed") {
|
if (oldStatus === "closed") {
|
||||||
await CheckContactOpenTickets(ticket.contact.id);
|
await CheckContactOpenTickets(ticket.contact.id);
|
||||||
@@ -54,9 +60,10 @@ const UpdateTicketService = async ({
|
|||||||
status,
|
status,
|
||||||
userId
|
userId
|
||||||
});
|
});
|
||||||
const ticketUser = await ticket.$get("user", { attributes: ["id", "name"] });
|
|
||||||
|
|
||||||
return { ticket, oldStatus, ticketUser };
|
await ticket.reload();
|
||||||
|
|
||||||
|
return { ticket, oldStatus, oldUserId };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default UpdateTicketService;
|
export default UpdateTicketService;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ const Ticket = () => {
|
|||||||
|
|
||||||
socket.on("ticket", data => {
|
socket.on("ticket", data => {
|
||||||
if (data.action === "updateStatus") {
|
if (data.action === "updateStatus") {
|
||||||
setTicket({ ...data.ticket, user: data.user });
|
setTicket(data.ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.action === "delete") {
|
if (data.action === "delete") {
|
||||||
|
|||||||
Reference in New Issue
Block a user