@recursyve/nestjs-data-filter 11.1.2 → 11.2.0

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.
@@ -229,9 +229,6 @@ let DataFilterRepository = class DataFilterRepository {
229
229
  }
230
230
  getSearchTranslationAttributes() {
231
231
  var _a;
232
- if (!this._config.getSearchableTranslationAttributes().length) {
233
- return [];
234
- }
235
232
  const attributes = [];
236
233
  const modelAttr = this._config.getSearchableTranslationAttributes();
237
234
  attributes.push(...modelAttr.map(attribute => ({
@@ -0,0 +1,4 @@
1
+ import { Type } from "@nestjs/common";
2
+ import { DynamicFilterController } from "../..";
3
+ import { FilterService } from "../filter.service";
4
+ export declare function OpenApiDynamicFilterController<T extends Type, D>(Base: T): Type<DynamicFilterController<D>> & (abstract new (filterService: FilterService<D>) => DynamicFilterController<D>);
@@ -0,0 +1,124 @@
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.OpenApiDynamicFilterController = OpenApiDynamicFilterController;
16
+ const common_1 = require("@nestjs/common");
17
+ const swagger_1 = require("@nestjs/swagger");
18
+ const __1 = require("../..");
19
+ const filter_query_guard_1 = require("../guards/filter-query.guard");
20
+ const data_file_download_interceptor_1 = require("../interceptors/data-file-download.interceptor");
21
+ const filter_resource_value_model_1 = require("../models/filter-resource-value.model");
22
+ function OpenApiDynamicFilterController(Base) {
23
+ const _FilterResultModel = (0, __1.FilterResultModelMixin)(Base);
24
+ class _FilterController extends __1.DynamicFilterController {
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
+ // @ts-ignore
123
+ return _FilterController;
124
+ }
@@ -5,6 +5,7 @@ export * from "./filter.service";
5
5
  export * from "./base-filter";
6
6
  export * from "./controllers/dynamic-filter.controller";
7
7
  export * from "./controllers/filter.controller";
8
+ export * from "./controllers/open-api-dynamic-filter.controller";
8
9
  export * from "./controllers/open-api-filter.controller";
9
10
  export * from "./decorators/inject-filter.decorator";
10
11
  export * from "./filter.utils";
@@ -21,6 +21,7 @@ __exportStar(require("./filter.service"), exports);
21
21
  __exportStar(require("./base-filter"), exports);
22
22
  __exportStar(require("./controllers/dynamic-filter.controller"), exports);
23
23
  __exportStar(require("./controllers/filter.controller"), exports);
24
+ __exportStar(require("./controllers/open-api-dynamic-filter.controller"), exports);
24
25
  __exportStar(require("./controllers/open-api-filter.controller"), exports);
25
26
  __exportStar(require("./decorators/inject-filter.decorator"), exports);
26
27
  __exportStar(require("./filter.utils"), exports);
@@ -1,6 +1,6 @@
1
1
  import { FilterOperatorTypes } from "../operators";
2
2
  export declare class RuleModel {
3
- operation: FilterOperatorTypes;
3
+ operation: FilterOperatorTypes | string;
4
4
  value: unknown | unknown[];
5
5
  }
6
6
  export interface IRule {
@@ -8,4 +8,5 @@ export declare class JsonOrderRule extends OrderRule implements JsonRuleDefiniti
8
8
  json: JsonConfig;
9
9
  constructor(definition: BaseOrderRuleDefinition & JsonRuleDefinition);
10
10
  getOrderOption(model: typeof M, context: OrderRuleContext): OrderItemColumn;
11
+ private getModelPath;
11
12
  }
@@ -2,14 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonOrderRule = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const sequelize_utils_1 = require("../../sequelize.utils");
5
6
  const order_rule_1 = require("./order-rule");
6
7
  class JsonOrderRule extends order_rule_1.OrderRule {
7
8
  constructor(definition) {
8
9
  super(definition);
9
10
  }
10
11
  getOrderOption(model, context) {
11
- const path = typeof this.json.path === "function" ? this.json.path(context) : this.json.path;
12
- return (0, sequelize_1.literal)(`UPPER(JSON_UNQUOTE(JSON_EXTRACT(${`\`${model.name}\`.\`${this.attribute}\``}, '$.${path}')))`);
12
+ const jsonPath = typeof this.json.path === "function" ? this.json.path(context) : this.json.path;
13
+ const modelPath = this.getModelPath(model);
14
+ return (0, sequelize_1.literal)(`UPPER(JSON_UNQUOTE(JSON_EXTRACT(${modelPath}, '$.${jsonPath}')))`);
15
+ }
16
+ getModelPath(model) {
17
+ if (this.path) {
18
+ return sequelize_utils_1.SequelizeUtils.getLiteralFullName(this.attribute, this.path);
19
+ }
20
+ return `\`${model.name}\`.\`${this.attribute}\``;
13
21
  }
14
22
  }
15
23
  exports.JsonOrderRule = JsonOrderRule;
@@ -268,14 +268,15 @@ class SequelizeUtils {
268
268
  return model;
269
269
  }
270
270
  static findColumnFieldName(model, name) {
271
- var _a;
271
+ var _a, _b;
272
272
  const field = Object.keys(model.rawAttributes).find((key) => {
273
+ var _a;
273
274
  if (key === name) {
274
275
  return true;
275
276
  }
276
- return model.rawAttributes[key].field === name;
277
+ return ((_a = model.rawAttributes[key]) === null || _a === void 0 ? void 0 : _a.field) === name;
277
278
  });
278
- return (_a = model.rawAttributes[field].field) !== null && _a !== void 0 ? _a : name;
279
+ return (_b = (_a = model.rawAttributes[field]) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : name;
279
280
  }
280
281
  static isColumnJson(model, name) {
281
282
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recursyve/nestjs-data-filter",
3
- "version": "11.1.2",
3
+ "version": "11.2.0",
4
4
  "description": "NestJs DataFilter library",
5
5
  "main": "index.js",
6
6
  "scripts": {