feat: customer form styling.

feat: customers list.
This commit is contained in:
Ahmed Bouhuolia
2020-11-08 21:44:20 +02:00
parent 982420c8e5
commit 9241f8b8a5
17 changed files with 305 additions and 282 deletions

View File

@@ -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, {