feat: mongoose schema hooks

This commit is contained in:
Arash Sheyda
2023-07-09 13:25:38 +03:00
parent 5a43ebe06f
commit d92a58b2ad
3 changed files with 30 additions and 7 deletions

View File

@ -7,10 +7,20 @@ export const UserSchema = defineMongooseModel({
type: 'string',
required: true,
},
slug: {
email: {
type: 'string',
required: true,
unique: false,
},
password: {
type: 'string',
required: true,
unique: true,
},
},
hooks(schema) {
schema.pre('save', function (this, next) {
this.password = `hash.${this.password}.${Math.random()}`
next()
})
},
})