fix: disable dynamic list in contacts resource.

This commit is contained in:
a.bouhuolia
2021-08-02 11:20:03 +02:00
parent 4b424a8e01
commit 38bb165211
3 changed files with 30 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
import { check, param, query, body, ValidationChain } from 'express-validator'; import { check, param, query, body, ValidationChain } from 'express-validator';
import { Router, Request, Response, NextFunction } from 'express'; import { Router, Request, Response, NextFunction } from 'express';
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import * as R from 'ramda';
import BaseController from 'api/controllers/BaseController'; import BaseController from 'api/controllers/BaseController';
import ContactsService from 'services/Contacts/ContactsService'; import ContactsService from 'services/Contacts/ContactsService';
import DynamicListingService from 'services/DynamicListing/DynamicListService'; import DynamicListingService from 'services/DynamicListing/DynamicListService';
@@ -87,9 +88,6 @@ export default class ContactsController extends BaseController {
limit: 10, limit: 10,
...this.matchedQueryData(req), ...this.matchedQueryData(req),
}; };
if (filter.stringifiedFilterRoles) {
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
}
try { try {
const contacts = await this.contactsService.autocompleteContacts( const contacts = await this.contactsService.autocompleteContacts(
tenantId, tenantId,

View File

@@ -84,13 +84,13 @@ export default class ResourceController extends BaseController {
const { resource_model: resourceModel } = req.params; const { resource_model: resourceModel } = req.params;
try { try {
const resourceFields = this.resourcesService.getResourceFields( // const resourceFields = this.resourcesService.getResourceFields(
tenantId, // tenantId,
resourceModel // resourceModel
); // );
return res.status(200).send({ return res.status(200).send({
resource_fields: this.transfromToResponse(resourceFields), resource_fields: [],
}); });
} catch (error) { } catch (error) {
next(error); next(error);

View File

@@ -1,6 +1,7 @@
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import { difference, upperFirst, omit } from 'lodash'; import { difference, upperFirst, omit } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import * as R from 'ramda';
import { ServiceError } from 'exceptions'; import { ServiceError } from 'exceptions';
import TenancyService from 'services/Tenancy/TenancyService'; import TenancyService from 'services/Tenancy/TenancyService';
import DynamicListingService from 'services/DynamicListing/DynamicListService'; import DynamicListingService from 'services/DynamicListing/DynamicListService';
@@ -205,6 +206,16 @@ export default class ContactsService {
return this.getContactByIdOrThrowError(tenantId, contactId, contactService); 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. * Retrieve auto-complete contacts list.
* @param {number} tenantId - * @param {number} tenantId -
@@ -213,23 +224,26 @@ export default class ContactsService {
*/ */
async autocompleteContacts( async autocompleteContacts(
tenantId: number, tenantId: number,
contactsFilter: IContactsAutoCompleteFilter query: IContactsAutoCompleteFilter
) { ) {
const { Contact } = this.tenancy.models(tenantId); const { Contact } = this.tenancy.models(tenantId);
// Parses auto-complete list filter DTO.
const filter = this.parseAutocompleteListFilterDTO(query);
// Dynamic list. // Dynamic list.
const dynamicList = await this.dynamicListService.dynamicList( // const dynamicList = await this.dynamicListService.dynamicList(
tenantId, // tenantId,
Contact, // Contact,
contactsFilter // filter
); // );
// Retrieve contacts list by the given query. // Retrieve contacts list by the given query.
const contacts = await Contact.query().onBuild((builder) => { const contacts = await Contact.query().onBuild((builder) => {
if (contactsFilter.keyword) { if (filter.keyword) {
builder.where('display_name', 'LIKE', `%${contactsFilter.keyword}%`); builder.where('display_name', 'LIKE', `%${filter.keyword}%`);
} }
dynamicList.buildQuery()(builder); // dynamicList.buildQuery()(builder);
builder.limit(contactsFilter.limit); builder.limit(filter.limit);
}); });
return contacts; return contacts;
} }