Skip to content

Commit

Permalink
fix: apply optional decorator to metadata factory props
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 27, 2023
1 parent 9d8588a commit d8b9dd3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/type-helpers/partial-type.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export function PartialType<T>(classRef: Type<T>): Type<Partial<T>> {
mapValues(metadata, (item) => ({ ...item, required: false }))
);

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

fields.forEach((key) => {
const metadata =
Reflect.getMetadata(
Expand All @@ -59,12 +68,5 @@ export function PartialType<T>(classRef: Type<T>): Type<Partial<T>> {
applyFields(fields);
});

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

return PartialTypeClass as Type<Partial<T>>;
}

0 comments on commit d8b9dd3

Please sign in to comment.