From 712f812abd13bf5078ac3603f0cf1db5de5aba8a Mon Sep 17 00:00:00 2001 From: Mohd Zaid Date: Wed, 21 Sep 2022 14:42:09 +0530 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20remove=20extra=20whitespaces?= =?UTF-8?q?=20from=20title=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/Modals/Campaign.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/components/Modals/Campaign.tsx b/client/src/components/Modals/Campaign.tsx index a3fa318..4ccfe2f 100644 --- a/client/src/components/Modals/Campaign.tsx +++ b/client/src/components/Modals/Campaign.tsx @@ -99,6 +99,7 @@ const CampaignModal = ({ onSubmit={async (data, { setSubmitting }) => { setSubmitting(true); let formattedData: CampaignInput = data as any; + formattedData.title = formattedData.title.replace(/\s+/g, ' ').trim(); if (data.scheduled) formattedData = formatDate(data as any); let uploadTemplate: any = { success: false }; From 657d4bb10cbf6109cdbb4e58f48963a77ccebd5d Mon Sep 17 00:00:00 2001 From: Mohd Zaid Date: Wed, 21 Sep 2022 21:21:02 +0530 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix=20toast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/utils/api.tsx | 60 +++++++++---------- client/src/utils/uploadFile.tsx | 8 +-- .../middlewares/validationMiddleware.ts | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/client/src/utils/api.tsx b/client/src/utils/api.tsx index aeabc96..a6a64e7 100644 --- a/client/src/utils/api.tsx +++ b/client/src/utils/api.tsx @@ -6,7 +6,7 @@ export const instance: AxiosInstance = axios.create({ baseURL: API_URL, }); -instance.interceptors.request.use((config)=> { +instance.interceptors.request.use(config => { const token = localStorage.getItem('token'); config.headers!.Authorization = token || ''; return config; @@ -25,8 +25,8 @@ export const handleRegister = async (payload: {}): Promise => { } return loginRes.data; } - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -38,8 +38,8 @@ export const handleLogin = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -51,8 +51,8 @@ export const fetchCampaigns = async (): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -67,7 +67,7 @@ export const postCampaigns = async (payload: any): Promise => { } return res.data; } catch (err: any) { - handleError('Oops! Something went wrong.'); + handleError(err.message); return false; } }; @@ -79,8 +79,8 @@ export const deleteCampaign = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -93,8 +93,8 @@ export const updateCampaign = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -106,8 +106,8 @@ export const fetchMailingLists = async (): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -119,8 +119,8 @@ export const postMailingList = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -132,8 +132,8 @@ export const updateMailingList = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -145,8 +145,8 @@ export const deleteMailingLists = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -158,8 +158,8 @@ export const fetchKeys = async (): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -171,8 +171,8 @@ export const postKey = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -184,8 +184,8 @@ export const deleteKey = async (payload: {}): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -196,8 +196,8 @@ export const resetKey = async (payload: string): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; @@ -209,8 +209,8 @@ export const toggleKey = async (payload: { _id: string; isEnabled: boolean }): P handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.'); + } catch (err: any) { + handleError(err.message); return false; } }; diff --git a/client/src/utils/uploadFile.tsx b/client/src/utils/uploadFile.tsx index 5306499..6fc0b1d 100644 --- a/client/src/utils/uploadFile.tsx +++ b/client/src/utils/uploadFile.tsx @@ -13,8 +13,8 @@ export const postTemplate = async (payload: string): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.', err); + } catch (err: any) { + handleError(err.message, err); return false; } }; @@ -31,8 +31,8 @@ export const postCsv = async (payload: string): Promise => { handleError(res.data.message); } return res.data; - } catch (err) { - handleError('Oops! Something went wrong.', err); + } catch (err: any) { + handleError(err.message, err); return false; } }; diff --git a/src/shared/middlewares/validationMiddleware.ts b/src/shared/middlewares/validationMiddleware.ts index 1e27153..e2b0f18 100644 --- a/src/shared/middlewares/validationMiddleware.ts +++ b/src/shared/middlewares/validationMiddleware.ts @@ -17,7 +17,7 @@ export function requestValidation(location: RequestLocation, schema: yup.AnyObje try { await schema.validate(_location); next(); - } catch (err) { + } catch (err: any) { next(new errorClass(err.message, 500)); } }; From 4af91da945eef2dac834897e3d2d8bd9c3101d89 Mon Sep 17 00:00:00 2001 From: Mohd Zaid Date: Wed, 21 Sep 2022 21:53:22 +0530 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20remove=20extra=20spaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/Modals/MailingList.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/components/Modals/MailingList.tsx b/client/src/components/Modals/MailingList.tsx index 916ed04..03a6f8e 100644 --- a/client/src/components/Modals/MailingList.tsx +++ b/client/src/components/Modals/MailingList.tsx @@ -90,7 +90,8 @@ const MailingList = ({ modal, setModal, MailingListData, updateData, createOrUpd return; } updateList(data); - const formattedData: any = data; + let formattedData: any = data; + formattedData = formattedData.name.replace(/\s+/g, ' ').trim(); delete formattedData.emailList; let result: any; if (createOrUpdate === 'create') { From 3a3bb1f0c2f7df52102afca5595e06a4aa63f295 Mon Sep 17 00:00:00 2001 From: Mohd Zaid Date: Fri, 23 Sep 2022 10:40:16 +0530 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20fix=20error=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/campaigns/controller.ts | 18 +++++++++--------- src/api/keys/controller.ts | 10 +++++----- src/api/mailingList/controller.ts | 16 ++++++++-------- src/api/user/controller.ts | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/api/campaigns/controller.ts b/src/api/campaigns/controller.ts index 5bb692b..577fd00 100644 --- a/src/api/campaigns/controller.ts +++ b/src/api/campaigns/controller.ts @@ -17,9 +17,9 @@ import { nanoid } from 'nanoid'; export const fetchCampaigns = async (next: NextFunction) => { try { return await (await database()).collection('campaign').find({}).toArray(); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in getting Campaign Data', 501)); + next(new errorClass(error.message || 'Error in getting Campaign Data', error.code || 501)); } }; @@ -53,7 +53,7 @@ export const createCampaign = async (body: any, next: NextFunction) => { try { const updatedBody = generateTemplateFromString(Body, jsonArray[i]); await sendMail([email], newCampaign.subject, updatedBody, newCampaign.senderMail); - } catch (error) { + } catch (error : any) { throw Error('Error in Generating Template'); } }); @@ -88,9 +88,9 @@ export const createCampaign = async (body: any, next: NextFunction) => { .insertOne({ ...newCampaign, launchStatus: true, templateName: body.fileName, csvFileName: body.csvFileName }); return { success: true, message: 'Campaign was created successfully' }; } - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Creating Campaign', 501)); + next(new errorClass(error.message ||'Error in Creating Campaign', error.code || 501)); } }; @@ -105,9 +105,9 @@ export const updateCampaign = async (body: any, next: NextFunction) => { await (await database()) .collection('campaign') .replaceOne({ _id: new ObjectId(id) }, { ...newCampaign, _id: new ObjectId(id) }); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Updating Campaign', 501)); + next(new errorClass(error.message ||'Error in Updating Campaign', error.code || 501)); } }; @@ -120,8 +120,8 @@ export const deleteCampaign = async (property: string, next: NextFunction) => { await (await database()) .collection('campaign') .deleteOne({ $or: [{ title: property }, { _id: new ObjectId(property) }] }); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Deleting Campaign', 501)); + next(new errorClass(error.message ||'Error in Deleting Campaign', error.code || 501)); } }; diff --git a/src/api/keys/controller.ts b/src/api/keys/controller.ts index b7746df..537a4ba 100644 --- a/src/api/keys/controller.ts +++ b/src/api/keys/controller.ts @@ -26,7 +26,7 @@ export const generateKey = async (user: string): Promise => { await (await database()).collection('keys').insertOne(newKey); return keyString; - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); if (error.message === 'User already exists') throw { code: 409, message: 'User already exists' }; throw Error('Error-' + error.message); @@ -38,7 +38,7 @@ export const toggleKey = async (_id: string, isEnabled: boolean): Promise await (await database()) .collection('keys') .updateOne({ _id: new ObjectId(_id) }, { $set: { isEnabled: isEnabled } }); - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); throw Error('Error-' + error.message); } @@ -50,7 +50,7 @@ export const resetKey = async (_id: string): Promise => { const key = encryptData(newKeyString); await (await database()).collection('keys').updateOne({ _id: new ObjectId(_id) }, { $set: { key } }); return newKeyString; - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); throw Error('Error-' + error.message); } @@ -60,7 +60,7 @@ export const fetchKeys = async (): Promise => { try { const allKeys = await (await database()).collection('keys').find({}).toArray(); return allKeys.map(decryptKey); - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); throw Error('Error-' + error.message); } @@ -70,7 +70,7 @@ export const deleteKey = async (_id: string): Promise => { const key = await (await database()).collection('keys').findOne({ _id: new ObjectId(_id) }); if (!key) throw Error('Key does not exist'); else await (await database()).collection('keys').findOneAndDelete({ _id: new ObjectId(_id) }); - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); if (error.message === 'Key does not exist') throw { code: 404, message: 'Key does not exist' }; throw Error('Error-' + error.message); diff --git a/src/api/mailingList/controller.ts b/src/api/mailingList/controller.ts index 84b021d..4928c2b 100644 --- a/src/api/mailingList/controller.ts +++ b/src/api/mailingList/controller.ts @@ -14,18 +14,18 @@ export const createMailingList = async (obj, next: NextFunction) => { const result = await (await database()).collection('mailingList').findOne({ name: mailingList.name }); if (result) next(new errorClass('Name Already Exists', 501)); await (await database()).collection('mailingList').insertOne(mailingList); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Creating New Mailing List', 501)); + next(new errorClass(error.message ||'Error in Creating New Mailing List', error.code || 501)); } }; export const getMailingList = async (next: NextFunction) => { try { return await (await database()).collection('mailingList').find({}).toArray(); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Fetching the Mailing Lists', 501)); + next(new errorClass(error.message ||'Error in Fetching the Mailing Lists', error.code || 501)); } }; @@ -36,9 +36,9 @@ export const updateMailingList = async (obj, next: NextFunction) => { await (await database()) .collection('mailingList') .replaceOne({ _id: new ObjectId(id) }, { _id: new ObjectId(id), ...mailingList }); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Updating the Mailing List', 501)); + next(new errorClass(error.message ||'Error in Updating the Mailing List', error.code || 501)); } }; @@ -47,8 +47,8 @@ export const deleteMailingList = async (id: string, next: NextFunction) => { const obj = await (await database()).collection('mailingList').findOne({ _id: new ObjectId(id) }); if (obj == null) throw Error('Mailing List does not exists'); await (await database()).collection('mailingList').deleteOne({ _id: new ObjectId(id) }); - } catch (error) { + } catch (error : any) { LoggerInstance.error(error); - next(new errorClass('Error in Deleting the mailing List', 501)); + next(new errorClass(error.message ||'Error in Deleting the mailing List', error.code || 501)); } }; diff --git a/src/api/user/controller.ts b/src/api/user/controller.ts index 98fa0d0..8b41beb 100644 --- a/src/api/user/controller.ts +++ b/src/api/user/controller.ts @@ -22,7 +22,7 @@ export const createUser = async ( password: await hash(password, 14), }; await (await database()).collection('user').insertOne(newUser); - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); if (error.message === 'User already exists') throw { code: 409, message: 'User already exists in the database' }; throw { code: 500, message: error.message }; @@ -35,7 +35,7 @@ export const userLogin = async (email: string, password: string) => { if (databaseResponse === null) throw Error('User does not exist'); if (!(await compare(password, databaseResponse.password))) throw Error('Invalid credentials'); return await signJwt({ email: email, name: databaseResponse.name }); - } catch (error) { + } catch (error: any) { LoggerInstance.error(error); throw { code: 403, message: 'User is not authorized' }; }