1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PickType = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | const mapped_types_1 = require("@nestjs/mapped-types");
|
6 | const decorators_1 = require("../decorators");
|
7 | const get_fields_and_decorator_util_1 = require("../schema-builder/utils/get-fields-and-decorator.util");
|
8 | const type_helpers_utils_1 = require("./type-helpers.utils");
|
9 | function PickType(classRef, keys, decorator) {
|
10 | const { fields, decoratorFactory } = (0, get_fields_and_decorator_util_1.getFieldsAndDecoratorForType)(classRef);
|
11 | const isInheritedPredicate = (propertyKey) => keys.includes(propertyKey);
|
12 | class PickObjectType {
|
13 | constructor() {
|
14 | (0, mapped_types_1.inheritPropertyInitializers)(this, classRef, isInheritedPredicate);
|
15 | }
|
16 | }
|
17 | decoratorFactory({ isAbstract: true })(PickObjectType);
|
18 | if (decorator) {
|
19 | decorator({ isAbstract: true })(PickObjectType);
|
20 | }
|
21 | else {
|
22 | decoratorFactory({ isAbstract: true })(PickObjectType);
|
23 | }
|
24 | (0, mapped_types_1.inheritValidationMetadata)(classRef, PickObjectType, isInheritedPredicate);
|
25 | (0, mapped_types_1.inheritTransformationMetadata)(classRef, PickObjectType, isInheritedPredicate);
|
26 | fields
|
27 | .filter((item) => keys.includes(item.name))
|
28 | .forEach((item) => {
|
29 | if ((0, shared_utils_1.isFunction)(item.typeFn)) {
|
30 | |
31 |
|
32 |
|
33 |
|
34 | item.typeFn();
|
35 | }
|
36 | (0, decorators_1.Field)(item.typeFn, { ...item.options })(PickObjectType.prototype, item.name);
|
37 | (0, type_helpers_utils_1.applyFieldDecorators)(PickObjectType, item);
|
38 | });
|
39 | return PickObjectType;
|
40 | }
|
41 | exports.PickType = PickType;
|