endpoint usuario y compras
This commit is contained in:
22
models/user.js
Executable file
22
models/user.js
Executable file
@@ -0,0 +1,22 @@
|
||||
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);
|
||||
|
||||
export default User;
|
||||
Reference in New Issue
Block a user