File size: 1,642 Bytes
0f8617c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);