From b38020d3971f562ed1aafb3f93b2b1cc95bf5a8d Mon Sep 17 00:00:00 2001 From: "a.nasouf" Date: Mon, 5 Feb 2024 18:58:02 +0200 Subject: [PATCH 1/3] fix: gmail email addresses dots gets removed --- .../src/api/controllers/Contacts/Contacts.ts | 126 +++++++++--------- .../webapp/src/components/Details/index.tsx | 2 +- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/packages/server/src/api/controllers/Contacts/Contacts.ts b/packages/server/src/api/controllers/Contacts/Contacts.ts index a05ee93fd..2449e7d6f 100644 --- a/packages/server/src/api/controllers/Contacts/Contacts.ts +++ b/packages/server/src/api/controllers/Contacts/Contacts.ts @@ -1,11 +1,11 @@ -import { check, param, query, body, ValidationChain } from 'express-validator'; -import { Router, Request, Response, NextFunction } from 'express'; -import { Inject, Service } from 'typedi'; -import { ServiceError } from '@/exceptions'; -import BaseController from '@/api/controllers/BaseController'; -import ContactsService from '@/services/Contacts/ContactsService'; -import DynamicListingService from '@/services/DynamicListing/DynamicListService'; -import { DATATYPES_LENGTH } from '@/data/DataTypes'; +import { check, param, query, body, ValidationChain } from "express-validator"; +import { Router, Request, Response, NextFunction } from "express"; +import { Inject, Service } from "typedi"; +import { ServiceError } from "@/exceptions"; +import BaseController from "@/api/controllers/BaseController"; +import ContactsService from "@/services/Contacts/ContactsService"; +import DynamicListingService from "@/services/DynamicListing/DynamicListService"; +import { DATATYPES_LENGTH } from "@/data/DataTypes"; @Service() export default class ContactsController extends BaseController { @@ -22,28 +22,28 @@ export default class ContactsController extends BaseController { const router = Router(); router.get( - '/auto-complete', + "/auto-complete", [...this.autocompleteQuerySchema], this.validationResult, this.asyncMiddleware(this.autocompleteContacts.bind(this)), this.dynamicListService.handlerErrorsToResponse ); router.get( - '/:id', - [param('id').exists().isNumeric().toInt()], + "/:id", + [param("id").exists().isNumeric().toInt()], this.validationResult, this.asyncMiddleware(this.getContact.bind(this)) ); router.post( - '/:id/inactivate', - [param('id').exists().isNumeric().toInt()], + "/:id/inactivate", + [param("id").exists().isNumeric().toInt()], this.validationResult, this.asyncMiddleware(this.inactivateContact.bind(this)), this.handlerServiceErrors ); router.post( - '/:id/activate', - [param('id').exists().isNumeric().toInt()], + "/:id/activate", + [param("id").exists().isNumeric().toInt()], this.validationResult, this.asyncMiddleware(this.activateContact.bind(this)), this.handlerServiceErrors @@ -56,11 +56,11 @@ export default class ContactsController extends BaseController { */ get autocompleteQuerySchema() { return [ - query('column_sort_by').optional().trim().escape(), - query('sort_order').optional().isIn(['desc', 'asc']), + query("column_sort_by").optional().trim().escape(), + query("sort_order").optional().isIn(["desc", "asc"]), - query('stringified_filter_roles').optional().isJSON(), - query('limit').optional().isNumeric().toInt(), + query("stringified_filter_roles").optional().isJSON(), + query("limit").optional().isNumeric().toInt(), ]; } @@ -97,8 +97,8 @@ export default class ContactsController extends BaseController { const { tenantId } = req; const filter = { filterRoles: [], - sortOrder: 'asc', - columnSortBy: 'display_name', + sortOrder: "asc", + columnSortBy: "display_name", limit: 10, ...this.matchedQueryData(req), }; @@ -118,170 +118,170 @@ export default class ContactsController extends BaseController { */ get contactDTOSchema(): ValidationChain[] { return [ - check('salutation') + check("salutation") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('first_name') + check("first_name") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('last_name') + check("last_name") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('company_name') + check("company_name") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('display_name') + check("display_name") .exists() .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('email') + check("email") .optional({ nullable: true }) .isString() - .normalizeEmail() + .normalizeEmail({ gmail_remove_dots: false }) .isEmail() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('website') + check("website") .optional({ nullable: true }) .isString() .trim() .isURL() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('work_phone') + check("work_phone") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('personal_phone') + check("personal_phone") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_1') + check("billing_address_1") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_2') + check("billing_address_2") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_city') + check("billing_address_city") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_country') + check("billing_address_country") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_email') + check("billing_address_email") .optional({ nullable: true }) .isString() .isEmail() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_postcode') + check("billing_address_postcode") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_phone') + check("billing_address_phone") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('billing_address_state') + check("billing_address_state") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_1') + check("shipping_address_1") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_2') + check("shipping_address_2") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_city') + check("shipping_address_city") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_country') + check("shipping_address_country") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_email') + check("shipping_address_email") .optional({ nullable: true }) .isString() .isEmail() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_postcode') + check("shipping_address_postcode") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_phone') + check("shipping_address_phone") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('shipping_address_state') + check("shipping_address_state") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check('note') + check("note") .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.TEXT }), - check('active').optional().isBoolean().toBoolean(), + check("active").optional().isBoolean().toBoolean(), ]; } @@ -291,19 +291,19 @@ export default class ContactsController extends BaseController { */ get contactNewDTOSchema(): ValidationChain[] { return [ - check('opening_balance') + check("opening_balance") .optional({ nullable: true }) .isInt({ min: 0, max: DATATYPES_LENGTH.DECIMAL_13_3 }) .toInt(), - check('opening_balance_exchange_rate') + check("opening_balance_exchange_rate") .default(1) .isFloat({ gt: 0 }) .toFloat(), - body('opening_balance_at') - .if(body('opening_balance').exists()) + body("opening_balance_at") + .if(body("opening_balance").exists()) .exists() .isISO8601(), - check('opening_balance_branch_id') + check("opening_balance_branch_id") .optional({ nullable: true }) .isNumeric() .toInt(), @@ -322,7 +322,7 @@ export default class ContactsController extends BaseController { * @returns {ValidationChain[]} */ get specificContactSchema(): ValidationChain[] { - return [param('id').exists().isNumeric().toInt()]; + return [param("id").exists().isNumeric().toInt()]; } /** @@ -340,7 +340,7 @@ export default class ContactsController extends BaseController { return res.status(200).send({ id: contactId, - message: 'The given contact activated successfully.', + message: "The given contact activated successfully.", }); } catch (error) { next(error); @@ -362,7 +362,7 @@ export default class ContactsController extends BaseController { return res.status(200).send({ id: contactId, - message: 'The given contact inactivated successfully.', + message: "The given contact inactivated successfully.", }); } catch (error) { next(error); @@ -383,19 +383,19 @@ export default class ContactsController extends BaseController { next: NextFunction ) { if (error instanceof ServiceError) { - if (error.errorType === 'contact_not_found') { + if (error.errorType === "contact_not_found") { return res.boom.badRequest(null, { - errors: [{ type: 'CONTACT.NOT.FOUND', code: 100 }], + errors: [{ type: "CONTACT.NOT.FOUND", code: 100 }], }); } - if (error.errorType === 'CONTACT_ALREADY_ACTIVE') { + if (error.errorType === "CONTACT_ALREADY_ACTIVE") { return res.boom.badRequest(null, { - errors: [{ type: 'CONTACT_ALREADY_ACTIVE', code: 700 }], + errors: [{ type: "CONTACT_ALREADY_ACTIVE", code: 700 }], }); } - if (error.errorType === 'CONTACT_ALREADY_INACTIVE') { + if (error.errorType === "CONTACT_ALREADY_INACTIVE") { return res.boom.badRequest(null, { - errors: [{ type: 'CONTACT_ALREADY_INACTIVE', code: 800 }], + errors: [{ type: "CONTACT_ALREADY_INACTIVE", code: 800 }], }); } } diff --git a/packages/webapp/src/components/Details/index.tsx b/packages/webapp/src/components/Details/index.tsx index e6803b069..9879fc7c0 100644 --- a/packages/webapp/src/components/Details/index.tsx +++ b/packages/webapp/src/components/Details/index.tsx @@ -66,7 +66,7 @@ export function DetailItem({ label, children, name, align, className }) { > {label} -
{children}
+
{children}
); } From f7f77b12c9d70b9b89f56d18ec9a368b6f1b568d Mon Sep 17 00:00:00 2001 From: "a.nasouf" Date: Mon, 5 Feb 2024 20:05:10 +0200 Subject: [PATCH 2/3] fix: file formatting --- .../src/api/controllers/Contacts/Contacts.ts | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/packages/server/src/api/controllers/Contacts/Contacts.ts b/packages/server/src/api/controllers/Contacts/Contacts.ts index 2449e7d6f..751654a8e 100644 --- a/packages/server/src/api/controllers/Contacts/Contacts.ts +++ b/packages/server/src/api/controllers/Contacts/Contacts.ts @@ -1,11 +1,11 @@ -import { check, param, query, body, ValidationChain } from "express-validator"; -import { Router, Request, Response, NextFunction } from "express"; -import { Inject, Service } from "typedi"; -import { ServiceError } from "@/exceptions"; -import BaseController from "@/api/controllers/BaseController"; -import ContactsService from "@/services/Contacts/ContactsService"; -import DynamicListingService from "@/services/DynamicListing/DynamicListService"; -import { DATATYPES_LENGTH } from "@/data/DataTypes"; +import { check, param, query, body, ValidationChain } from 'express-validator'; +import { Router, Request, Response, NextFunction } from 'express'; +import { Inject, Service } from 'typedi'; +import { ServiceError } from '@/exceptions'; +import BaseController from '@/api/controllers/BaseController'; +import ContactsService from '@/services/Contacts/ContactsService'; +import DynamicListingService from '@/services/DynamicListing/DynamicListService'; +import { DATATYPES_LENGTH } from '@/data/DataTypes'; @Service() export default class ContactsController extends BaseController { @@ -22,31 +22,31 @@ export default class ContactsController extends BaseController { const router = Router(); router.get( - "/auto-complete", + '/auto-complete', [...this.autocompleteQuerySchema], this.validationResult, this.asyncMiddleware(this.autocompleteContacts.bind(this)), - this.dynamicListService.handlerErrorsToResponse + this.dynamicListService.handlerErrorsToResponse, ); router.get( - "/:id", - [param("id").exists().isNumeric().toInt()], + '/:id', + [param('id').exists().isNumeric().toInt()], this.validationResult, - this.asyncMiddleware(this.getContact.bind(this)) + this.asyncMiddleware(this.getContact.bind(this)), ); router.post( - "/:id/inactivate", - [param("id").exists().isNumeric().toInt()], + '/:id/inactivate', + [param('id').exists().isNumeric().toInt()], this.validationResult, this.asyncMiddleware(this.inactivateContact.bind(this)), - this.handlerServiceErrors + this.handlerServiceErrors, ); router.post( - "/:id/activate", - [param("id").exists().isNumeric().toInt()], + '/:id/activate', + [param('id').exists().isNumeric().toInt()], this.validationResult, this.asyncMiddleware(this.activateContact.bind(this)), - this.handlerServiceErrors + this.handlerServiceErrors, ); return router; } @@ -56,11 +56,11 @@ export default class ContactsController extends BaseController { */ get autocompleteQuerySchema() { return [ - query("column_sort_by").optional().trim().escape(), - query("sort_order").optional().isIn(["desc", "asc"]), + query('column_sort_by').optional().trim().escape(), + query('sort_order').optional().isIn(['desc', 'asc']), - query("stringified_filter_roles").optional().isJSON(), - query("limit").optional().isNumeric().toInt(), + query('stringified_filter_roles').optional().isJSON(), + query('limit').optional().isNumeric().toInt(), ]; } @@ -77,7 +77,7 @@ export default class ContactsController extends BaseController { try { const contact = await this.contactsService.getContact( tenantId, - contactId + contactId, ); return res.status(200).send({ customer: this.transfromToResponse(contact), @@ -97,15 +97,15 @@ export default class ContactsController extends BaseController { const { tenantId } = req; const filter = { filterRoles: [], - sortOrder: "asc", - columnSortBy: "display_name", + sortOrder: 'asc', + columnSortBy: 'display_name', limit: 10, ...this.matchedQueryData(req), }; try { const contacts = await this.contactsService.autocompleteContacts( tenantId, - filter + filter, ); return res.status(200).send({ contacts }); } catch (error) { @@ -118,170 +118,170 @@ export default class ContactsController extends BaseController { */ get contactDTOSchema(): ValidationChain[] { return [ - check("salutation") + check('salutation') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("first_name") + check('first_name') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("last_name") + check('last_name') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("company_name") + check('company_name') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("display_name") + check('display_name') .exists() .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("email") + check('email') .optional({ nullable: true }) .isString() .normalizeEmail({ gmail_remove_dots: false }) .isEmail() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("website") + check('website') .optional({ nullable: true }) .isString() .trim() .isURL() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("work_phone") + check('work_phone') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("personal_phone") + check('personal_phone') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_1") + check('billing_address_1') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_2") + check('billing_address_2') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_city") + check('billing_address_city') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_country") + check('billing_address_country') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_email") + check('billing_address_email') .optional({ nullable: true }) .isString() .isEmail() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_postcode") + check('billing_address_postcode') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_phone") + check('billing_address_phone') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("billing_address_state") + check('billing_address_state') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_1") + check('shipping_address_1') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_2") + check('shipping_address_2') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_city") + check('shipping_address_city') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_country") + check('shipping_address_country') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_email") + check('shipping_address_email') .optional({ nullable: true }) .isString() .isEmail() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_postcode") + check('shipping_address_postcode') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_phone") + check('shipping_address_phone') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("shipping_address_state") + check('shipping_address_state') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.STRING }), - check("note") + check('note') .optional({ nullable: true }) .isString() .trim() .escape() .isLength({ max: DATATYPES_LENGTH.TEXT }), - check("active").optional().isBoolean().toBoolean(), + check('active').optional().isBoolean().toBoolean(), ]; } @@ -291,19 +291,19 @@ export default class ContactsController extends BaseController { */ get contactNewDTOSchema(): ValidationChain[] { return [ - check("opening_balance") + check('opening_balance') .optional({ nullable: true }) .isInt({ min: 0, max: DATATYPES_LENGTH.DECIMAL_13_3 }) .toInt(), - check("opening_balance_exchange_rate") + check('opening_balance_exchange_rate') .default(1) .isFloat({ gt: 0 }) .toFloat(), - body("opening_balance_at") - .if(body("opening_balance").exists()) + body('opening_balance_at') + .if(body('opening_balance').exists()) .exists() .isISO8601(), - check("opening_balance_branch_id") + check('opening_balance_branch_id') .optional({ nullable: true }) .isNumeric() .toInt(), @@ -322,7 +322,7 @@ export default class ContactsController extends BaseController { * @returns {ValidationChain[]} */ get specificContactSchema(): ValidationChain[] { - return [param("id").exists().isNumeric().toInt()]; + return [param('id').exists().isNumeric().toInt()]; } /** @@ -340,7 +340,7 @@ export default class ContactsController extends BaseController { return res.status(200).send({ id: contactId, - message: "The given contact activated successfully.", + message: 'The given contact activated successfully.', }); } catch (error) { next(error); @@ -362,7 +362,7 @@ export default class ContactsController extends BaseController { return res.status(200).send({ id: contactId, - message: "The given contact inactivated successfully.", + message: 'The given contact inactivated successfully.', }); } catch (error) { next(error); @@ -380,22 +380,22 @@ export default class ContactsController extends BaseController { error: Error, req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { if (error instanceof ServiceError) { - if (error.errorType === "contact_not_found") { + if (error.errorType === 'contact_not_found') { return res.boom.badRequest(null, { - errors: [{ type: "CONTACT.NOT.FOUND", code: 100 }], + errors: [{ type: 'CONTACT.NOT.FOUND', code: 100 }], }); } - if (error.errorType === "CONTACT_ALREADY_ACTIVE") { + if (error.errorType === 'CONTACT_ALREADY_ACTIVE') { return res.boom.badRequest(null, { - errors: [{ type: "CONTACT_ALREADY_ACTIVE", code: 700 }], + errors: [{ type: 'CONTACT_ALREADY_ACTIVE', code: 700 }], }); } - if (error.errorType === "CONTACT_ALREADY_INACTIVE") { + if (error.errorType === 'CONTACT_ALREADY_INACTIVE') { return res.boom.badRequest(null, { - errors: [{ type: "CONTACT_ALREADY_INACTIVE", code: 800 }], + errors: [{ type: 'CONTACT_ALREADY_INACTIVE', code: 800 }], }); } } From 17dbe9713b97267a350a9cd52076ed5ba91af857 Mon Sep 17 00:00:00 2001 From: "a.nasouf" Date: Sat, 10 Feb 2024 19:59:12 +0200 Subject: [PATCH 3/3] fix: remove normalizeEmail function --- packages/server/src/api/controllers/Contacts/Contacts.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/api/controllers/Contacts/Contacts.ts b/packages/server/src/api/controllers/Contacts/Contacts.ts index 751654a8e..24b99e09f 100644 --- a/packages/server/src/api/controllers/Contacts/Contacts.ts +++ b/packages/server/src/api/controllers/Contacts/Contacts.ts @@ -153,7 +153,6 @@ export default class ContactsController extends BaseController { check('email') .optional({ nullable: true }) .isString() - .normalizeEmail({ gmail_remove_dots: false }) .isEmail() .isLength({ max: DATATYPES_LENGTH.STRING }), check('website')