@recursyve/nestjs-data-filter 11.0.0 → 11.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/data-filter.repository.d.ts +3 -2
  2. package/lib/data-filter.repository.js +39 -9
  3. package/lib/decorators/index.d.ts +1 -0
  4. package/lib/decorators/index.js +1 -0
  5. package/lib/decorators/searchable-translation-attributes.decorator.d.ts +1 -0
  6. package/lib/decorators/searchable-translation-attributes.decorator.js +21 -0
  7. package/lib/filter/controllers/dynamic-filter.controller.d.ts +8 -8
  8. package/lib/filter/controllers/dynamic-filter.controller.js +27 -25
  9. package/lib/filter/controllers/filter.controller.d.ts +7 -7
  10. package/lib/filter/controllers/filter.controller.js +24 -22
  11. package/lib/filter/controllers/open-api-filter.controller.d.ts +4 -0
  12. package/lib/filter/controllers/open-api-filter.controller.js +123 -0
  13. package/lib/filter/filter.service.d.ts +20 -5
  14. package/lib/filter/filter.service.js +47 -55
  15. package/lib/filter/filters/filter.d.ts +4 -1
  16. package/lib/filter/filters/options.filter.d.ts +3 -2
  17. package/lib/filter/filters/options.filter.js +23 -1
  18. package/lib/filter/filters/select.filter.d.ts +1 -1
  19. package/lib/filter/filters/select.filter.js +22 -1
  20. package/lib/filter/index.d.ts +1 -0
  21. package/lib/filter/index.js +1 -0
  22. package/lib/filter/models/filter-configuration-search.model.d.ts +1 -1
  23. package/lib/filter/models/filter-configuration-search.model.js +35 -0
  24. package/lib/filter/models/filter-configuration.model.d.ts +6 -6
  25. package/lib/filter/models/filter-configuration.model.js +115 -0
  26. package/lib/filter/models/filter-resource-value.model.d.ts +1 -1
  27. package/lib/filter/models/filter-resource-value.model.js +25 -0
  28. package/lib/filter/models/query.model.d.ts +5 -3
  29. package/lib/filter/models/query.model.js +43 -0
  30. package/lib/filter/models/rule.model.d.ts +3 -3
  31. package/lib/filter/models/rule.model.js +28 -0
  32. package/lib/filter/order-rules/enum.order-rule.js +1 -1
  33. package/lib/filter/order-rules/index.d.ts +2 -1
  34. package/lib/filter/order-rules/index.js +2 -1
  35. package/lib/filter/order-rules/json.order-rule.d.ts +11 -0
  36. package/lib/filter/order-rules/json.order-rule.js +15 -0
  37. package/lib/filter/order-rules/order-rule.d.ts +7 -2
  38. package/lib/models/attributes.model.d.ts +4 -1
  39. package/lib/models/attributes.model.js +8 -1
  40. package/lib/models/data-filter.model.d.ts +5 -1
  41. package/lib/models/data-filter.model.js +25 -6
  42. package/lib/models/filter.model.d.ts +15 -6
  43. package/lib/models/filter.model.js +148 -0
  44. package/lib/models/include.model.d.ts +2 -0
  45. package/lib/models/search-attributes.model.d.ts +1 -0
  46. package/lib/scanners/sequelize-model.scanner.d.ts +1 -1
  47. package/lib/scanners/sequelize-model.scanner.js +20 -13
  48. package/package.json +2 -1
@@ -27,13 +27,14 @@ export declare class DataFilterRepository<Data> {
27
27
  findAll(options?: FindOptions, conditions?: object): Promise<Data[]>;
28
28
  findAllFromUser(user: DataFilterUserModel, options?: FindOptions, conditions?: object): Promise<Data[]>;
29
29
  count(where?: WhereOptions, conditions?: object): Promise<number>;
30
- search(search: string, options?: FindOptions, conditions?: object): Promise<Data[]>;
30
+ search(search: string, language?: string | null, options?: FindOptions, conditions?: object): Promise<Data[]>;
31
31
  searchFromUser(user: DataFilterUserModel, search: string, options?: FindOptions, conditions?: object): Promise<Data[]>;
32
32
  generateFindOptions(options?: FindOptions, conditions?: object): FindOptions;
33
33
  generateOrderInclude(order: OrderModel, conditions?: object): IncludeOptions[];
34
34
  generateSearchInclude(conditions?: object): Includeable[];
35
35
  reduceObject(result: any): Data;
36
36
  getSearchAttributes(): SearchAttributesModel[];
37
+ getSearchTranslationAttributes(): SearchAttributesModel[];
37
38
  hasCustomAttribute(name: string): boolean;
38
39
  getCustomAttribute(name: string): CustomAttributesConfig | null;
39
40
  getCustomAttributeGroupBy(): (string | Fn | Col)[];
@@ -45,7 +46,7 @@ export declare class DataFilterRepository<Data> {
45
46
  downloadPdf(headers: string[], data: any[], lang: string, options?: any): Promise<Buffer>;
46
47
  downloadZip(headers: string[], data: any[], lang: string, options?: any): Promise<Buffer>;
47
48
  private init;
48
- addSearchCondition(search: string, options: FindOptions): void;
49
+ addSearchCondition(search: string, options: FindOptions, language?: string | null): void;
49
50
  private getExportsHeader;
50
51
  private getExportData;
51
52
  private getExportValue;
@@ -92,9 +92,9 @@ let DataFilterRepository = class DataFilterRepository {
92
92
  const options = this.generateFindOptions({ where }, conditions);
93
93
  return this.model.count(options);
94
94
  }
95
- async search(search, options, conditions) {
95
+ async search(search, language = null, options, conditions) {
96
96
  const findOptions = this.generateFindOptions(options, conditions);
97
- this.addSearchCondition(search, findOptions);
97
+ this.addSearchCondition(search, findOptions, language);
98
98
  const result = await this.model.findAll(findOptions);
99
99
  if (!(result === null || result === void 0 ? void 0 : result.length)) {
100
100
  return result;
@@ -103,7 +103,7 @@ let DataFilterRepository = class DataFilterRepository {
103
103
  }
104
104
  async searchFromUser(user, search, options, conditions) {
105
105
  const findOptions = this.generateFindOptions(options, conditions);
106
- this.addSearchCondition(search, findOptions);
106
+ this.addSearchCondition(search, findOptions, user.language);
107
107
  findOptions.where = await this.mergeAccessControlCondition(findOptions.where, user);
108
108
  const result = await this.model.findAll(findOptions);
109
109
  if (!(result === null || result === void 0 ? void 0 : result.length)) {
@@ -209,7 +209,7 @@ let DataFilterRepository = class DataFilterRepository {
209
209
  return data;
210
210
  }
211
211
  getSearchAttributes() {
212
- var _a;
212
+ var _a, _b, _c;
213
213
  const attributes = [];
214
214
  const modelAttr = this._config.getSearchableAttributes();
215
215
  attributes.push(...modelAttr.map(a => ({
@@ -221,12 +221,34 @@ let DataFilterRepository = class DataFilterRepository {
221
221
  if (!definition.path) {
222
222
  continue;
223
223
  }
224
- const attr = definition.ignoreInSearch ? [] : (_a = definition.searchableAttributes) !== null && _a !== void 0 ? _a : definition.attributes;
224
+ const attr = (definition.ignoreInSearch || ((_a = definition.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.length) && !((_b = definition.searchableAttributes) === null || _b === void 0 ? void 0 : _b.length)) ? [] : (_c = definition.searchableAttributes) !== null && _c !== void 0 ? _c : definition.attributes;
225
225
  const additionalIncludes = definition.transformIncludesConfig({});
226
226
  attributes.push(...this.sequelizeModelScanner.getAttributes(this.model, definition.path, additionalIncludes, attr));
227
227
  }
228
228
  return attributes;
229
229
  }
230
+ getSearchTranslationAttributes() {
231
+ var _a;
232
+ if (!this._config.getSearchableTranslationAttributes().length) {
233
+ return [];
234
+ }
235
+ const attributes = [];
236
+ const modelAttr = this._config.getSearchableTranslationAttributes();
237
+ attributes.push(...modelAttr.map(attribute => ({
238
+ name: attribute,
239
+ key: attribute,
240
+ isJson: sequelize_utils_1.SequelizeUtils.isColumnJson(this.model, attribute),
241
+ isTranslationAttribute: true
242
+ })));
243
+ for (const definition of this._definitions) {
244
+ if (!definition.path || definition.ignoreInSearch || !((_a = definition.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.length)) {
245
+ continue;
246
+ }
247
+ const additionalIncludes = definition.transformIncludesConfig({});
248
+ attributes.push(...this.sequelizeModelScanner.getAttributes(this.model, definition.path, additionalIncludes, definition.searchableTranslationAttributes, true));
249
+ }
250
+ return attributes;
251
+ }
230
252
  hasCustomAttribute(name) {
231
253
  return !!this._config.customAttributes.find((x) => { var _a; return ((_a = x.config) === null || _a === void 0 ? void 0 : _a.name) === name; });
232
254
  }
@@ -305,7 +327,7 @@ let DataFilterRepository = class DataFilterRepository {
305
327
  this._config = this.dataFilterScanner.getDataFilter(this.dataDef);
306
328
  this._definitions = this.dataFilterScanner.getAttributes(this.dataDef);
307
329
  }
308
- addSearchCondition(search, options) {
330
+ addSearchCondition(search, options, language = null) {
309
331
  if (!search) {
310
332
  return;
311
333
  }
@@ -318,10 +340,13 @@ let DataFilterRepository = class DataFilterRepository {
318
340
  options.where = { [sequelize_1.Op.and]: [options.where] };
319
341
  }
320
342
  const where = options.where;
321
- const generateFieldsObject = (searchValue) => this.getSearchAttributes()
343
+ const generateFieldsObject = (searchValue) => [
344
+ ...this.getSearchAttributes(),
345
+ ...this.getSearchTranslationAttributes()
346
+ ]
322
347
  .map(a => {
323
- var _a, _b;
324
- if (a.isJson) {
348
+ var _a, _b, _c, _d;
349
+ if (a.isJson && !a.isTranslationAttribute) {
325
350
  const field = (_a = a.literalKey) !== null && _a !== void 0 ? _a : `\`${this.model.name}\`.\`${a.key}\``;
326
351
  /**
327
352
  * literal function is not working of some reason...
@@ -330,6 +355,11 @@ let DataFilterRepository = class DataFilterRepository {
330
355
  const value = (_b = this.model.sequelize) === null || _b === void 0 ? void 0 : _b.escape(`%${searchValue.toUpperCase()}%`);
331
356
  return new sequelize_1.Utils.Literal(`UPPER(JSON_EXTRACT(${field}, '$')) LIKE ${value}`);
332
357
  }
358
+ if (a.isJson && a.isTranslationAttribute) {
359
+ const field = (_c = a.literalKey) !== null && _c !== void 0 ? _c : `\`${this.model.name}\`.\`${a.name}\``;
360
+ const value = (_d = this.model.sequelize) === null || _d === void 0 ? void 0 : _d.escape(`%${searchValue.toUpperCase()}%`);
361
+ return new sequelize_1.Utils.Literal(`UPPER(JSON_UNQUOTE(JSON_EXTRACT(${field}, '$.${language}'))) LIKE ${value}`);
362
+ }
333
363
  return {
334
364
  [a.key]: {
335
365
  [sequelize_1.Op.like]: `%${searchValue}%`
@@ -11,6 +11,7 @@ export * from "./paranoid.decorator";
11
11
  export * from "./path.decorator";
12
12
  export * from "./required.decorator";
13
13
  export * from "./seachable-attributes.decorator";
14
+ export * from "./searchable-translation-attributes.decorator";
14
15
  export * from "./separate.decorator";
15
16
  export * from "./sum.decorator";
16
17
  export * from "./where.decorator";
@@ -27,6 +27,7 @@ __exportStar(require("./paranoid.decorator"), exports);
27
27
  __exportStar(require("./path.decorator"), exports);
28
28
  __exportStar(require("./required.decorator"), exports);
29
29
  __exportStar(require("./seachable-attributes.decorator"), exports);
30
+ __exportStar(require("./searchable-translation-attributes.decorator"), exports);
30
31
  __exportStar(require("./separate.decorator"), exports);
31
32
  __exportStar(require("./sum.decorator"), exports);
32
33
  __exportStar(require("./where.decorator"), exports);
@@ -0,0 +1 @@
1
+ export declare function SearchableTranslationAttributes(attributes: string[]): PropertyDecorator & ClassDecorator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchableTranslationAttributes = SearchableTranslationAttributes;
4
+ const attributes_handler_1 = require("../handlers/attributes.handler");
5
+ const data_filter_handler_1 = require("../handlers/data-filter.handler");
6
+ function SearchableTranslationAttributes(attributes) {
7
+ return (target, propertyKey) => {
8
+ defineSearchableTranslationAttributesMetadata(target, propertyKey, attributes);
9
+ };
10
+ }
11
+ function defineSearchableTranslationAttributesMetadata(target, propertyKey, attributes) {
12
+ if (!propertyKey) {
13
+ const dataFilter = data_filter_handler_1.DataFilterHandler.getDataFilter(target);
14
+ dataFilter.setSearchableTranslationAttributes(attributes);
15
+ data_filter_handler_1.DataFilterHandler.saveDataFilter(target, dataFilter);
16
+ return;
17
+ }
18
+ const attribute = attributes_handler_1.AttributesHandler.getAttribute(target, propertyKey);
19
+ attribute.setSearchableTranslationAttributes(attributes);
20
+ attributes_handler_1.AttributesHandler.saveAttribute(target, attribute);
21
+ }
@@ -9,12 +9,12 @@ export declare abstract class DynamicFilterController<Data> {
9
9
  private readonly userUserDeserializer;
10
10
  private readonly option;
11
11
  protected constructor(filterService: FilterService<Data>);
12
- filter(query: FilterQueryModel, req: any): Promise<FilterResultModel<Data>>;
13
- filterCount(query: FilterQueryModel, req: any): Promise<number>;
14
- downloadData(query: FilterQueryModel, type: ExportTypes, req: any): Promise<Buffer | string>;
15
- getFilterConfig(req: any): Promise<FilterConfigurationModel[]>;
16
- searchFilterResourceValue(search: FilterResourceValueModel, req: any): Promise<SelectFilterValue | null>;
17
- searchFilterConfigValues(search: FilterConfigurationSearchModel, req: any): Promise<SelectFilterValue[]>;
18
- protected getUser(req: any): Promise<DataFilterUserModel | null>;
19
- protected abstract transformQuery(query: FilterQueryModel, req: any): FilterQueryModel;
12
+ filter(query: FilterQueryModel, request: any): Promise<FilterResultModel<Data>>;
13
+ filterCount(query: FilterQueryModel, request: any): Promise<number>;
14
+ downloadData(query: FilterQueryModel, type: ExportTypes, request: any): Promise<Buffer | string>;
15
+ getFilterConfig(request: any): Promise<FilterConfigurationModel[]>;
16
+ searchFilterResourceValue(search: FilterResourceValueModel, request: any): Promise<SelectFilterValue | null>;
17
+ searchFilterConfigValues(search: FilterConfigurationSearchModel, request: any): Promise<SelectFilterValue[]>;
18
+ protected getUser(request: any): Promise<DataFilterUserModel | null>;
19
+ protected abstract transformQuery(query: FilterQueryModel, request: any): FilterQueryModel;
20
20
  }
@@ -19,42 +19,44 @@ const constant_1 = require("../../constant");
19
19
  const deserializers_1 = require("../../deserializers");
20
20
  const filter_query_guard_1 = require("../guards/filter-query.guard");
21
21
  const data_file_download_interceptor_1 = require("../interceptors/data-file-download.interceptor");
22
+ const filter_configuration_search_model_1 = require("../models/filter-configuration-search.model");
23
+ const filter_resource_value_model_1 = require("../models/filter-resource-value.model");
22
24
  class DynamicFilterController {
23
25
  constructor(filterService) {
24
26
  this.filterService = filterService;
25
27
  }
26
- async filter(query, req) {
27
- query = this.transformQuery(query, req);
28
- const user = await this.getUser(req);
29
- return user ? this.filterService.filter(user, query) : this.filterService.filter(query);
28
+ async filter(query, request) {
29
+ query = this.transformQuery(query, request);
30
+ const user = await this.getUser(request);
31
+ return this.filterService.filter({ options: query, request, user });
30
32
  }
31
- async filterCount(query, req) {
32
- query = this.transformQuery(query, req);
33
- const user = await this.getUser(req);
34
- return user ? this.filterService.count(user, query) : this.filterService.count(query);
33
+ async filterCount(query, request) {
34
+ query = this.transformQuery(query, request);
35
+ const user = await this.getUser(request);
36
+ return this.filterService.count({ options: query, user });
35
37
  }
36
- async downloadData(query, type, req) {
37
- query = this.transformQuery(query, req);
38
- const user = await this.getUser(req);
39
- return await this.filterService.downloadData(user, type, query);
38
+ async downloadData(query, type, request) {
39
+ query = this.transformQuery(query, request);
40
+ const user = await this.getUser(request);
41
+ return await this.filterService.downloadData({ options: query, request, type, user });
40
42
  }
41
- async getFilterConfig(req) {
43
+ async getFilterConfig(request) {
42
44
  var _a;
43
- return await this.filterService.getConfig(req, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
45
+ return await this.filterService.getConfig(request, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
44
46
  }
45
- async searchFilterResourceValue(search, req) {
47
+ async searchFilterResourceValue(search, request) {
46
48
  var _a;
47
- return await this.filterService.findResourceValueById(req, search, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
49
+ return await this.filterService.findResourceValueById(request, search, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
48
50
  }
49
- async searchFilterConfigValues(search, req) {
51
+ async searchFilterConfigValues(search, request) {
50
52
  var _a;
51
- return await this.filterService.searchConfigValues(req, search, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
53
+ return await this.filterService.searchConfigValues(request, search, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
52
54
  }
53
- async getUser(req) {
55
+ async getUser(request) {
54
56
  if (!this.userUserDeserializer || this.option.disableAccessControl) {
55
57
  return null;
56
58
  }
57
- return this.userUserDeserializer.deserializeUser(req);
59
+ return this.userUserDeserializer.deserializeUser(request);
58
60
  }
59
61
  }
60
62
  exports.DynamicFilterController = DynamicFilterController;
@@ -74,7 +76,7 @@ __decorate([
74
76
  __param(0, (0, common_1.Body)()),
75
77
  __param(1, (0, common_1.Req)()),
76
78
  __metadata("design:type", Function),
77
- __metadata("design:paramtypes", [Object, Object]),
79
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
78
80
  __metadata("design:returntype", Promise)
79
81
  ], DynamicFilterController.prototype, "filter", null);
80
82
  __decorate([
@@ -83,7 +85,7 @@ __decorate([
83
85
  __param(0, (0, common_1.Body)()),
84
86
  __param(1, (0, common_1.Req)()),
85
87
  __metadata("design:type", Function),
86
- __metadata("design:paramtypes", [Object, Object]),
88
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
87
89
  __metadata("design:returntype", Promise)
88
90
  ], DynamicFilterController.prototype, "filterCount", null);
89
91
  __decorate([
@@ -94,7 +96,7 @@ __decorate([
94
96
  __param(1, (0, common_1.Param)("type")),
95
97
  __param(2, (0, common_1.Req)()),
96
98
  __metadata("design:type", Function),
97
- __metadata("design:paramtypes", [Object, String, Object]),
99
+ __metadata("design:paramtypes", [__1.FilterQueryModel, String, Object]),
98
100
  __metadata("design:returntype", Promise)
99
101
  ], DynamicFilterController.prototype, "downloadData", null);
100
102
  __decorate([
@@ -109,7 +111,7 @@ __decorate([
109
111
  __param(0, (0, common_1.Query)()),
110
112
  __param(1, (0, common_1.Req)()),
111
113
  __metadata("design:type", Function),
112
- __metadata("design:paramtypes", [Object, Object]),
114
+ __metadata("design:paramtypes", [filter_resource_value_model_1.FilterResourceValueModel, Object]),
113
115
  __metadata("design:returntype", Promise)
114
116
  ], DynamicFilterController.prototype, "searchFilterResourceValue", null);
115
117
  __decorate([
@@ -117,6 +119,6 @@ __decorate([
117
119
  __param(0, (0, common_1.Query)()),
118
120
  __param(1, (0, common_1.Req)()),
119
121
  __metadata("design:type", Function),
120
- __metadata("design:paramtypes", [Object, Object]),
122
+ __metadata("design:paramtypes", [filter_configuration_search_model_1.FilterConfigurationSearchModel, Object]),
121
123
  __metadata("design:returntype", Promise)
122
124
  ], DynamicFilterController.prototype, "searchFilterConfigValues", null);
@@ -9,11 +9,11 @@ export declare class FilterController<Data> {
9
9
  private readonly userUserDeserializer;
10
10
  private readonly option;
11
11
  constructor(filterService: FilterService<Data>);
12
- filter(query: FilterQueryModel, req: any): Promise<FilterResultModel<Data>>;
13
- filterCount(query: FilterQueryModel, req: any): Promise<number>;
14
- downloadData(query: FilterQueryModel, type: ExportTypes, req: any): Promise<Buffer | string>;
15
- getFilterConfig(req: any): Promise<FilterConfigurationModel[]>;
16
- searchFilterResourceValue(search: FilterResourceValueModel, req: any): Promise<SelectFilterValue | null>;
17
- searchFilterConfigValues(search: FilterConfigurationSearchModel, req: any): Promise<SelectFilterValue[]>;
18
- protected getUser(req: any): Promise<DataFilterUserModel | null>;
12
+ filter(query: FilterQueryModel, request: any): Promise<FilterResultModel<Data>>;
13
+ filterCount(query: FilterQueryModel, request: any): Promise<number>;
14
+ downloadData(query: FilterQueryModel, type: ExportTypes, request: any): Promise<Buffer | string>;
15
+ getFilterConfig(request: any): Promise<FilterConfigurationModel[]>;
16
+ searchFilterResourceValue(search: FilterResourceValueModel, request: any): Promise<SelectFilterValue | null>;
17
+ searchFilterConfigValues(search: FilterConfigurationSearchModel, request: any): Promise<SelectFilterValue[]>;
18
+ protected getUser(request: any): Promise<DataFilterUserModel | null>;
19
19
  }
@@ -19,39 +19,41 @@ const constant_1 = require("../../constant");
19
19
  const deserializers_1 = require("../../deserializers");
20
20
  const filter_query_guard_1 = require("../guards/filter-query.guard");
21
21
  const data_file_download_interceptor_1 = require("../interceptors/data-file-download.interceptor");
22
+ const filter_configuration_search_model_1 = require("../models/filter-configuration-search.model");
23
+ const filter_resource_value_model_1 = require("../models/filter-resource-value.model");
22
24
  class FilterController {
23
25
  constructor(filterService) {
24
26
  this.filterService = filterService;
25
27
  }
26
- async filter(query, req) {
27
- const user = await this.getUser(req);
28
- return user ? this.filterService.filter(user, query) : this.filterService.filter(query);
28
+ async filter(query, request) {
29
+ const user = await this.getUser(request);
30
+ return this.filterService.filter({ options: query, request, user });
29
31
  }
30
- async filterCount(query, req) {
31
- const user = await this.getUser(req);
32
- return user ? this.filterService.count(user, query) : this.filterService.count(query);
32
+ async filterCount(query, request) {
33
+ const user = await this.getUser(request);
34
+ return this.filterService.count({ options: query, user });
33
35
  }
34
- async downloadData(query, type, req) {
35
- const user = await this.getUser(req);
36
- return await this.filterService.downloadData(user, type, query);
36
+ async downloadData(query, type, request) {
37
+ const user = await this.getUser(request);
38
+ return await this.filterService.downloadData({ options: query, request, type, user });
37
39
  }
38
- async getFilterConfig(req) {
40
+ async getFilterConfig(request) {
39
41
  var _a;
40
- return await this.filterService.getConfig(req, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
42
+ return await this.filterService.getConfig(request, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
41
43
  }
42
- async searchFilterResourceValue(search, req) {
44
+ async searchFilterResourceValue(search, request) {
43
45
  var _a;
44
- return await this.filterService.findResourceValueById(req, search, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
46
+ return await this.filterService.findResourceValueById(request, search, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
45
47
  }
46
- async searchFilterConfigValues(search, req) {
48
+ async searchFilterConfigValues(search, request) {
47
49
  var _a;
48
- return await this.filterService.searchConfigValues(req, search, (_a = await this.getUser(req)) !== null && _a !== void 0 ? _a : {});
50
+ return await this.filterService.searchConfigValues(request, search, (_a = await this.getUser(request)) !== null && _a !== void 0 ? _a : {});
49
51
  }
50
- async getUser(req) {
52
+ async getUser(request) {
51
53
  if (!this.userUserDeserializer || this.option.disableAccessControl) {
52
54
  return null;
53
55
  }
54
- return this.userUserDeserializer.deserializeUser(req);
56
+ return this.userUserDeserializer.deserializeUser(request);
55
57
  }
56
58
  }
57
59
  exports.FilterController = FilterController;
@@ -71,7 +73,7 @@ __decorate([
71
73
  __param(0, (0, common_1.Body)()),
72
74
  __param(1, (0, common_1.Req)()),
73
75
  __metadata("design:type", Function),
74
- __metadata("design:paramtypes", [Object, Object]),
76
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
75
77
  __metadata("design:returntype", Promise)
76
78
  ], FilterController.prototype, "filter", null);
77
79
  __decorate([
@@ -80,7 +82,7 @@ __decorate([
80
82
  __param(0, (0, common_1.Body)()),
81
83
  __param(1, (0, common_1.Req)()),
82
84
  __metadata("design:type", Function),
83
- __metadata("design:paramtypes", [Object, Object]),
85
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
84
86
  __metadata("design:returntype", Promise)
85
87
  ], FilterController.prototype, "filterCount", null);
86
88
  __decorate([
@@ -91,7 +93,7 @@ __decorate([
91
93
  __param(1, (0, common_1.Param)("type")),
92
94
  __param(2, (0, common_1.Req)()),
93
95
  __metadata("design:type", Function),
94
- __metadata("design:paramtypes", [Object, String, Object]),
96
+ __metadata("design:paramtypes", [__1.FilterQueryModel, String, Object]),
95
97
  __metadata("design:returntype", Promise)
96
98
  ], FilterController.prototype, "downloadData", null);
97
99
  __decorate([
@@ -106,7 +108,7 @@ __decorate([
106
108
  __param(0, (0, common_1.Query)()),
107
109
  __param(1, (0, common_1.Req)()),
108
110
  __metadata("design:type", Function),
109
- __metadata("design:paramtypes", [Object, Object]),
111
+ __metadata("design:paramtypes", [filter_resource_value_model_1.FilterResourceValueModel, Object]),
110
112
  __metadata("design:returntype", Promise)
111
113
  ], FilterController.prototype, "searchFilterResourceValue", null);
112
114
  __decorate([
@@ -114,6 +116,6 @@ __decorate([
114
116
  __param(0, (0, common_1.Query)()),
115
117
  __param(1, (0, common_1.Req)()),
116
118
  __metadata("design:type", Function),
117
- __metadata("design:paramtypes", [Object, Object]),
119
+ __metadata("design:paramtypes", [filter_configuration_search_model_1.FilterConfigurationSearchModel, Object]),
118
120
  __metadata("design:returntype", Promise)
119
121
  ], FilterController.prototype, "searchFilterConfigValues", null);
@@ -0,0 +1,4 @@
1
+ import { Type } from "@nestjs/common";
2
+ import { FilterController } from "../..";
3
+ import { FilterService } from "../filter.service";
4
+ export declare function OpenApiFilterController<T extends Type, D>(Base: T): Type<FilterController<D>> & (new (filterService: FilterService<D>) => FilterController<D>);
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OpenApiFilterController = OpenApiFilterController;
16
+ const common_1 = require("@nestjs/common");
17
+ const __1 = require("../..");
18
+ const filter_query_guard_1 = require("../guards/filter-query.guard");
19
+ const data_file_download_interceptor_1 = require("../interceptors/data-file-download.interceptor");
20
+ const swagger_1 = require("@nestjs/swagger");
21
+ const filter_resource_value_model_1 = require("../models/filter-resource-value.model");
22
+ function OpenApiFilterController(Base) {
23
+ const _FilterResultModel = (0, __1.FilterResultModelMixin)(Base);
24
+ class _FilterController extends __1.FilterController {
25
+ async filter(query, req) {
26
+ return super.filter(query, req);
27
+ }
28
+ async filterCount(query, req) {
29
+ return super.filterCount(query, req);
30
+ }
31
+ async downloadData(query, type, req) {
32
+ return super.downloadData(query, type, req);
33
+ }
34
+ async getFilterConfig(req) {
35
+ return super.getFilterConfig(req);
36
+ }
37
+ async searchFilterResourceValue(search, req) {
38
+ return super.searchFilterResourceValue(search, req);
39
+ }
40
+ async searchFilterConfigValues(search, req) {
41
+ return super.searchFilterConfigValues(search, req);
42
+ }
43
+ }
44
+ __decorate([
45
+ (0, common_1.Post)("filter"),
46
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
47
+ (0, common_1.UseGuards)(filter_query_guard_1.FilterQueryGuard),
48
+ (0, swagger_1.ApiOkResponse)({ type: () => _FilterResultModel }),
49
+ (0, swagger_1.ApiOperation)({ operationId: `filter${Base.name}` }),
50
+ __param(0, (0, common_1.Body)()),
51
+ __param(1, (0, common_1.Req)()),
52
+ __metadata("design:type", Function),
53
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
54
+ __metadata("design:returntype", Promise)
55
+ ], _FilterController.prototype, "filter", null);
56
+ __decorate([
57
+ (0, common_1.Post)("filter-count"),
58
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
59
+ (0, swagger_1.ApiOkResponse)({ schema: { type: "number" } }),
60
+ (0, swagger_1.ApiOperation)({ operationId: `filter${Base.name}Count` }),
61
+ __param(0, (0, common_1.Body)()),
62
+ __param(1, (0, common_1.Req)()),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [__1.FilterQueryModel, Object]),
65
+ __metadata("design:returntype", Promise)
66
+ ], _FilterController.prototype, "filterCount", null);
67
+ __decorate([
68
+ (0, common_1.Post)("download/:type"),
69
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
70
+ (0, common_1.UseInterceptors)(data_file_download_interceptor_1.DataFileDownloadInterceptor),
71
+ (0, swagger_1.ApiOkResponse)({
72
+ description: 'Returns file data as binary (Buffer) or as text (string) depending on the export type.',
73
+ content: {
74
+ 'application/octet-stream': {
75
+ schema: {
76
+ oneOf: [
77
+ { type: 'string', format: 'binary' },
78
+ { type: 'string' }
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ }),
84
+ (0, swagger_1.ApiParam)({ name: "type", enum: __1.ExportTypes, enumName: "ExportTypes" }),
85
+ (0, swagger_1.ApiOperation)({ operationId: `download${Base.name}Data` }),
86
+ __param(0, (0, common_1.Body)()),
87
+ __param(1, (0, common_1.Param)("type")),
88
+ __param(2, (0, common_1.Req)()),
89
+ __metadata("design:type", Function),
90
+ __metadata("design:paramtypes", [__1.FilterQueryModel, String, Object]),
91
+ __metadata("design:returntype", Promise)
92
+ ], _FilterController.prototype, "downloadData", null);
93
+ __decorate([
94
+ (0, common_1.Post)("filter/config"),
95
+ (0, swagger_1.ApiOkResponse)({ type: () => __1.FilterConfigurationModel, isArray: true }),
96
+ (0, swagger_1.ApiOperation)({ operationId: `get${Base.name}FilterConfig` }),
97
+ __param(0, (0, common_1.Req)()),
98
+ __metadata("design:type", Function),
99
+ __metadata("design:paramtypes", [Object]),
100
+ __metadata("design:returntype", Promise)
101
+ ], _FilterController.prototype, "getFilterConfig", null);
102
+ __decorate([
103
+ (0, common_1.Post)("filter/config/id"),
104
+ (0, swagger_1.ApiOkResponse)({ type: () => __1.SelectFilterValue }),
105
+ (0, swagger_1.ApiOperation)({ operationId: `search${Base.name}FilterResourceValue` }),
106
+ __param(0, (0, common_1.Query)()),
107
+ __param(1, (0, common_1.Req)()),
108
+ __metadata("design:type", Function),
109
+ __metadata("design:paramtypes", [filter_resource_value_model_1.FilterResourceValueModel, Object]),
110
+ __metadata("design:returntype", Promise)
111
+ ], _FilterController.prototype, "searchFilterResourceValue", null);
112
+ __decorate([
113
+ (0, common_1.Post)("filter/config/value"),
114
+ (0, swagger_1.ApiOkResponse)({ type: () => __1.SelectFilterValue, isArray: true }),
115
+ (0, swagger_1.ApiOperation)({ operationId: `search${Base.name}FilterConfigValues` }),
116
+ __param(0, (0, common_1.Query)()),
117
+ __param(1, (0, common_1.Req)()),
118
+ __metadata("design:type", Function),
119
+ __metadata("design:paramtypes", [__1.FilterConfigurationSearchModel, Object]),
120
+ __metadata("design:returntype", Promise)
121
+ ], _FilterController.prototype, "searchFilterConfigValues", null);
122
+ return _FilterController;
123
+ }
@@ -13,6 +13,22 @@ import { QueryModel } from "./models";
13
13
  import { FilterConfigurationSearchModel } from "./models/filter-configuration-search.model";
14
14
  import { FilterConfigurationModel } from "./models/filter-configuration.model";
15
15
  import { FilterResourceValueModel } from "./models/filter-resource-value.model";
16
+ interface CountParams<Users extends DataFilterUserModel> {
17
+ options: FilterQueryModel;
18
+ user?: Users | null;
19
+ }
20
+ interface DownloadDataParams<Users extends DataFilterUserModel, Request> {
21
+ exportOptions?: object;
22
+ options: FilterQueryModel;
23
+ request: Request;
24
+ type: ExportTypes;
25
+ user: Users | null;
26
+ }
27
+ interface FilterParams<Users extends DataFilterUserModel, Request> {
28
+ options: FilterQueryModel;
29
+ request: Request;
30
+ user?: Users | null;
31
+ }
16
32
  export declare class FilterService<Data> {
17
33
  private accessControlAdapter;
18
34
  private translateAdapter;
@@ -31,11 +47,9 @@ export declare class FilterService<Data> {
31
47
  searchConfigValues(request: any, search: FilterConfigurationSearchModel, user?: DataFilterUserModel): Promise<SelectFilterValue[]>;
32
48
  private convertNumber;
33
49
  findResourceValueById(request: any, search: FilterResourceValueModel, user?: DataFilterUserModel): Promise<SelectFilterValue | null>;
34
- count(user: DataFilterUserModel, options: FilterQueryModel): Promise<number>;
35
- count(options: FilterQueryModel): Promise<number>;
36
- filter(user: DataFilterUserModel, options: FilterQueryModel): Promise<FilterResultModel<Data>>;
37
- filter(options: FilterQueryModel): Promise<FilterResultModel<Data>>;
38
- downloadData(user: DataFilterUserModel | null, type: ExportTypes, options: FilterQueryModel, exportOptions?: object): Promise<Buffer | string>;
50
+ count<Users extends DataFilterUserModel>(params: CountParams<Users>): Promise<number>;
51
+ filter<Request, Users extends DataFilterUserModel>(params: FilterParams<DataFilterUserModel, Request>): Promise<FilterResultModel<Data>>;
52
+ downloadData<Request>(params: DownloadDataParams<DataFilterUserModel, Request>): Promise<Buffer | string>;
39
53
  getFindOptions(model: typeof M, query: QueryModel | undefined, data?: object): Promise<FindOptions>;
40
54
  private init;
41
55
  private getInclude;
@@ -56,3 +70,4 @@ export declare class FilterService<Data> {
56
70
  private normalizeOrder;
57
71
  private getNonNestedOrderColumns;
58
72
  }
73
+ export {};