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