2022-01-06 01:26:15 +00:00
|
|
|
import Whatsapp from "../../models/Whatsapp";
|
|
|
|
import AppError from "../../errors/AppError";
|
|
|
|
|
2022-04-17 21:02:15 +00:00
|
|
|
import WhatsappQueue from "../../models/WhatsappQueue";
|
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const DeleteWhatsAppService = async (id: string): Promise<void> => {
|
|
|
|
const whatsapp = await Whatsapp.findOne({
|
|
|
|
where: { id }
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!whatsapp) {
|
2022-04-17 21:02:15 +00:00
|
|
|
throw new AppError("ERR_NO_WAPP_FOUND", 404);
|
2022-01-06 01:26:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 21:02:15 +00:00
|
|
|
//test del
|
|
|
|
try {
|
|
|
|
await WhatsappQueue.destroy({ where: {whatsappId: id } });
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error on delete WhatsappQueue by whatsapp id: ',id)
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
await whatsapp.destroy();
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DeleteWhatsAppService;
|