-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js.html
156 lines (127 loc) · 4.53 KB
/
models.js.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: models.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: models.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file models.js
* @description Defines Mongoose schemas and models for Users, Movies, Genres, Directors, and Actors.
*/
// Import mongoose to create the schemas and models
const mongoose = require('mongoose');
// Password hashing using bcrypt
const bcrypt = require('bcrypt');
/**
* Define SCHEMAS for Users, Movies, Genres, Directors, Actors
*/
let userSchema = mongoose.Schema({
username: { type: String, required: true },
password: { type: String, required: true },
email: { type: String, required: true },
birthday: { type: Date, required: true },
favorite_movies: [{ type: mongoose.Schema.Types.String, ref: 'Movie' }]
});
/**
* Hashes the password
* @param {string} password - The password to hash.
* @returns {string} - The hashed password.
*/
userSchema.statics.hashPassword = (password) => {
return bcrypt.hashSync(password, 10); // 10 is the number of rounds to process the data for
};
/**
* Compares hashed password with the entered password
* @param {string} password - The password to validate.
* @returns {boolean} - True if passwords match, false otherwise.
*/
userSchema.methods.validatePassword = function (password) {
return bcrypt.compareSync(password, this.password);
};
/**
* Movie schema
*/
let movieSchema = mongoose.Schema({
_id: { type: String, required: true },
Title: { type: String, required: true },
ReleaseYear: String,
Rating: String,
Runtime: String,
Description: { type: String, required: true },
Genres: [{ type: mongoose.Schema.Types.String, ref: 'Genre' }],
Director: String,
Actors: [{ type: mongoose.Schema.Types.String, ref: 'Actor' }],
ImagePath: String,
Featured: Boolean
});
/**
* Genre schema
*/
let genreSchema = mongoose.Schema({
_id: { type: String, required: true },
name: { type: String, required: true },
description: { type: String, required: true }
});
/**
* Director schema
*/
let directorSchema = mongoose.Schema({
_id: { type: String, required: true },
name: { type: String, required: true },
birthDate: Date,
deathDate: Date,
bio: { type: String, required: true },
movies: [{ type: mongoose.Schema.Types.String, ref: 'Movie' }],
imagePath: { type: String, required: true }
});
/**
* Actor schema
*/
let actorSchema = mongoose.Schema({
_id: { type: String, required: true },
name: { type: String, required: true },
birthDate: Date,
deathDate: Date,
bio: { type: String, required: true },
movies: [{ type: mongoose.Schema.Types.String, ref: 'Movie' }],
imagePath: { type: String, required: true }
});
// Create the MODELS which use the SCHEMAS we just defined
let Movie = mongoose.model('Movie', movieSchema);
let User = mongoose.model('User', userSchema);
let Genre = mongoose.model('Genre', genreSchema);
let Director = mongoose.model('Director', directorSchema);
let Actor = mongoose.model('Actor', actorSchema);
// Export the MODELS so they may be used in the index.js file
module.exports.Movie = Movie;
module.exports.User = User;
module.exports.Genre = Genre;
module.exports.Director = Director;
module.exports.Actor = Actor;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#actorSchema">actorSchema</a></li><li><a href="global.html#directorSchema">directorSchema</a></li><li><a href="global.html#generateJWTToken">generateJWTToken</a></li><li><a href="global.html#genreSchema">genreSchema</a></li><li><a href="global.html#movieSchema">movieSchema</a></li><li><a href="global.html#userSchema">userSchema</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.3</a> on Sun May 26 2024 14:03:01 GMT-0500 (Central Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>