Snaplocal / server /src /models /User.js
Kuruva Laxmi
SnapLocal MVP - Complete platform with 4 MVP features
0f8617c
Raw
History Blame Contribute Delete
1.64 kB
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const userSchema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
role: { type: String, enum: ['photographer', 'customer'], default: 'customer' },
roles: { type: [String], enum: ['photographer', 'customer'], default: ['customer'] },
firstName: String,
lastName: String,
bio: String,
profilePicture: String,
specialty: String,
price: Number,
experience: Number,
address: String,
location: {
type: {
type: String,
enum: ['Point'],
default: 'Point'
},
coordinates: {
type: [Number],
default: [0, 0]
}
},
isVerified: {
type: Boolean,
default: false
},
recommendationScore: {
type: Number,
default: 0
},
availability: [String],
portfolio: [
{
type: { type: String, enum: ['image', 'video'], default: 'image' },
url: { type: String, required: true }
}
],
rating: { type: Number, default: 4.9 },
reviewsCount: { type: Number, default: 0 },
createdAt: { type: Date, default: Date.now }
});
userSchema.pre('save', async function () {
if (!this.isModified('password')) return;
this.password = await bcrypt.hash(this.password, 10);
});
userSchema.methods.comparePassword = async function (candidatePassword) {
return await bcrypt.compare(candidatePassword, this.password);
};
module.exports = mongoose.model('User', userSchema);