mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 16:19:49 +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;
|
const { id: contactId } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contact = await this.customersService.getCustomer(tenantId, contactId)
|
const customer = await this.customersService.getCustomer(tenantId, contactId);
|
||||||
return res.status(200).send({ contact });
|
return res.status(200).send({ customer });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import {
|
|||||||
IPaginationMeta,
|
IPaginationMeta,
|
||||||
ICustomersFilter,
|
ICustomersFilter,
|
||||||
IContactNewDTO,
|
IContactNewDTO,
|
||||||
IContactEditDTO
|
IContactEditDTO,
|
||||||
|
IContact
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import { ServiceError } from 'exceptions';
|
import { ServiceError } from 'exceptions';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
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.
|
* Creates a new customer.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -153,7 +161,8 @@ export default class CustomersService {
|
|||||||
* @param {number} customerId
|
* @param {number} customerId
|
||||||
*/
|
*/
|
||||||
public async getCustomer(tenantId: number, customerId: number) {
|
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 {
|
return {
|
||||||
customers: results,
|
customers: results.map(this.transformContactToCustomer),
|
||||||
pagination,
|
pagination,
|
||||||
filterMeta: dynamicList.getResponseMeta(),
|
filterMeta: dynamicList.getResponseMeta(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user