Created
December 19, 2017 14:21
-
-
Save iamdanthedev/85ee5aa124ca0227cd3a02650d7143f6 to your computer and use it in GitHub Desktop.
Mongoose post init hook in typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-ignore | |
nutrientSchema.post('init', async function(this: NutrientInstance) { | |
// noinspection JSDeprecatedSymbols | |
if (!this.displayUnitCode && this.displayUnitId) { | |
const unit = await NutrientUnitModel.findById(this.displayUnitId); | |
if (unit) { | |
this.displayUnitCode = unit.code; | |
await this.save(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment