feat: add queue and assoc with whatsapps

This commit is contained in:
canove
2021-01-08 17:41:08 -03:00
parent a12c9db731
commit 9f99245dc4
14 changed files with 217 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import Whatsapp from "../../models/Whatsapp";
interface Request {
name: string;
queueIds: number[];
status?: string;
isDefault?: boolean;
}
@@ -17,6 +18,7 @@ interface Response {
const CreateWhatsAppService = async ({
name,
status = "OPENING",
queueIds,
isDefault = false
}: Request): Promise<Response> => {
const schema = Yup.object().shape({
@@ -68,6 +70,8 @@ const CreateWhatsAppService = async ({
isDefault
});
await whatsapp.$set("queues", queueIds);
return { whatsapp, oldDefaultWhatsapp };
};

View File

@@ -1,7 +1,12 @@
import Queue from "../../models/Queue";
import Whatsapp from "../../models/Whatsapp";
const ListWhatsAppsService = async (): Promise<Whatsapp[]> => {
const whatsapps = await Whatsapp.findAll();
const whatsapps = await Whatsapp.findAll({
include: [
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
]
});
return whatsapps;
};

View File

@@ -9,6 +9,7 @@ interface WhatsappData {
status?: string;
session?: string;
isDefault?: boolean;
queueIds?: number[];
}
interface Request {
@@ -30,7 +31,7 @@ const UpdateWhatsAppService = async ({
isDefault: Yup.boolean()
});
const { name, status, isDefault, session } = whatsappData;
const { name, status, isDefault, session, queueIds = [] } = whatsappData;
try {
await schema.validate({ name, status, isDefault });
@@ -63,6 +64,8 @@ const UpdateWhatsAppService = async ({
isDefault
});
await whatsapp.$set("queues", queueIds);
return { whatsapp, oldDefaultWhatsapp };
};