Skip to content

Commit

Permalink
Fixed some namespace pollution when using the ObjectID decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 29, 2015
1 parent 0b0e8da commit 486696d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
8 changes: 2 additions & 6 deletions dist/lib/Decorators.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/Decorators.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions lib/Decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export function Transform(fromDB: (value: any) => any, toDB: (value: any) => any
}

export function ObjectID(target: { constructor: typeof Instance }, name: string) {
target.constructor.schema = <Schema>_.clone(target.constructor.schema || {});
target.constructor.schema[name] = MongoDB.ObjectID;
target.constructor.transforms[name] = {
fromDB: value => value && value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value,
toDB: value => value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value
};
Property(MongoDB.ObjectID)(target, name);
Transform(
value => value && value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value,
value => value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value
)(target, name);
}

0 comments on commit 486696d

Please sign in to comment.