Added user model, joi validation and register new user function
This commit is contained in:
1 parent
862e420c9e
commit
baba4ec540
9 files changed
+658
-15
No files matched your search
@@ -0,0 +1,45 @@
|
||||
const mongoose = require('mongoose')
|
||||
const bcrypt = require('bcrypt')
|
||||
|
||||
const UserSchema = mongoose.Schema({
|
||||
username: {
|
||||
type: String
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
profilePicUrl: {
|
||||
type: String
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
isVerified: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
updated_at: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
})
|
||||
|
||||
UserSchema.pre('save', async function (next) {
|
||||
if (!this.isModified('password')) {
|
||||
next()
|
||||
}
|
||||
const salt = bcrypt.genSalt(10);
|
||||
this.password = await bcrypt.hash(this.password, salt);
|
||||
})
|
||||
|
||||
module.exports = mongoose.model('User',UserSchema)
|
||||
Reference in new issue
Block a user