-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRating.js
More file actions
35 lines (32 loc) · 750 Bytes
/
Rating.js
File metadata and controls
35 lines (32 loc) · 750 Bytes
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
const mongoose = require("mongoose");
let schema = new mongoose.Schema(
{
category: {
type: String,
enum: ["job", "applicant"],
required: true,
},
receiverId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
},
senderId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
},
rating: {
type: Number,
max: 5.0,
default: -1.0,
validate: {
validator: function (v) {
return v >= -1.0 && v <= 5.0;
},
msg: "Invalid rating",
},
},
},
{ collation: { locale: "en" } }
);
schema.index({ category: 1, receiverId: 1, senderId: 1 }, { unique: true });
module.exports = mongoose.model("ratings", schema);