mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
fix(Contacts): transform create/edit DTO.
This commit is contained in:
@@ -62,12 +62,7 @@ export default class ContactsService {
|
|||||||
* Converts contact DTO object to model object attributes to insert or update.
|
* Converts contact DTO object to model object attributes to insert or update.
|
||||||
* @param {IContactNewDTO | IContactEditDTO} contactDTO
|
* @param {IContactNewDTO | IContactEditDTO} contactDTO
|
||||||
*/
|
*/
|
||||||
private transformContactObj(contactDTO: IContactNewDTO | IContactEditDTO) {
|
private commonTransformContactObj(contactDTO: IContactNewDTO | IContactEditDTO) {
|
||||||
const baseCurrency = 'USD';
|
|
||||||
const currencyCode = typeof contactDTO.currencyCode !== 'undefined'
|
|
||||||
? contactDTO.currencyCode
|
|
||||||
: baseCurrency;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...omit(contactDTO, [
|
...omit(contactDTO, [
|
||||||
'billingAddress1',
|
'billingAddress1',
|
||||||
@@ -79,10 +74,35 @@ export default class ContactsService {
|
|||||||
billing_address_2: contactDTO?.billingAddress2,
|
billing_address_2: contactDTO?.billingAddress2,
|
||||||
shipping_address_1: contactDTO?.shippingAddress1,
|
shipping_address_1: contactDTO?.shippingAddress1,
|
||||||
shipping_address_2: contactDTO?.shippingAddress2,
|
shipping_address_2: contactDTO?.shippingAddress2,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms contact new DTO object to model object to insert to the storage.
|
||||||
|
* @param {IContactNewDTO} contactDTO
|
||||||
|
*/
|
||||||
|
private transformNewContactDTO(contactDTO: IContactNewDTO) {
|
||||||
|
const baseCurrency = 'USD';
|
||||||
|
const currencyCode = typeof contactDTO.currencyCode !== 'undefined'
|
||||||
|
? contactDTO.currencyCode
|
||||||
|
: baseCurrency;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...this.commonTransformContactObj(contactDTO),
|
||||||
...(currencyCode ? ({ currencyCode }) : {}),
|
...(currencyCode ? ({ currencyCode }) : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms contact edit DTO object to model object to update to the storage.
|
||||||
|
* @param {IContactEditDTO} contactDTO
|
||||||
|
*/
|
||||||
|
private transformEditContactDTO(contactDTO: IContactEditDTO) {
|
||||||
|
return {
|
||||||
|
...this.commonTransformContactObj(contactDTO),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new contact on the storage.
|
* Creates a new contact on the storage.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -95,7 +115,7 @@ export default class ContactsService {
|
|||||||
contactService: TContactService
|
contactService: TContactService
|
||||||
) {
|
) {
|
||||||
const { contactRepository } = this.tenancy.repositories(tenantId);
|
const { contactRepository } = this.tenancy.repositories(tenantId);
|
||||||
const contactObj = this.transformContactObj(contactDTO);
|
const contactObj = this.transformNewContactDTO(contactDTO);
|
||||||
|
|
||||||
this.logger.info('[contacts] trying to insert contact to the storage.', {
|
this.logger.info('[contacts] trying to insert contact to the storage.', {
|
||||||
tenantId,
|
tenantId,
|
||||||
@@ -126,7 +146,7 @@ export default class ContactsService {
|
|||||||
contactService: TContactService
|
contactService: TContactService
|
||||||
) {
|
) {
|
||||||
const { contactRepository } = this.tenancy.repositories(tenantId);
|
const { contactRepository } = this.tenancy.repositories(tenantId);
|
||||||
const contactObj = this.transformContactObj(contactDTO);
|
const contactObj = this.transformEditContactDTO(contactDTO);
|
||||||
|
|
||||||
// Retrieve the given contact by id or throw not found service error.
|
// Retrieve the given contact by id or throw not found service error.
|
||||||
const contact = await this.getContactByIdOrThrowError(
|
const contact = await this.getContactByIdOrThrowError(
|
||||||
|
|||||||
Reference in New Issue
Block a user