Files
finanzas_api/models/user.js

24 lines
665 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}
});
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