Comparing version 3.3.0 to 3.3.1
{ | ||
"name": "typegoose", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"description": "Define Mongoose models using TypeScript classes.", | ||
@@ -5,0 +5,0 @@ "main": "lib/typegoose.js", |
@@ -77,3 +77,3 @@ # Typegoose | ||
```typescript | ||
class Job extends Typegoose { | ||
class Job { | ||
@prop() | ||
@@ -105,2 +105,3 @@ title?: string; | ||
``` | ||
Please note that sub documents doesn't have to extend Typegoose. You can still give them default value in prop decorator, but you can't create staic or instance methods on them. | ||
@@ -392,2 +393,2 @@ ## Requirements | ||
* Add frequently used (currently not present) features if needed | ||
* Create moar tests (break down current huge one into multiple unit tests) | ||
* Create moar tests (break down current huge one into multiple unit tests) |
@@ -133,2 +133,21 @@ import * as _ from 'lodash'; | ||
}); | ||
it('should add a language and job using instance methods', async () => { | ||
const user = await User.create({ | ||
firstName: 'harry', | ||
lastName: 'potter', | ||
gender: Genders.MALE, | ||
languages: ['english'], | ||
uniqueId: 'unique-id', | ||
}); | ||
await user.addJob({ position: 'Dark Wizzard', title: 'Archmage' }); | ||
await user.addJob(); | ||
const savedUser = await user.addLanguage(); | ||
expect(savedUser.languages).to.include('Hungarian'); | ||
expect(savedUser.previousJobs.length).to.be.above(0); | ||
_.map(savedUser.previousJobs, (prevJob) => { | ||
expect(prevJob.startedAt).to.be.ok; | ||
}); | ||
}); | ||
}); |
@@ -1,4 +0,4 @@ | ||
import { Typegoose, prop } from '../../typegoose'; | ||
import { prop } from '../../typegoose'; | ||
export class Job extends Typegoose { | ||
export class Job { | ||
@prop() | ||
@@ -11,3 +11,3 @@ title?: string; | ||
@prop({ required: true, default: Date.now }) | ||
startedAt: Date; | ||
startedAt?: Date; | ||
} |
@@ -83,2 +83,16 @@ import * as mongoose from 'mongoose'; | ||
@instanceMethod | ||
addLanguage(this: InstanceType<User>) { | ||
this.languages.push('Hungarian'); | ||
return this.save(); | ||
} | ||
@instanceMethod | ||
addJob(this: InstanceType<User>, job: Partial<Job> = {}) { | ||
this.previousJobs.push(job); | ||
return this.save(); | ||
} | ||
static findOrCreate: (condition: any) => Promise<FindOrCreateResult<User>>; | ||
@@ -85,0 +99,0 @@ } |
111438
1692
392