From e020a5f75d72d7d9690019f824556afd52b0513d Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 7 Mar 2024 18:03:46 -0300 Subject: [PATCH] fix: Update frontend to indicate lack of WhatsApp connection and adjust backend to return 422 status for WhatsApp number validation issues --- backend/src/controllers/TicketController.ts | 6 +++--- .../services/WbotServices/CheckIsValidContact.ts | 13 ++++++++----- frontend/src/components/ContactModal/index.js | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index cc7f7e8..13773b3 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -93,9 +93,9 @@ export const index = async (req: Request, res: Response): Promise => { let queueIds: number[] = []; - if (queueIdsStringified) { + if (queueIdsStringified && queueIdsStringified.trim().length > 0) { queueIds = JSON.parse(queueIdsStringified); - } + } const { tickets, count, hasMore } = await ListTicketsService({ searchParam, @@ -109,7 +109,7 @@ export const index = async (req: Request, res: Response): Promise => { unlimited, searchParamContent }); - + return res.status(200).json({ tickets, count, hasMore }); }; diff --git a/backend/src/services/WbotServices/CheckIsValidContact.ts b/backend/src/services/WbotServices/CheckIsValidContact.ts index 8060739..d663206 100644 --- a/backend/src/services/WbotServices/CheckIsValidContact.ts +++ b/backend/src/services/WbotServices/CheckIsValidContact.ts @@ -24,12 +24,13 @@ const CheckIsValidContact = async ( if (data?.isValid) { isValidNumber = data; } - } + } try { - if (!isValidNumber) { - - const { data } = await axios.post( + let _status: any; + + if (!isValidNumber) { + const { data, status } = await axios.post( `${process.env.WHATS_NUMBER_VALIDATOR_URL}/api/validate`, { mobile: number }, { @@ -40,10 +41,12 @@ const CheckIsValidContact = async ( ); isValidNumber = data; + _status = status; } - if (ignoreThrow) return isValidNumber?.number; + if (_status && _status == 422) throw new AppError("ERR_NO_WAPP_FOUND"); + if (!isValidNumber || (isValidNumber && !isValidNumber.isValid)) { throw new AppError("invalidNumber"); } diff --git a/frontend/src/components/ContactModal/index.js b/frontend/src/components/ContactModal/index.js index 5b4d924..95e16e9 100644 --- a/frontend/src/components/ContactModal/index.js +++ b/frontend/src/components/ContactModal/index.js @@ -125,11 +125,11 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => { } handleClose() } - toast.success(i18n.t("contactModal.success")) - setSaving(false) + toast.success(i18n.t("contactModal.success")) } catch (err) { toastError(err) } + setSaving(false) } return (