Files
finanzas_api/models/user.js
2022-04-19 20:43:49 -05:00

27 lines
896 B
JavaScript
Executable File

const mongoose = require('mongoose');
const {Schema} =mongoose;
const bscryptjs = require('bcrypt');
const UserSchema=new Schema({
name: {type:String,required:true},
email: {type:String, required:true},
password:{type:String, required:true},
date: {type: Date, default: Date.now},
role: {type: String,default:"USER",enum:["USER","ADMIN"]},
image: {
secure_url: {type: String, default:"https://res.cloudinary.com/mdchaparror/image/upload/v1650399265/avatars/user.jpg"},
public_id: String
}
});
UserSchema.methods.encryptPassword = async (password)=>{
const salt=await bscryptjs.genSalt(10);
const hash=await bscryptjs.hash(password,salt);
return hash;
};
UserSchema.methods.matchPassword=async function (password){
return await bscryptjs.compare(password,this.password);
};
const User = mongoose.model('Users',UserSchema);
module.exports = User