feat: universal search.

This commit is contained in:
a.bouhuolia
2021-08-21 18:59:49 +02:00
parent a7b0f1a8d2
commit 79c1b2ab67
82 changed files with 2497 additions and 317 deletions

View File

@@ -23,6 +23,7 @@ import { ServiceError } from 'exceptions';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import TenancyService from 'services/Tenancy/TenancyService';
import events from 'subscribers/events';
import VendorTransfromer from './Vendors/VendorTransformer';
const ERRORS = {
VENDOR_HAS_TRANSACTIONS: 'VENDOR_HAS_TRANSACTIONS',
@@ -51,6 +52,9 @@ export default class VendorsService {
@Inject('BillPayments')
billPaymentsService: IBillPaymentsService;
@Inject()
vendorTransformer: VendorTransfromer;
/**
* Converts vendor to contact DTO.
* @param {IVendorNewDTO|IVendorEditDTO} vendorDTO
@@ -139,8 +143,8 @@ export default class VendorsService {
/**
* Validate the given vendor has no associated transactions.
* @param {number} tenantId
* @param {number} vendorId
* @param {number} tenantId
* @param {number} vendorId
*/
private async validateAssociatedTransactions(
tenantId: number,
@@ -151,8 +155,10 @@ export default class VendorsService {
await this.billsService.validateVendorHasNoBills(tenantId, vendorId);
// Validate vendor has no paymentys.
await this.billPaymentsService.validateVendorHasNoPayments(tenantId, vendorId);
await this.billPaymentsService.validateVendorHasNoPayments(
tenantId,
vendorId
);
} catch (error) {
throw new ServiceError(ERRORS.VENDOR_HAS_TRANSACTIONS);
}
@@ -196,7 +202,9 @@ export default class VendorsService {
* @param {number} vendorId
*/
public async getVendor(tenantId: number, vendorId: number) {
return this.contactService.getContact(tenantId, vendorId, 'vendor');
const vendor = this.contactService.getContact(tenantId, vendorId, 'vendor');
return this.vendorTransformer.transform(vendor);
}
/**
@@ -257,9 +265,7 @@ export default class VendorsService {
}
private parseVendorsListFilterDTO(filterDTO) {
return R.compose(
this.dynamicListService.parseStringifiedFilter
)(filterDTO);
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
}
/**
@@ -297,7 +303,7 @@ export default class VendorsService {
.pagination(filter.page - 1, filter.pageSize);
return {
vendors: results,
vendors: this.vendorTransformer.transform(results),
pagination,
filterMeta: dynamicList.getResponseMeta(),
};