feat: removed optionNumber from queues assocs

This commit is contained in:
canove
2021-01-11 06:38:45 -03:00
parent a75eb49b31
commit be320fa34b
11 changed files with 39 additions and 94 deletions

View File

@@ -4,13 +4,9 @@ import AppError from "../../errors/AppError";
import Whatsapp from "../../models/Whatsapp";
import AssociateWhatsappQueue from "../QueueService/AssociateWhatsappQueue";
interface QueueData {
id: number;
optionNumber: number;
}
interface Request {
name: string;
queuesData: QueueData[];
queueIds?: number[];
greetingMessage?: string;
status?: string;
isDefault?: boolean;
@@ -24,7 +20,7 @@ interface Response {
const CreateWhatsAppService = async ({
name,
status = "OPENING",
queuesData = [],
queueIds = [],
greetingMessage,
isDefault = false
}: Request): Promise<Response> => {
@@ -71,6 +67,10 @@ const CreateWhatsAppService = async ({
}
}
if (queueIds.length > 1 && !greetingMessage) {
throw new AppError("ERR_WAPP_GREETING_REQUIRED");
}
const whatsapp = await Whatsapp.create(
{
name,
@@ -81,9 +81,7 @@ const CreateWhatsAppService = async ({
{ include: ["queues"] }
);
await AssociateWhatsappQueue(whatsapp, queuesData);
await whatsapp.reload();
await AssociateWhatsappQueue(whatsapp, queueIds);
return { whatsapp, oldDefaultWhatsapp };
};