From 38bb165211c7d86ff2989696d6866d81ca635f74 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Mon, 2 Aug 2021 11:20:03 +0200 Subject: [PATCH] fix: disable dynamic list in contacts resource. --- .../src/api/controllers/Contacts/Contacts.ts | 4 +-- server/src/api/controllers/Resources.ts | 10 +++--- .../src/services/Contacts/ContactsService.ts | 34 +++++++++++++------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/server/src/api/controllers/Contacts/Contacts.ts b/server/src/api/controllers/Contacts/Contacts.ts index f2c257639..bc8354e3b 100644 --- a/server/src/api/controllers/Contacts/Contacts.ts +++ b/server/src/api/controllers/Contacts/Contacts.ts @@ -1,6 +1,7 @@ import { check, param, query, body, ValidationChain } from 'express-validator'; import { Router, Request, Response, NextFunction } from 'express'; import { Inject, Service } from 'typedi'; +import * as R from 'ramda'; import BaseController from 'api/controllers/BaseController'; import ContactsService from 'services/Contacts/ContactsService'; import DynamicListingService from 'services/DynamicListing/DynamicListService'; @@ -87,9 +88,6 @@ export default class ContactsController extends BaseController { limit: 10, ...this.matchedQueryData(req), }; - if (filter.stringifiedFilterRoles) { - filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles); - } try { const contacts = await this.contactsService.autocompleteContacts( tenantId, diff --git a/server/src/api/controllers/Resources.ts b/server/src/api/controllers/Resources.ts index a28bb6045..f10b4cb53 100644 --- a/server/src/api/controllers/Resources.ts +++ b/server/src/api/controllers/Resources.ts @@ -84,13 +84,13 @@ export default class ResourceController extends BaseController { const { resource_model: resourceModel } = req.params; try { - const resourceFields = this.resourcesService.getResourceFields( - tenantId, - resourceModel - ); + // const resourceFields = this.resourcesService.getResourceFields( + // tenantId, + // resourceModel + // ); return res.status(200).send({ - resource_fields: this.transfromToResponse(resourceFields), + resource_fields: [], }); } catch (error) { next(error); diff --git a/server/src/services/Contacts/ContactsService.ts b/server/src/services/Contacts/ContactsService.ts index 3a71df82b..718692fed 100644 --- a/server/src/services/Contacts/ContactsService.ts +++ b/server/src/services/Contacts/ContactsService.ts @@ -1,6 +1,7 @@ import { Inject, Service } from 'typedi'; import { difference, upperFirst, omit } from 'lodash'; import moment from 'moment'; +import * as R from 'ramda'; import { ServiceError } from 'exceptions'; import TenancyService from 'services/Tenancy/TenancyService'; import DynamicListingService from 'services/DynamicListing/DynamicListService'; @@ -205,6 +206,16 @@ export default class ContactsService { return this.getContactByIdOrThrowError(tenantId, contactId, contactService); } + /** + * Parsees accounts list filter DTO. + * @param filterDTO + */ + private parseAutocompleteListFilterDTO(filterDTO) { + return R.compose( + this.dynamicListService.parseStringifiedFilter + )(filterDTO); + } + /** * Retrieve auto-complete contacts list. * @param {number} tenantId - @@ -213,23 +224,26 @@ export default class ContactsService { */ async autocompleteContacts( tenantId: number, - contactsFilter: IContactsAutoCompleteFilter + query: IContactsAutoCompleteFilter ) { const { Contact } = this.tenancy.models(tenantId); + // Parses auto-complete list filter DTO. + const filter = this.parseAutocompleteListFilterDTO(query); + // Dynamic list. - const dynamicList = await this.dynamicListService.dynamicList( - tenantId, - Contact, - contactsFilter - ); + // const dynamicList = await this.dynamicListService.dynamicList( + // tenantId, + // Contact, + // filter + // ); // Retrieve contacts list by the given query. const contacts = await Contact.query().onBuild((builder) => { - if (contactsFilter.keyword) { - builder.where('display_name', 'LIKE', `%${contactsFilter.keyword}%`); + if (filter.keyword) { + builder.where('display_name', 'LIKE', `%${filter.keyword}%`); } - dynamicList.buildQuery()(builder); - builder.limit(contactsFilter.limit); + // dynamicList.buildQuery()(builder); + builder.limit(filter.limit); }); return contacts; }