diff --git a/server/src/api/controllers/Contacts/Customers.ts b/server/src/api/controllers/Contacts/Customers.ts index 80481a57a..5f12cc1ae 100644 --- a/server/src/api/controllers/Contacts/Customers.ts +++ b/server/src/api/controllers/Contacts/Customers.ts @@ -175,8 +175,8 @@ export default class CustomersController extends ContactsController { const { id: contactId } = req.params; try { - const contact = await this.customersService.getCustomer(tenantId, contactId) - return res.status(200).send({ contact }); + const customer = await this.customersService.getCustomer(tenantId, contactId); + return res.status(200).send({ customer }); } catch (error) { next(error); } diff --git a/server/src/services/Contacts/CustomersService.ts b/server/src/services/Contacts/CustomersService.ts index 3649b810a..089de0612 100644 --- a/server/src/services/Contacts/CustomersService.ts +++ b/server/src/services/Contacts/CustomersService.ts @@ -14,7 +14,8 @@ import { IPaginationMeta, ICustomersFilter, IContactNewDTO, - IContactEditDTO + IContactEditDTO, + IContact } from 'interfaces'; import { ServiceError } from 'exceptions'; import TenancyService from 'services/Tenancy/TenancyService'; @@ -65,6 +66,13 @@ export default class CustomersService { } } + private transformContactToCustomer(contactModel: IContact) { + return { + ...omit(contactModel, ['contactService', 'contactType']), + customerType: contactModel.contactService, + }; + } + /** * Creates a new customer. * @param {number} tenantId @@ -153,7 +161,8 @@ export default class CustomersService { * @param {number} customerId */ public async getCustomer(tenantId: number, customerId: number) { - return this.contactService.getContact(tenantId, customerId, 'customer'); + const contact = await this.contactService.getContact(tenantId, customerId, 'customer'); + return this.transformContactToCustomer(contact); } /** @@ -177,7 +186,7 @@ export default class CustomersService { ); return { - customers: results, + customers: results.map(this.transformContactToCustomer), pagination, filterMeta: dynamicList.getResponseMeta(), };