itlab-internal-services 2.4.2 → 2.4.3

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.
@@ -4,8 +4,9 @@ exports.PropertyLimit = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const class_validator_1 = require("class-validator");
7
+ const transform_1 = require("../../transform");
7
8
  /**
8
9
  * Creates a PropertyLimitDecorator with the given options.
9
10
  */
10
- const PropertyLimit = () => (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({ required: false, minimum: 0, example: 10, description: 'Die maximale Anzahl der Ergebnisse' }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
11
+ const PropertyLimit = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 10, description: 'Die maximale Anzahl der Ergebnisse' }), (0, transform_1.TransformNumber)({ default: 10, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
11
12
  exports.PropertyLimit = PropertyLimit;
@@ -4,13 +4,9 @@ exports.PropertySkip = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const class_validator_1 = require("class-validator");
7
+ const transform_1 = require("../../transform");
7
8
  /**
8
9
  * Creates a PropertySkipDecorator with the given options.
9
10
  */
10
- const PropertySkip = () => (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({
11
- required: false,
12
- minimum: 0,
13
- example: 0,
14
- description: 'Die Anzahl der zu überspringenden Ergebnisse',
15
- }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
11
+ const PropertySkip = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 0, description: 'Die Anzahl der zu überspringenden Ergebnisse' }), (0, transform_1.TransformNumber)({ default: 0, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
16
12
  exports.PropertySkip = PropertySkip;
@@ -4,13 +4,15 @@ exports.PropertySortDirection = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const class_validator_1 = require("class-validator");
7
+ const transform_1 = require("../../transform");
7
8
  /**
8
9
  * Creates a PropertySortDirectionDecorator with the given options.
9
10
  */
10
- const PropertySortDirection = () => (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({
11
- required: false,
12
- description: 'Die Reihenfolge der Ergebnisse (1 = aufsteigend, -1 = absteigend)',
13
- examples: [-1, 1],
14
- default: -1,
15
- }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsIn)([-1, 1]));
11
+ const PropertySortDirection = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
12
+ description: 'Die Reihenfolge der Ergebnisse (1 = aufsteigend, -1 = absteigend [default])',
13
+ examples: {
14
+ asc: { value: 1, summary: 'Aufsteigend' },
15
+ desc: { value: -1, summary: 'Absteigend (Standard)' },
16
+ },
17
+ }), (0, transform_1.TransformNumber)({ default: -1, min: -1, max: 1 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsIn)([-1, 1]));
16
18
  exports.PropertySortDirection = PropertySortDirection;
@@ -7,11 +7,9 @@ const class_validator_1 = require("class-validator");
7
7
  /**
8
8
  * Creates a PropertySortFieldDecorator with the given options.
9
9
  */
10
- const PropertySortField = () => (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({
11
- required: false,
10
+ const PropertySortField = () => (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
12
11
  description: 'Das Feld, nach dem sortiert werden soll',
13
- examples: ['title', 'timestamp', 'createdAt', 'updatedAt', '_id'],
14
- example: 'title',
15
12
  default: '_id',
13
+ example: 'title',
16
14
  }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.MinLength)(1));
17
15
  exports.PropertySortField = PropertySortField;
@@ -1,3 +1,4 @@
1
+ import { Type } from '@nestjs/common';
1
2
  /**
2
3
  * Represents the result of a search operation.
3
4
  *
@@ -6,9 +7,10 @@
6
7
  * @property {T[]} results - Array of found objects.
7
8
  * @property {number} total - Total number of objects without pagination.
8
9
  */
9
- export declare class SearchResult<T> {
10
+ export declare class SearchResult<TData> {
10
11
  /** Array of found objects. */
11
- results: T[];
12
+ results: TData[];
12
13
  /** Total number of objects without pagination. */
13
14
  total: number;
14
15
  }
16
+ export declare const ApiSearchResultResponse: <TModel extends Type<any>>(model: TModel) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -9,7 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SearchResult = void 0;
12
+ exports.ApiSearchResultResponse = exports.SearchResult = void 0;
13
+ const common_1 = require("@nestjs/common");
13
14
  const swagger_1 = require("@nestjs/swagger");
14
15
  /**
15
16
  * Represents the result of a search operation.
@@ -22,11 +23,29 @@ const swagger_1 = require("@nestjs/swagger");
22
23
  class SearchResult {
23
24
  }
24
25
  __decorate([
25
- (0, swagger_1.ApiProperty)({ description: 'Gefundene Events', type: [Object] }),
26
+ (0, swagger_1.ApiProperty)({ description: 'Gefundene Elemente', type: [Object] }),
26
27
  __metadata("design:type", Array)
27
28
  ], SearchResult.prototype, "results", void 0);
28
29
  __decorate([
29
- (0, swagger_1.ApiProperty)({ description: 'Insgesamt auffindbare Events', example: 17 }),
30
+ (0, swagger_1.ApiProperty)({ description: 'Insgesamt verfügbare Elemente', example: 17 }),
30
31
  __metadata("design:type", Number)
31
32
  ], SearchResult.prototype, "total", void 0);
32
33
  exports.SearchResult = SearchResult;
34
+ const ApiSearchResultResponse = (model) => (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(SearchResult, model), (0, swagger_1.ApiOkResponse)({
35
+ description: 'Gefundene Elemente',
36
+ schema: {
37
+ title: `SearchResultOf${model.name}`,
38
+ allOf: [
39
+ { $ref: (0, swagger_1.getSchemaPath)(SearchResult) },
40
+ {
41
+ properties: {
42
+ results: {
43
+ type: 'array',
44
+ items: { $ref: (0, swagger_1.getSchemaPath)(model) },
45
+ },
46
+ },
47
+ },
48
+ ],
49
+ },
50
+ }));
51
+ exports.ApiSearchResultResponse = ApiSearchResultResponse;
@@ -58,14 +58,7 @@ exports.Hid = Hid;
58
58
  * @param {string} param - the parameter for the API HID
59
59
  * @return A decorator that creates an API HID with the given parameter
60
60
  */
61
- const ApiHid = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({
62
- name: param,
63
- example: 'hallo-welt',
64
- examples: {
65
- 'Hallo Welt': { value: 'hallo-welt' },
66
- 'Heute ist ein toller Tag': { value: 'heute-ist-ein-toller-tag' },
67
- },
68
- }), (0, swagger_1.ApiResponse)({ description, status }));
61
+ const ApiHid = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, example: 'hallo-welt' }), (0, swagger_1.ApiResponse)({ description, status }));
69
62
  exports.ApiHid = ApiHid;
70
63
  /**
71
64
  * Check if the given value is a valid hub ID.
@@ -79,12 +79,5 @@ exports.Target = Target;
79
79
  * @param {string} param - the parameter for the API target
80
80
  * @return A decorator that creates an API target with the given parameter
81
81
  */
82
- const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({
83
- name: param,
84
- example: Targets.NEWSROOM,
85
- examples: Object.entries(Targets).reduce((map, [value, key]) => {
86
- map[key] = { value };
87
- return map;
88
- }, {}),
89
- }), (0, swagger_1.ApiResponse)({ description, status }));
82
+ const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, enum: Targets }), (0, swagger_1.ApiResponse)({ description, status }));
90
83
  exports.ApiTarget = ApiTarget;
@@ -1,4 +1,6 @@
1
+ export { TransformBoolean } from './transformBoolean';
1
2
  export { TransformImage } from './transformImage';
3
+ export { TransformNumber } from './transformNumber';
2
4
  export { TransformString } from './transformString';
3
5
  export { TransformStringArray } from './transformStringArray';
4
6
  export { isStringLike, isStringLikeMin, TransformStringLike } from './transformStringLike';
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformImage = void 0;
3
+ exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformNumber = exports.TransformImage = exports.TransformBoolean = void 0;
4
+ var transformBoolean_1 = require("./transformBoolean");
5
+ Object.defineProperty(exports, "TransformBoolean", { enumerable: true, get: function () { return transformBoolean_1.TransformBoolean; } });
4
6
  var transformImage_1 = require("./transformImage");
5
7
  Object.defineProperty(exports, "TransformImage", { enumerable: true, get: function () { return transformImage_1.TransformImage; } });
8
+ var transformNumber_1 = require("./transformNumber");
9
+ Object.defineProperty(exports, "TransformNumber", { enumerable: true, get: function () { return transformNumber_1.TransformNumber; } });
6
10
  var transformString_1 = require("./transformString");
7
11
  Object.defineProperty(exports, "TransformString", { enumerable: true, get: function () { return transformString_1.TransformString; } });
8
12
  var transformStringArray_1 = require("./transformStringArray");
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This function transforms the input value to a trimmed number if it's a string
3
+ * or a number, otherwise it returns the original value.
4
+ */
5
+ export declare function TransformBoolean(): PropertyDecorator;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformBoolean = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const transformStringLike_1 = require("./transformStringLike");
6
+ const _trim_1 = require("./_trim");
7
+ /**
8
+ * This function transforms the input value to a trimmed number if it's a string
9
+ * or a number, otherwise it returns the original value.
10
+ */
11
+ function TransformBoolean() {
12
+ return (0, class_transformer_1.Transform)(({ value }) => {
13
+ if ((0, transformStringLike_1.isStringLike)(value))
14
+ value = (0, _trim_1.trimStringLike)(value).toLowerCase();
15
+ if (value === true || value === 'true' || value === 1 || value === '1')
16
+ return true;
17
+ if (value === false || value === 'false' || value === 0 || value === '0')
18
+ return false;
19
+ return value;
20
+ });
21
+ }
22
+ exports.TransformBoolean = TransformBoolean;
@@ -0,0 +1,11 @@
1
+ interface NumberOptions {
2
+ default?: number;
3
+ min?: number;
4
+ max?: number;
5
+ }
6
+ /**
7
+ * This function transforms the input value to a trimmed number if it's a string
8
+ * or a number, otherwise it returns the original value.
9
+ */
10
+ export declare function TransformNumber(opts?: NumberOptions): PropertyDecorator;
11
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformNumber = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ /**
6
+ * This function transforms the input value to a trimmed number if it's a string
7
+ * or a number, otherwise it returns the original value.
8
+ */
9
+ function TransformNumber(opts = {}) {
10
+ return (0, class_transformer_1.Transform)(({ value }) => {
11
+ let number = Number.parseInt(value || String(opts.default), 10);
12
+ if (Number.isNaN(number) && !opts.default)
13
+ return value;
14
+ if (Number.isNaN(number))
15
+ number = opts.default;
16
+ if (opts.min && number < opts.min)
17
+ number = opts.min;
18
+ if (opts.max && number > opts.max)
19
+ number = opts.max;
20
+ return number;
21
+ });
22
+ }
23
+ exports.TransformNumber = TransformNumber;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "timo.scheuermann@sv-informatik.de",
6
6
  "url": "https://timos.design"
7
7
  },
8
- "version": "2.4.2",
8
+ "version": "2.4.3",
9
9
  "type": "commonjs",
10
10
  "files": [
11
11
  "dist"