Skip to content

Commit

Permalink
feat(pojos): support File as a metadata constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Nov 10, 2021
1 parent 54d2b65 commit 0eafe05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/pojos/src/lib/create-metadata-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function createMetadataMap<TModel extends Dictionary<TModel> = any>(
| DateConstructor
| NumberConstructor
| BooleanConstructor
| typeof File.prototype.constructor
| string
| null;
}
Expand All @@ -34,6 +35,7 @@ export function createMetadataMap<TModel extends Dictionary<TModel> = any>(
| DateConstructor
| NumberConstructor
| BooleanConstructor
| typeof File.prototype.constructor
| string
| null
| false;
Expand All @@ -49,6 +51,7 @@ export function createMetadataMap<TModel extends Dictionary<TModel> = any>(
| DateConstructor
| NumberConstructor
| BooleanConstructor
| typeof File.prototype.constructor
| string
| null;
},
Expand All @@ -58,6 +61,7 @@ export function createMetadataMap<TModel extends Dictionary<TModel> = any>(
| DateConstructor
| NumberConstructor
| BooleanConstructor
| typeof File.prototype.constructor
| string
| null
| false;
Expand Down
8 changes: 8 additions & 0 deletions packages/pojos/src/lib/utils/instantiate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isDateConstructor,
isDefined,
isEmpty,
isFileConstructor,
isPrimitiveConstructor,
setMutate,
} from '@automapper/core';
Expand Down Expand Up @@ -34,6 +35,7 @@ export function instantiate<TModel extends Dictionary<TModel>>(
setMutate(obj as Record<string, unknown>, key, value);
continue;
}

if (isDateConstructor(metaResult)) {
const value = isDefined(valueAtKey)
? new Date(valueAtKey as number)
Expand All @@ -42,6 +44,12 @@ export function instantiate<TModel extends Dictionary<TModel>>(
continue;
}

if (isFileConstructor(metaResult)) {
const value = isDefined(valueAtKey) ? valueAtKey : undefined;
setMutate(obj as Record<string, unknown>, key, value);
continue;
}

if (typeof metaResult !== 'string') {
continue;
}
Expand Down

0 comments on commit 0eafe05

Please sign in to comment.