projeto-hit/backend/src/services/QueueService/DeleteQueueService.ts

38 lines
896 B
TypeScript

import ShowQueueService from "./ShowQueueService";
import UserQueue from "../../models/UserQueue";
import ListTicketsServiceCache from "../TicketServices/ListTicketServiceCache";
import { deleteTicketsFieldsCache } from '../../helpers/TicketCache'
import deleteFileFromTMP from "../../helpers/deleteFileFromTMP";
const DeleteQueueService = async (queueId: number | string): Promise<void> => {
const queue = await ShowQueueService(queueId);
if (queue.id) {
const tickets = await ListTicketsServiceCache({ queueId })
await deleteTicketsFieldsCache(tickets, ['queue.id', 'queue.name', 'queue.color'])
}
try {
await UserQueue.destroy({ where: { queueId: queueId } });
} catch (error) {
console.log('Error on delete UserQueue by queueId: ', queueId)
}
await queue.destroy();
deleteFileFromTMP(`botInfo.json`)
};
export default DeleteQueueService;