mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: customer form styling.
feat: customers list.
This commit is contained in:
@@ -12,12 +12,15 @@ import {
|
||||
ICustomerEditDTO,
|
||||
ICustomer,
|
||||
IPaginationMeta,
|
||||
ICustomersFilter
|
||||
ICustomersFilter,
|
||||
IContactNewDTO,
|
||||
IContactEditDTO
|
||||
} from 'interfaces';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import events from 'subscribers/events';
|
||||
import moment from 'moment';
|
||||
|
||||
@Service()
|
||||
export default class CustomersService {
|
||||
@@ -41,7 +44,7 @@ export default class CustomersService {
|
||||
* @param {ICustomerNewDTO|ICustomerEditDTO} customerDTO
|
||||
* @returns {IContactDTO}
|
||||
*/
|
||||
private customerToContactDTO(customerDTO: ICustomerNewDTO | ICustomerEditDTO) {
|
||||
private customerToContactDTO(customerDTO: ICustomerNewDTO|ICustomerEditDTO): IContactNewDTO|IContactEditDTO {
|
||||
return {
|
||||
...omit(customerDTO, ['customerType']),
|
||||
contactType: customerDTO.customerType,
|
||||
@@ -50,6 +53,18 @@ export default class CustomersService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms new customer DTO to contact.
|
||||
* @param customerDTO
|
||||
*/
|
||||
private transformNewCustomerDTO(customerDTO: ICustomerNewDTO): IContactNewDTO {
|
||||
return {
|
||||
...this.customerToContactDTO(customerDTO),
|
||||
openingBalanceAt: customerDTO?.openingBalanceAt
|
||||
? moment(customerDTO.openingBalanceAt).toMySqlDateTime() : null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new customer.
|
||||
* @param {number} tenantId
|
||||
@@ -62,8 +77,8 @@ export default class CustomersService {
|
||||
): Promise<ICustomer> {
|
||||
this.logger.info('[customer] trying to create a new customer.', { tenantId, customerDTO });
|
||||
|
||||
const contactDTO = this.customerToContactDTO(customerDTO)
|
||||
const customer = await this.contactService.newContact(tenantId, contactDTO, 'customer');
|
||||
const customerObj = this.transformNewCustomerDTO(customerDTO);
|
||||
const customer = await this.contactService.newContact(tenantId, customerObj, 'customer');
|
||||
|
||||
this.logger.info('[customer] created successfully.', { tenantId, customerDTO });
|
||||
await this.eventDispatcher.dispatch(events.customers.onCreated, {
|
||||
|
||||
Reference in New Issue
Block a user