mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
fix: customer API schema.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user