Skip to content

Commit

Permalink
fix(): add is optional to properties detected by plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 23, 2020
1 parent 7f2e7b7 commit e550426
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/type-helpers/partial-type.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@nestjs/mapped-types';
import { Field } from '../decorators';
import { ClassDecoratorFactory } from '../interfaces/class-decorator-factory.interface';
import { METADATA_FACTORY_NAME } from '../plugin/plugin-constants';
import { getFieldsAndDecoratorForType } from '../schema-builder/utils/get-fields-and-decorator.util';

export function PartialType<T>(
Expand Down Expand Up @@ -40,6 +41,15 @@ export function PartialType<T>(
applyIsOptionalDecorator(PartialObjectType, item.name);
});

if (PartialObjectType[METADATA_FACTORY_NAME]) {
const pluginFields = Object.keys(
PartialObjectType[METADATA_FACTORY_NAME](),
);
pluginFields.forEach((key) =>
applyIsOptionalDecorator(PartialObjectType, key),
);
}

Object.defineProperty(PartialObjectType, 'name', {
value: `Partial${classRef.name}`,
});
Expand Down

0 comments on commit e550426

Please sign in to comment.