mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
feat: add queue and assoc with whatsapps
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user