diff --git a/backend/src/controllers/WhatsAppController.ts b/backend/src/controllers/WhatsAppController.ts index 9b0e532..c71d883 100644 --- a/backend/src/controllers/WhatsAppController.ts +++ b/backend/src/controllers/WhatsAppController.ts @@ -54,6 +54,7 @@ interface WhatsappData { isDefault?: boolean; isOfficial?: boolean; phoneNumberId?: string; + number?: string; wabaId?: string; } @@ -322,7 +323,8 @@ export const store = async (req: Request, res: Response): Promise => { urlApi, phoneNumberId, wabaId, - isOfficial + isOfficial, + number }: WhatsappData = req.body; if (req.user.profile !== "master") { @@ -333,7 +335,8 @@ export const store = async (req: Request, res: Response): Promise => { urlApi, isOfficial, phoneNumberId, - wabaId + wabaId, + number }); if (invalid) { @@ -346,6 +349,7 @@ export const store = async (req: Request, res: Response): Promise => { } else if (!isOfficial) { phoneNumberId = ""; wabaId = ""; + number = ""; } let invalidPhoneName = validatePhoneName(name); @@ -365,7 +369,8 @@ export const store = async (req: Request, res: Response): Promise => { queueIds, phoneNumberId, wabaId, - isOfficial + isOfficial, + number }); console.log("whatsapp.id: ", whatsapp.id); @@ -408,7 +413,7 @@ export const update = async ( res: Response ): Promise => { const { whatsappId } = req.params; - const whatsappData = req.body; + const whatsappData = req.body; let invalidPhoneName = validatePhoneName(whatsappData.name); @@ -549,19 +554,23 @@ interface WhatsappDataValidate { isOfficial?: boolean; phoneNumberId?: string; wabaId?: string; + number?: string; } const checkWhatsAppData = ({ urlApi, isOfficial, phoneNumberId, - wabaId + wabaId, + number }: WhatsappDataValidate) => { if (isOfficial && (!phoneNumberId || phoneNumberId.trim() == "")) { return { message: "Phone number Id is required!" }; } else if (isOfficial && (!wabaId || wabaId.trim() == "")) { return { message: "WABA ID is required!" }; + } else if (isOfficial && (!number || number.trim() == "")) { + return { message: "Phone number is required!" }; } else if (!isOfficial && (!urlApi || urlApi.trim() == "")) { return { message: "urlApi is required!" }; - } + } }; diff --git a/backend/src/helpers/RedisClient.ts b/backend/src/helpers/RedisClient.ts index aadc8c8..93c9e0a 100644 --- a/backend/src/helpers/RedisClient.ts +++ b/backend/src/helpers/RedisClient.ts @@ -17,6 +17,18 @@ export async function get(key: string) { return JSON.parse(value); } +export async function clearAllKeys() { + // Retrieve all keys matching the pattern '*' + const keys = await redis.keys("user:*"); + + // If there are keys, delete them + if (keys.length > 0) { + console.log('keys: ', keys) + await redis.del(...keys); + } +} + + export async function findByContain( key: string, keyName: string, diff --git a/backend/src/server.ts b/backend/src/server.ts index f02362b..6aa0b13 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -23,7 +23,7 @@ import fs from "fs"; import dir from "path"; import { getSettingValue } from "./helpers/WhaticketSettings"; import loadSettings from "./helpers/LoadSettings"; -import { set } from "./helpers/RedisClient"; +import { clearAllKeys, set } from "./helpers/RedisClient"; const server = app.listen(process.env.PORT, () => { logger.info(`Server started on port: ${process.env.PORT}`); @@ -39,11 +39,13 @@ const server = app.listen(process.env.PORT, () => { initIO(server); // StartAllWhatsAppsSessions(); -gracefulShutdown(server); +gracefulShutdown(server); (async () => { console.log("os.tmpdir(): ", os.tmpdir()); + await clearAllKeys(); + const users = await User.findAll(); for (const user of users) { diff --git a/backend/src/services/WhatsappService/CreateWhatsAppService.ts b/backend/src/services/WhatsappService/CreateWhatsAppService.ts index 2693709..879bde4 100644 --- a/backend/src/services/WhatsappService/CreateWhatsAppService.ts +++ b/backend/src/services/WhatsappService/CreateWhatsAppService.ts @@ -16,6 +16,7 @@ interface Request { phoneNumberId?: string; wabaId?: string; isOfficial?: boolean; + number?: string; } interface Response { @@ -34,7 +35,8 @@ const CreateWhatsAppService = async ({ isDefault = false, isOfficial = false, phoneNumberId, - wabaId + wabaId, + number }: Request): Promise => { try { const schema = Yup.object().shape({ @@ -98,6 +100,7 @@ const CreateWhatsAppService = async ({ phoneNumberId, wabaId, isOfficial, + number, classification }, { include: ["queues"] } diff --git a/frontend/src/components/WhatsAppModal/index.js b/frontend/src/components/WhatsAppModal/index.js index 4468aaf..0ee0533 100644 --- a/frontend/src/components/WhatsAppModal/index.js +++ b/frontend/src/components/WhatsAppModal/index.js @@ -70,6 +70,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => { farewellMessage: '', isDefault: false, isOfficial: false, + number: '', phoneNumberId: '', wabaId: '' } @@ -109,6 +110,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => { if (!isOfficial) { values.phoneNumberId = '' values.wabaId = '' + values.number = '' } @@ -276,6 +278,18 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => { margin="dense" className={classes.textField} /> + +