diff --git a/src/models/user.js b/src/models/user.js index e827eec76..2e171d0da 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -1,20 +1,20 @@ -const mongoose = require("mongoose"); -const bcrypt = require("bcrypt"); +const mongoose = require('mongoose') +const bcrypt = require('bcrypt') const UserSchema = new mongoose.Schema({ username: { type: String, required: true, unique: true }, - password: { type: String, required: true }, -}); + password: { type: String, required: true } +}) -UserSchema.pre("save", async function (next) { - if (this.isModified("password")) { - this.password = await bcrypt.hash(this.password, 10); +UserSchema.pre('save', async function (next) { + if (this.isModified('password')) { + this.password = await bcrypt.hash(this.password, 10) } - next(); -}); + next() +}) UserSchema.methods.comparePassword = function (password) { - return bcrypt.compare(password, this.password); -}; + return bcrypt.compare(password, this.password) +} -module.exports = mongoose.model("User", UserSchema); +module.exports = mongoose.model('User', UserSchema)