-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.js
44 lines (38 loc) · 1.06 KB
/
models.js
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
// Import modules
const mongoose = require('mongoose'),
bcrypt = require('bcrypt');
// Movie Schema
const movieSchema = mongoose.Schema({
Title: { type: String, required: true },
Description: { type: String, required: true },
Premiere: Date,
Genre: {
Type: String,
Description: String,
},
Director: {
Name: String,
Bio: String,
},
Actors: [String],
ImagePath: String,
Featured: Boolean,
});
// User Schema
const userSchema = mongoose.Schema({
Username: { type: String, required: true },
Password: { type: String, required: true },
Email: { type: String, required: true },
Birthday: Date,
FavoriteMovies: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Movie' }],
});
userSchema.statics.hashPassword = (Password) => {
return bcrypt.hashSync(Password, 10);
};
userSchema.methods.validatePassword = function (Password) {
return bcrypt.compareSync(Password, this.Password);
};
const Movie = mongoose.model('Movie', movieSchema);
const User = mongoose.model('User', userSchema);
module.exports.Movie = Movie;
module.exports.User = User;