forked from nax3t/background-slider
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathreview.js
41 lines (39 loc) · 1.17 KB
/
review.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
var mongoose = require("mongoose");
var reviewSchema = new mongoose.Schema({
rating: {
// Setting the field type
type: Number,
// Making the star rating required
required: "Please provide a rating (1-5 stars).",
// Defining min and max values
min: 1,
max: 5,
// Adding validation to see if the entry is an integer
validate: {
// validator accepts a function definition which it uses for validation
validator: Number.isInteger,
message: "{VALUE} is not an integer value."
}
},
// review text
text: {
type: String
},
// author id and username fields
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
// campground associated with the review
campground: {
type: mongoose.Schema.Types.ObjectId,
ref: "Campground"
}
}, {
// if timestamps are set to true, mongoose assigns createdAt and updatedAt fields to your schema, the type assigned is Date.
timestamps: true
});
module.exports = mongoose.model("Review", reviewSchema);