1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.IntersectionType = void 0;
|
4 | const mapped_types_1 = require("@nestjs/mapped-types");
|
5 | const constants_1 = require("../constants");
|
6 | const decorators_1 = require("../decorators");
|
7 | const model_properties_accessor_1 = require("../services/model-properties-accessor");
|
8 | const mapped_types_utils_1 = require("./mapped-types.utils");
|
9 | const modelPropertiesAccessor = new model_properties_accessor_1.ModelPropertiesAccessor();
|
10 | function IntersectionType(classARef, classBRef) {
|
11 | const fieldsOfA = modelPropertiesAccessor.getModelProperties(classARef.prototype);
|
12 | const fieldsOfB = modelPropertiesAccessor.getModelProperties(classBRef.prototype);
|
13 | class IntersectionTypeClass {
|
14 | constructor() {
|
15 | (0, mapped_types_1.inheritPropertyInitializers)(this, classARef);
|
16 | (0, mapped_types_1.inheritPropertyInitializers)(this, classBRef);
|
17 | }
|
18 | }
|
19 | (0, mapped_types_1.inheritValidationMetadata)(classARef, IntersectionTypeClass);
|
20 | (0, mapped_types_1.inheritTransformationMetadata)(classARef, IntersectionTypeClass);
|
21 | (0, mapped_types_1.inheritValidationMetadata)(classBRef, IntersectionTypeClass);
|
22 | (0, mapped_types_1.inheritTransformationMetadata)(classBRef, IntersectionTypeClass);
|
23 | (0, mapped_types_utils_1.clonePluginMetadataFactory)(IntersectionTypeClass, classARef.prototype);
|
24 | (0, mapped_types_utils_1.clonePluginMetadataFactory)(IntersectionTypeClass, classBRef.prototype);
|
25 | fieldsOfA.forEach((propertyKey) => {
|
26 | const metadata = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES, classARef.prototype, propertyKey);
|
27 | const decoratorFactory = (0, decorators_1.ApiProperty)(metadata);
|
28 | decoratorFactory(IntersectionTypeClass.prototype, propertyKey);
|
29 | });
|
30 | fieldsOfB.forEach((propertyKey) => {
|
31 | const metadata = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES, classBRef.prototype, propertyKey);
|
32 | const decoratorFactory = (0, decorators_1.ApiProperty)(metadata);
|
33 | decoratorFactory(IntersectionTypeClass.prototype, propertyKey);
|
34 | });
|
35 | Object.defineProperty(IntersectionTypeClass, 'name', {
|
36 | value: `Intersection${classARef.name}${classBRef.name}`
|
37 | });
|
38 | return IntersectionTypeClass;
|
39 | }
|
40 | exports.IntersectionType = IntersectionType;
|