2022-01-06 01:26:15 +00:00
|
|
|
import ShowQueueService from "./ShowQueueService";
|
|
|
|
|
2022-04-17 21:02:15 +00:00
|
|
|
import UserQueue from "../../models/UserQueue";
|
|
|
|
|
2022-10-25 14:16:36 +00:00
|
|
|
import ListTicketsServiceCache from "../TicketServices/ListTicketServiceCache";
|
|
|
|
|
2024-04-12 21:33:15 +00:00
|
|
|
import { deleteTicketsFieldsCache } from "../../helpers/TicketCache";
|
|
|
|
import { del } from "../../helpers/RedisClient";
|
2022-10-25 14:16:36 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const DeleteQueueService = async (queueId: number | string): Promise<void> => {
|
|
|
|
const queue = await ShowQueueService(queueId);
|
|
|
|
|
2022-10-25 14:16:36 +00:00
|
|
|
if (queue.id) {
|
2024-04-12 21:33:15 +00:00
|
|
|
const tickets = await ListTicketsServiceCache({ queueId });
|
2022-10-25 14:16:36 +00:00
|
|
|
|
2024-04-12 21:33:15 +00:00
|
|
|
await deleteTicketsFieldsCache(tickets, [
|
|
|
|
"queue.id",
|
|
|
|
"queue.name",
|
|
|
|
"queue.color"
|
|
|
|
]);
|
2022-10-25 14:16:36 +00:00
|
|
|
}
|
|
|
|
|
2024-04-12 21:33:15 +00:00
|
|
|
try {
|
2022-10-25 14:16:36 +00:00
|
|
|
await UserQueue.destroy({ where: { queueId: queueId } });
|
|
|
|
|
2024-04-12 21:33:15 +00:00
|
|
|
del(`queue:${queueId}`);
|
2022-04-17 21:02:15 +00:00
|
|
|
} catch (error) {
|
2024-04-12 21:33:15 +00:00
|
|
|
console.log("Error on delete UserQueue by queueId: ", queueId);
|
2022-10-25 14:16:36 +00:00
|
|
|
}
|
2022-04-17 21:02:15 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
await queue.destroy();
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DeleteQueueService;
|