-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.js
57 lines (48 loc) · 1.44 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
45
46
47
48
49
50
51
52
53
54
55
56
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
let movieSchema = mongoose.Schema({
Title: { type: String, required: true },
Description: { type: String, required: true },
Genre: {
Name: { type: String, required: true },
Description: String
},
Director: {
Name: { type: String, required: true },
Bio: String,
Birthdate: Date,
},
Actors: [String],
ImagePath: String,
Featured: Boolean
});
let userSchema = mongoose.Schema({
Username: { type: String, required: true },
Password: { type: String, required: true },
Email: { type: String, required: true },
Birthdate: 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);
};
// let directorSchema = mongoose.Schema({
// Name: String,
// Bio: String,
// Birthdate: Date
// });
// let genreSchema = mongoose.Schema({
// Name: String,
// Description: String
// });
let Movie = mongoose.model('Movie', movieSchema);
let User = mongoose.model('User', userSchema);
// let Director = mongoose.model('Director', directorSchema);
// let Genre = mongoose.model('Genre', genreSchema);
module.exports.Movie = Movie;
module.exports.User = User;
// module.exports.Director = Director;
// module.exports.Genre = Genre;