Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
feat(mongoose): Add SchemaTypeOpts as options parameter to Model deco…
Browse files Browse the repository at this point in the history
…rator (#20)

feat(mongoose): Add SchemaTypeOpts as options parameter to Model decorator (#20)
  • Loading branch information
fum36205 authored and serhiisol committed Jan 30, 2017
1 parent 8760a34 commit 81442c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mongoose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Mongoose#1.1.2
* New `options` parameter for `Model` decorator to pass in Schema Type options
* `Set` and `Option` decorators are now deprecated and will be removed in a future release

# Mongoose#1.1.1
* Automatic definitions generation
* new **ref(collectionRef)** - helper function to define reference to another collection/model
Expand Down
4 changes: 2 additions & 2 deletions mongoose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install @decorators/mongoose --save

#### Decorators
##### Class
* @Model(name: string)
* @Model(name: string, options?: SchemaTypeOpts)

##### Method
* @Static()
Expand All @@ -28,7 +28,7 @@ npm install @decorators/mongoose --save
* @SchemaField(schemaFieldDefinition)
* @Static()
* @Index()
* @Set() = @Option()
* @Set() = @Option() (*deprecated* Use options parameter of Model decorator instead)

### Example Mongoose Model
```typescript
Expand Down
2 changes: 1 addition & 1 deletion mongoose/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decorators/mongoose",
"version": "1.1.1",
"version": "1.1.2",
"description": "node decorators",
"main": "index.js",
"dependencies": {
Expand Down
14 changes: 11 additions & 3 deletions mongoose/src/decorators/model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { getMongooseMeta } from '../meta';

import { SchemaTypeOpts } from 'mongoose';
/**
* Defines model class
* @param {String} name Model name
* @param {SchemaTypeOpts} options
*/
export let Model = (name: string) => {
export let Model = (name: string, options?: SchemaTypeOpts<any>) => {
return (target: Function) => {
getMongooseMeta(target.prototype).name = name;
const mongooseMeta = getMongooseMeta(target.prototype);
mongooseMeta.name = name;
if (options) {
Object.keys(options)
.forEach((key) => {
mongooseMeta.options.push(key, options[key]);
});
}
}
};
2 changes: 2 additions & 0 deletions mongoose/src/decorators/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export function Index() {
* Defines set method - options for model
*/
export function Set() {
console.warn(`Deprecated: This decorator will be removed in a future release.
Use the options parameter of the Model decorator instead.`);
return (target: any, name: string) => {
getMongooseMeta(target).options.push(name);
}
Expand Down

0 comments on commit 81442c1

Please sign in to comment.