@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
@@ -1,2 +1,45 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.QueryModel = exports.QueryRuleModel = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const class_validator_1 = require("class-validator");
15
+ const rule_model_1 = require("./rule.model");
16
+ const conditions = ["and", "or"];
17
+ class QueryRuleModel extends rule_model_1.RuleModel {
18
+ }
19
+ exports.QueryRuleModel = QueryRuleModel;
20
+ __decorate([
21
+ (0, class_validator_1.IsString)(),
22
+ (0, swagger_1.ApiProperty)({ type: () => String }),
23
+ __metadata("design:type", String)
24
+ ], QueryRuleModel.prototype, "id", void 0);
25
+ let QueryModel = class QueryModel {
26
+ };
27
+ exports.QueryModel = QueryModel;
28
+ __decorate([
29
+ (0, class_validator_1.IsIn)(conditions),
30
+ (0, swagger_1.ApiProperty)({ enum: conditions, enumName: "Condition" }),
31
+ __metadata("design:type", String)
32
+ ], QueryModel.prototype, "condition", void 0);
33
+ __decorate([
34
+ (0, class_validator_1.IsArray)(),
35
+ (0, swagger_1.ApiProperty)({
36
+ oneOf: [
37
+ { type: "array", items: { $ref: (0, swagger_1.getSchemaPath)(QueryRuleModel) } },
38
+ { type: "array", items: { $ref: (0, swagger_1.getSchemaPath)(QueryModel) } },
39
+ ],
40
+ }),
41
+ __metadata("design:type", Array)
42
+ ], QueryModel.prototype, "rules", void 0);
43
+ exports.QueryModel = QueryModel = __decorate([
44
+ (0, swagger_1.ApiExtraModels)(QueryRuleModel)
45
+ ], QueryModel);
@@ -1,6 +1,6 @@
1
- import { FilterOperators } from "../operators";
2
- export interface RuleModel {
3
- operation: FilterOperators;
1
+ import { FilterOperatorTypes } from "../operators";
2
+ export declare class RuleModel {
3
+ operation: FilterOperatorTypes;
4
4
  value: unknown | unknown[];
5
5
  }
6
6
  export interface IRule {
@@ -1,2 +1,30 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RuleModel = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const class_validator_1 = require("class-validator");
15
+ const operators_1 = require("../operators");
16
+ class RuleModel {
17
+ }
18
+ exports.RuleModel = RuleModel;
19
+ __decorate([
20
+ (0, class_validator_1.IsIn)(Object.values(operators_1.FilterOperatorTypes)),
21
+ (0, swagger_1.ApiProperty)({ enum: operators_1.FilterOperatorTypes, enumName: "FilterOperatorTypes" }),
22
+ __metadata("design:type", String)
23
+ ], RuleModel.prototype, "operation", void 0);
24
+ __decorate([
25
+ (0, class_validator_1.IsDefined)(),
26
+ (0, swagger_1.ApiProperty)({
27
+ oneOf: [{ type: "object" }, { type: "array", items: { type: "object" } }],
28
+ }),
29
+ __metadata("design:type", Object)
30
+ ], RuleModel.prototype, "value", void 0);
@@ -9,7 +9,7 @@ class EnumOrderRule extends order_rule_1.OrderRule {
9
9
  super(definition);
10
10
  }
11
11
  getOrderOption(model) {
12
- let order = `CASE ${this.path ? sequelize_utils_1.SequelizeUtils.getLiteralFullName(this.attribute, this.path) : this.attribute} `;
12
+ let order = `CASE ${this.path ? sequelize_utils_1.SequelizeUtils.getLiteralFullName(this.attribute, this.path) : `\`${model.name}\`.\`${this.attribute}\``} `;
13
13
  for (let i = 0; i < this.priorities.length; ++i) {
14
14
  order += `WHEN '${this.priorities[i]}' THEN ${this.priorities.length - i} `;
15
15
  }
@@ -1,4 +1,5 @@
1
+ export * from "./default.order-rule";
1
2
  export * from "./enum.order-rule";
2
3
  export * from "./if.order-rule";
3
4
  export * from "./is-null.order-rule";
4
- export * from "./default.order-rule";
5
+ export * from "./json.order-rule";
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default.order-rule"), exports);
17
18
  __exportStar(require("./enum.order-rule"), exports);
18
19
  __exportStar(require("./if.order-rule"), exports);
19
20
  __exportStar(require("./is-null.order-rule"), exports);
20
- __exportStar(require("./default.order-rule"), exports);
21
+ __exportStar(require("./json.order-rule"), exports);
@@ -0,0 +1,11 @@
1
+ import { M } from "../../sequelize.utils";
2
+ import { BaseOrderRuleDefinition, OrderItemColumn, OrderRule, OrderRuleContext } from "./order-rule";
3
+ import { JsonConfig } from "../..";
4
+ export interface JsonRuleDefinition {
5
+ json: JsonConfig;
6
+ }
7
+ export declare class JsonOrderRule extends OrderRule implements JsonRuleDefinition {
8
+ json: JsonConfig;
9
+ constructor(definition: BaseOrderRuleDefinition & JsonRuleDefinition);
10
+ getOrderOption(model: typeof M, context: OrderRuleContext): OrderItemColumn;
11
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonOrderRule = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ const order_rule_1 = require("./order-rule");
6
+ class JsonOrderRule extends order_rule_1.OrderRule {
7
+ constructor(definition) {
8
+ super(definition);
9
+ }
10
+ 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}')))`);
13
+ }
14
+ }
15
+ exports.JsonOrderRule = JsonOrderRule;
@@ -1,13 +1,18 @@
1
1
  import { Col, Fn, Literal } from "sequelize/types/utils";
2
2
  import { M } from "../../sequelize.utils";
3
3
  import { IRule } from "../models";
4
+ import { DataFilterUserModel } from "../../models/user.model";
4
5
  export type OrderItemColumn = string | Col | Fn | Literal;
5
6
  export interface BaseOrderRuleDefinition {
6
7
  attribute: string;
7
8
  path?: string;
8
9
  }
10
+ export type OrderRuleContext<Request = unknown> = {
11
+ request: Request;
12
+ user: DataFilterUserModel | null;
13
+ };
9
14
  export interface OrderRuleDefinition extends BaseOrderRuleDefinition, IRule {
10
- getOrderOption(model: typeof M): OrderItemColumn;
15
+ getOrderOption(model: typeof M, context: OrderRuleContext): OrderItemColumn;
11
16
  }
12
17
  export declare abstract class OrderRule implements OrderRuleDefinition {
13
18
  readonly _type = "order_rule";
@@ -15,5 +20,5 @@ export declare abstract class OrderRule implements OrderRuleDefinition {
15
20
  path?: string;
16
21
  protected constructor(definition?: BaseOrderRuleDefinition);
17
22
  static validate(definition: IRule): boolean;
18
- abstract getOrderOption(model: typeof M): OrderItemColumn;
23
+ abstract getOrderOption(model: typeof M, context: OrderRuleContext): OrderItemColumn;
19
24
  }
@@ -10,16 +10,19 @@ export interface AttributesConfigModel {
10
10
  customAttributes: CustomAttributesConfig[];
11
11
  }
12
12
  export declare class AttributesConfig implements AttributesConfigModel {
13
+ private _searchableAttributes?;
13
14
  readonly key: string;
14
15
  attributes?: FindAttributeOptions;
15
- searchableAttributes?: string[];
16
+ searchableTranslationAttributes?: string[];
16
17
  path: PathConfig;
17
18
  includes: IncludeConfig[];
18
19
  customAttributes: CustomAttributesConfig[];
19
20
  ignoreInSearch: boolean;
20
21
  constructor(key: string | symbol);
22
+ get searchableAttributes(): string[] | undefined;
21
23
  setAttributes(attributes?: FindAttributeOptions): void;
22
24
  setSearchableAttributes(attributes: string[]): void;
25
+ setSearchableTranslationAttributes(attributes: string[]): void;
23
26
  setPath(path: PathConfig): void;
24
27
  containsPath(path: string): boolean;
25
28
  setIgnoreInPath(ignore: boolean): void;
@@ -14,11 +14,18 @@ class AttributesConfig {
14
14
  paranoid: true
15
15
  });
16
16
  }
17
+ get searchableAttributes() {
18
+ var _a;
19
+ return (_a = this._searchableAttributes) === null || _a === void 0 ? void 0 : _a.filter(attribute => { var _a; return !((_a = this.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.includes(attribute)); });
20
+ }
17
21
  setAttributes(attributes) {
18
22
  this.attributes = attributes;
19
23
  }
20
24
  setSearchableAttributes(attributes) {
21
- this.searchableAttributes = attributes;
25
+ this._searchableAttributes = attributes;
26
+ }
27
+ setSearchableTranslationAttributes(attributes) {
28
+ this.searchableTranslationAttributes = attributes;
22
29
  }
23
30
  setPath(path) {
24
31
  this.path = path;
@@ -9,20 +9,24 @@ export interface DataFilterConfigModel {
9
9
  customAttributes: CustomAttributesConfig[];
10
10
  }
11
11
  export declare class DataFilterConfig implements DataFilterConfigModel {
12
+ private _searchableAttributes?;
12
13
  model: typeof Model;
13
14
  attributes?: FindAttributeOptions;
14
- searchableAttributes?: string[];
15
+ searchableTranslationAttributes?: string[];
15
16
  exportColumns?: string[];
16
17
  customAttributes: CustomAttributesConfig[];
17
18
  ignoreInSearch: boolean;
18
19
  setModel(model: typeof Model): void;
19
20
  setIgnoreInPath(ignore: boolean): void;
20
21
  setAttributes(attributes?: FindAttributeOptions): void;
22
+ get searchableAttributes(): string[] | undefined;
21
23
  setSearchableAttributes(attributes: string[]): void;
24
+ setSearchableTranslationAttributes(attributes: string[]): void;
22
25
  setExportColumns(exportColumns: string[]): void;
23
26
  addCustomAttribute(attribute: CustomAttributesConfig): void;
24
27
  transformAttributesConfig(options?: object): FindAttributeOptions | null;
25
28
  getCustomAttributes(options?: object): CustomAttributesModel[];
26
29
  getCustomAttributesIncludes(): IncludeConfig[];
27
30
  getSearchableAttributes(): string[];
31
+ getSearchableTranslationAttributes(): string[];
28
32
  }
@@ -16,8 +16,15 @@ class DataFilterConfig {
16
16
  setAttributes(attributes) {
17
17
  this.attributes = attributes;
18
18
  }
19
+ get searchableAttributes() {
20
+ var _a;
21
+ return (_a = this._searchableAttributes) === null || _a === void 0 ? void 0 : _a.filter((attribute) => { var _a; return !((_a = this.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.includes(attribute)); });
22
+ }
19
23
  setSearchableAttributes(attributes) {
20
- this.searchableAttributes = attributes;
24
+ this._searchableAttributes = attributes;
25
+ }
26
+ setSearchableTranslationAttributes(attributes) {
27
+ this.searchableTranslationAttributes = attributes;
21
28
  }
22
29
  setExportColumns(exportColumns) {
23
30
  this.exportColumns = exportColumns;
@@ -72,18 +79,30 @@ class DataFilterConfig {
72
79
  });
73
80
  }
74
81
  getSearchableAttributes() {
75
- var _a;
82
+ var _a, _b, _c;
76
83
  if (this.ignoreInSearch) {
77
84
  return [];
78
85
  }
86
+ if (!((_a = this.searchableAttributes) === null || _a === void 0 ? void 0 : _a.length) && ((_b = this.searchableTranslationAttributes) === null || _b === void 0 ? void 0 : _b.length)) {
87
+ return [];
88
+ }
79
89
  if (this.searchableAttributes) {
80
90
  return sequelize_utils_1.SequelizeUtils.getModelSearchableFieldAttributes(this.model, this.searchableAttributes);
81
91
  }
82
92
  const searchableAttributes = sequelize_utils_1.SequelizeUtils.getModelSearchableAttributes(this.model);
83
- const attributes = sequelize_utils_1.SequelizeUtils.getModelSearchableFieldAttributes(this.model, (_a = this.attributes) !== null && _a !== void 0 ? _a : []);
84
- return attributes.length ?
85
- attributes === null || attributes === void 0 ? void 0 : attributes.filter(x => searchableAttributes.some(attr => attr === x)) :
86
- searchableAttributes;
93
+ const attributes = sequelize_utils_1.SequelizeUtils.getModelSearchableFieldAttributes(this.model, (_c = this.attributes) !== null && _c !== void 0 ? _c : []);
94
+ return (attributes.length ?
95
+ attributes.filter(x => searchableAttributes.includes(x)) :
96
+ searchableAttributes).filter(attribute => { var _a; return !((_a = this.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.includes(attribute)); });
97
+ }
98
+ getSearchableTranslationAttributes() {
99
+ if (this.ignoreInSearch) {
100
+ return [];
101
+ }
102
+ if (!this.searchableTranslationAttributes) {
103
+ return [];
104
+ }
105
+ return sequelize_utils_1.SequelizeUtils.getModelSearchableFieldAttributes(this.model, this.searchableTranslationAttributes);
87
106
  }
88
107
  }
89
108
  exports.DataFilterConfig = DataFilterConfig;
@@ -1,19 +1,22 @@
1
+ import { Type as _Type } from "@nestjs/common";
1
2
  import { QueryModel } from "../filter/models/query.model";
2
- export interface FilterPageMode {
3
+ export declare class FilterPageModel {
3
4
  number: number;
4
5
  size: number;
5
6
  offset?: number;
6
7
  }
7
- export interface FilterSearchModel {
8
+ export declare class FilterSearchModel {
8
9
  value: string;
9
10
  }
10
- export interface OrderModel {
11
+ declare const directions: readonly ["asc", "desc", ""];
12
+ export type Direction = (typeof directions)[number];
13
+ export declare class OrderModel {
11
14
  column: string;
12
- direction: "asc" | "desc" | "";
15
+ direction: Direction;
13
16
  nullLast?: boolean;
14
17
  }
15
- export interface FilterQueryModel {
16
- page?: FilterPageMode;
18
+ export declare class FilterQueryModel {
19
+ page?: FilterPageModel;
17
20
  search?: FilterSearchModel;
18
21
  query?: QueryModel;
19
22
  order?: OrderModel | OrderModel[];
@@ -28,3 +31,9 @@ export interface FilterResultModel<T> {
28
31
  size: number;
29
32
  };
30
33
  }
34
+ export declare class PageModel {
35
+ number: number;
36
+ size: number;
37
+ }
38
+ export declare function FilterResultModelMixin<T extends _Type>(Base: T): _Type<FilterResultModel<T>>;
39
+ export {};
@@ -1,2 +1,150 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PageModel = exports.FilterQueryModel = exports.OrderModel = exports.FilterSearchModel = exports.FilterPageModel = void 0;
13
+ exports.FilterResultModelMixin = FilterResultModelMixin;
14
+ const swagger_1 = require("@nestjs/swagger");
15
+ const class_transformer_1 = require("class-transformer");
16
+ const class_validator_1 = require("class-validator");
17
+ const query_model_1 = require("../filter/models/query.model");
18
+ class FilterPageModel {
19
+ }
20
+ exports.FilterPageModel = FilterPageModel;
21
+ __decorate([
22
+ (0, class_validator_1.IsInt)(),
23
+ (0, swagger_1.ApiProperty)({ type: () => Number }),
24
+ __metadata("design:type", Number)
25
+ ], FilterPageModel.prototype, "number", void 0);
26
+ __decorate([
27
+ (0, class_validator_1.IsInt)(),
28
+ (0, swagger_1.ApiProperty)({ type: () => Number }),
29
+ __metadata("design:type", Number)
30
+ ], FilterPageModel.prototype, "size", void 0);
31
+ __decorate([
32
+ (0, class_validator_1.IsOptional)(),
33
+ (0, class_validator_1.IsInt)(),
34
+ (0, swagger_1.ApiPropertyOptional)({ type: () => Number }),
35
+ __metadata("design:type", Number)
36
+ ], FilterPageModel.prototype, "offset", void 0);
37
+ class FilterSearchModel {
38
+ }
39
+ exports.FilterSearchModel = FilterSearchModel;
40
+ __decorate([
41
+ (0, class_validator_1.IsString)(),
42
+ (0, swagger_1.ApiProperty)({ type: () => String }),
43
+ __metadata("design:type", String)
44
+ ], FilterSearchModel.prototype, "value", void 0);
45
+ const directions = ["asc", "desc", ""];
46
+ class OrderModel {
47
+ }
48
+ exports.OrderModel = OrderModel;
49
+ __decorate([
50
+ (0, class_validator_1.IsString)(),
51
+ (0, swagger_1.ApiProperty)({ type: () => String }),
52
+ __metadata("design:type", String)
53
+ ], OrderModel.prototype, "column", void 0);
54
+ __decorate([
55
+ (0, class_validator_1.IsOptional)(),
56
+ (0, class_validator_1.IsIn)(directions),
57
+ (0, swagger_1.ApiPropertyOptional)({ enum: directions, enumName: "Direction" }),
58
+ __metadata("design:type", String)
59
+ ], OrderModel.prototype, "direction", void 0);
60
+ __decorate([
61
+ (0, class_validator_1.IsOptional)(),
62
+ (0, class_validator_1.IsBoolean)(),
63
+ (0, swagger_1.ApiPropertyOptional)({ type: () => Boolean }),
64
+ __metadata("design:type", Boolean)
65
+ ], OrderModel.prototype, "nullLast", void 0);
66
+ let FilterQueryModel = class FilterQueryModel {
67
+ };
68
+ exports.FilterQueryModel = FilterQueryModel;
69
+ __decorate([
70
+ (0, class_validator_1.IsOptional)(),
71
+ (0, class_validator_1.ValidateNested)(),
72
+ (0, class_transformer_1.Type)(() => FilterPageModel),
73
+ (0, swagger_1.ApiPropertyOptional)({ type: () => FilterPageModel }),
74
+ __metadata("design:type", FilterPageModel)
75
+ ], FilterQueryModel.prototype, "page", void 0);
76
+ __decorate([
77
+ (0, class_validator_1.IsOptional)(),
78
+ (0, class_validator_1.ValidateNested)(),
79
+ (0, class_transformer_1.Type)(() => FilterSearchModel),
80
+ (0, swagger_1.ApiPropertyOptional)({ type: () => FilterSearchModel }),
81
+ __metadata("design:type", FilterSearchModel)
82
+ ], FilterQueryModel.prototype, "search", void 0);
83
+ __decorate([
84
+ (0, class_validator_1.IsOptional)(),
85
+ (0, class_validator_1.ValidateNested)(),
86
+ (0, class_transformer_1.Type)(() => query_model_1.QueryModel),
87
+ (0, swagger_1.ApiPropertyOptional)({ type: () => query_model_1.QueryModel }),
88
+ __metadata("design:type", query_model_1.QueryModel)
89
+ ], FilterQueryModel.prototype, "query", void 0);
90
+ __decorate([
91
+ (0, class_validator_1.IsOptional)(),
92
+ (0, class_validator_1.ValidateNested)(),
93
+ (0, class_transformer_1.Type)(() => OrderModel),
94
+ (0, swagger_1.ApiPropertyOptional)({
95
+ oneOf: [
96
+ {
97
+ $ref: (0, swagger_1.getSchemaPath)(OrderModel),
98
+ },
99
+ {
100
+ type: "array",
101
+ items: { $ref: (0, swagger_1.getSchemaPath)(OrderModel) },
102
+ },
103
+ ],
104
+ }),
105
+ __metadata("design:type", Object)
106
+ ], FilterQueryModel.prototype, "order", void 0);
107
+ __decorate([
108
+ (0, class_validator_1.IsOptional)(),
109
+ (0, class_validator_1.IsObject)(),
110
+ (0, swagger_1.ApiPropertyOptional)({ type: () => Object }),
111
+ __metadata("design:type", Object)
112
+ ], FilterQueryModel.prototype, "data", void 0);
113
+ __decorate([
114
+ (0, class_validator_1.IsOptional)(),
115
+ (0, class_validator_1.IsString)(),
116
+ (0, swagger_1.ApiPropertyOptional)({ type: () => String }),
117
+ __metadata("design:type", String)
118
+ ], FilterQueryModel.prototype, "groupBy", void 0);
119
+ exports.FilterQueryModel = FilterQueryModel = __decorate([
120
+ (0, swagger_1.ApiExtraModels)(OrderModel)
121
+ ], FilterQueryModel);
122
+ class PageModel {
123
+ }
124
+ exports.PageModel = PageModel;
125
+ __decorate([
126
+ (0, swagger_1.ApiProperty)({ type: () => Number }),
127
+ __metadata("design:type", Number)
128
+ ], PageModel.prototype, "number", void 0);
129
+ __decorate([
130
+ (0, swagger_1.ApiProperty)({ type: () => Number }),
131
+ __metadata("design:type", Number)
132
+ ], PageModel.prototype, "size", void 0);
133
+ function FilterResultModelMixin(Base) {
134
+ class _FilterResultModel {
135
+ }
136
+ __decorate([
137
+ (0, swagger_1.ApiProperty)({ type: () => Base, isArray: true }),
138
+ __metadata("design:type", Array)
139
+ ], _FilterResultModel.prototype, "values", void 0);
140
+ __decorate([
141
+ (0, swagger_1.ApiProperty)({ type: () => Number }),
142
+ __metadata("design:type", Number)
143
+ ], _FilterResultModel.prototype, "total", void 0);
144
+ __decorate([
145
+ (0, swagger_1.ApiPropertyOptional)({ type: () => PageModel }),
146
+ __metadata("design:type", PageModel)
147
+ ], _FilterResultModel.prototype, "page", void 0);
148
+ Object.defineProperty(_FilterResultModel, "name", { value: `${Base.name}FilterResultModel` });
149
+ return _FilterResultModel;
150
+ }
@@ -6,6 +6,7 @@ export interface IncludeConfig {
6
6
  path: string;
7
7
  attributes?: FindAttributeOptions;
8
8
  searchableAttributes?: string[];
9
+ searchableTranslationAttributes?: string[];
9
10
  ignoreInSearch?: boolean;
10
11
  order?: Order;
11
12
  where?: IncludeWhereModel;
@@ -19,6 +20,7 @@ export interface IncludeModel {
19
20
  path: string;
20
21
  attributes?: FindAttributeOptions;
21
22
  searchableAttributes?: string[];
23
+ searchableTranslationAttributes?: string[];
22
24
  ignoreInSearch?: boolean;
23
25
  order?: Order;
24
26
  where?: WhereOptions;
@@ -3,4 +3,5 @@ export interface SearchAttributesModel {
3
3
  key: string;
4
4
  literalKey?: string;
5
5
  isJson?: boolean;
6
+ isTranslationAttribute?: boolean;
6
7
  }
@@ -6,7 +6,7 @@ import { PathModel } from "../models/path.model";
6
6
  import { SearchAttributesModel } from "../models/search-attributes.model";
7
7
  export declare class SequelizeModelScanner {
8
8
  getIncludes(model: typeof Model, path: PathModel, additionalIncludes: IncludeModel[], attributes?: FindAttributeOptions | null, ignoreAttributes?: boolean): IncludeOptions[];
9
- getAttributes(model: typeof Model, path: PathModel, additionalIncludes: IncludeModel[], attributes?: FindAttributeOptions): SearchAttributesModel[];
9
+ getAttributes(model: typeof Model, path: PathModel, additionalIncludes: IncludeModel[], attributes?: FindAttributeOptions, isTranslationAttribute?: boolean): SearchAttributesModel[];
10
10
  getOrder(model: typeof Model, orderObj: OrderModel): Order | undefined;
11
11
  getGroup(model: typeof Model, orderObj: OrderModel): string[];
12
12
  getOrderIncludes(model: typeof Model, orderObj: OrderModel): IncludeOptions[];
@@ -71,7 +71,7 @@ let SequelizeModelScanner = class SequelizeModelScanner {
71
71
  (_b = includes[0].include) === null || _b === void 0 ? void 0 : _b.push(...sequelize_utils_1.SequelizeUtils.reduceIncludes(addIncludes, ignoreAttributes));
72
72
  return result;
73
73
  }
74
- getAttributes(model, path, additionalIncludes, attributes) {
74
+ getAttributes(model, path, additionalIncludes, attributes, isTranslationAttribute = false) {
75
75
  var _a;
76
76
  const objects = path.path.split(".");
77
77
  if (!objects.length) {
@@ -89,20 +89,27 @@ let SequelizeModelScanner = class SequelizeModelScanner {
89
89
  name: a,
90
90
  key: sequelize_utils_1.SequelizeUtils.getAttributeFullName(a, path.path),
91
91
  literalKey: sequelize_utils_1.SequelizeUtils.getLiteralFullName(a, path.path),
92
- isJson: sequelize_utils_1.SequelizeUtils.isColumnJson(model, a)
92
+ isJson: sequelize_utils_1.SequelizeUtils.isColumnJson(model, a),
93
+ isTranslationAttribute
93
94
  })));
94
- for (const include of additionalIncludes) {
95
- if (include.ignoreInSearch) {
96
- continue;
95
+ if (!isTranslationAttribute) {
96
+ for (const include of additionalIncludes) {
97
+ if (include.ignoreInSearch) {
98
+ continue;
99
+ }
100
+ result.push(...this.getAttributes(model, {
101
+ path: include.path
102
+ }, [], (_a = include.searchableAttributes) !== null && _a !== void 0 ? _a : include.attributes).map(a => {
103
+ var _a, _b;
104
+ return ({
105
+ name: a.name,
106
+ key: sequelize_utils_1.SequelizeUtils.getAttributeFullName(a.name, [path.path, include.path].join(".")),
107
+ literalKey: sequelize_utils_1.SequelizeUtils.getLiteralFullName(a.name, [path.path, include.path].join(".")),
108
+ isJson: a.isJson,
109
+ isTranslationAttribute: (_b = (_a = include.searchableTranslationAttributes) === null || _a === void 0 ? void 0 : _a.includes(a.name)) !== null && _b !== void 0 ? _b : false
110
+ });
111
+ }));
97
112
  }
98
- result.push(...this.getAttributes(model, {
99
- path: include.path
100
- }, [], (_a = include.searchableAttributes) !== null && _a !== void 0 ? _a : include.attributes).map(a => ({
101
- name: a.name,
102
- key: sequelize_utils_1.SequelizeUtils.getAttributeFullName(a.name, [path.path, include.path].join(".")),
103
- literalKey: sequelize_utils_1.SequelizeUtils.getLiteralFullName(a.name, [path.path, include.path].join(".")),
104
- isJson: a.isJson
105
- })));
106
113
  }
107
114
  return result;
108
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recursyve/nestjs-data-filter",
3
- "version": "11.0.0",
3
+ "version": "11.1.1",
4
4
  "description": "NestJs DataFilter library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,6 +28,7 @@
28
28
  "sequelize-typescript": ">=2.1.0"
29
29
  },
30
30
  "dependencies": {
31
+ "@nestjs/swagger": "^11.1.0",
31
32
  "csv-stringify": "^6.5.2",
32
33
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
33
34
  },