fix: customer API schema.

This commit is contained in:
Ahmed Bouhuolia
2020-11-09 21:57:52 +02:00
parent 4a41df6b01
commit af37fe8cba
2 changed files with 14 additions and 5 deletions

View File

@@ -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(),
};