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

View File

@@ -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);

View File

@@ -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;
}