Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra whitespaces in Title #50

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/components/Modals/Campaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Modals/MailingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
60 changes: 30 additions & 30 deletions client/src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,8 +25,8 @@ export const handleRegister = async (payload: {}): Promise<any> => {
}
return loginRes.data;
}
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -38,8 +38,8 @@ export const handleLogin = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -51,8 +51,8 @@ export const fetchCampaigns = async (): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -67,7 +67,7 @@ export const postCampaigns = async (payload: any): Promise<any> => {
}
return res.data;
} catch (err: any) {
handleError('Oops! Something went wrong.');
handleError(err.message);
return false;
}
};
Expand All @@ -79,8 +79,8 @@ export const deleteCampaign = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -93,8 +93,8 @@ export const updateCampaign = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -106,8 +106,8 @@ export const fetchMailingLists = async (): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -119,8 +119,8 @@ export const postMailingList = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -132,8 +132,8 @@ export const updateMailingList = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -145,8 +145,8 @@ export const deleteMailingLists = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -158,8 +158,8 @@ export const fetchKeys = async (): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -171,8 +171,8 @@ export const postKey = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -184,8 +184,8 @@ export const deleteKey = async (payload: {}): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -196,8 +196,8 @@ export const resetKey = async (payload: string): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.');
} catch (err: any) {
handleError(err.message);
return false;
}
};
Expand All @@ -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;
}
};
Expand Down
8 changes: 4 additions & 4 deletions client/src/utils/uploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const postTemplate = async (payload: string): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.', err);
} catch (err: any) {
handleError(err.message, err);
return false;
}
};
Expand All @@ -31,8 +31,8 @@ export const postCsv = async (payload: string): Promise<any> => {
handleError(res.data.message);
}
return res.data;
} catch (err) {
handleError('Oops! Something went wrong.', err);
} catch (err: any) {
handleError(err.message, err);
return false;
}
};
Expand Down
18 changes: 9 additions & 9 deletions src/api/campaigns/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -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');
}
});
Expand Down Expand Up @@ -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));
}
};

Expand All @@ -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));
}
};

Expand All @@ -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));
}
};
10 changes: 5 additions & 5 deletions src/api/keys/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const generateKey = async (user: string): Promise<string> => {

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);
Expand All @@ -38,7 +38,7 @@ export const toggleKey = async (_id: string, isEnabled: boolean): Promise<void>
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);
}
Expand All @@ -50,7 +50,7 @@ export const resetKey = async (_id: string): Promise<string> => {
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);
}
Expand All @@ -60,7 +60,7 @@ export const fetchKeys = async (): Promise<Key[]> => {
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);
}
Expand All @@ -70,7 +70,7 @@ export const deleteKey = async (_id: string): Promise<void> => {
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);
Expand Down
16 changes: 8 additions & 8 deletions src/api/mailingList/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand All @@ -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));
}
};

Expand All @@ -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));
}
};
4 changes: 2 additions & 2 deletions src/api/user/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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' };
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/middlewares/validationMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
Expand Down