-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
54 lines (47 loc) · 1.74 KB
/
Copy pathmodels.js
File metadata and controls
54 lines (47 loc) · 1.74 KB
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
import mongoose from "mongoose";
import dotenv from 'dotenv';
dotenv.config();
let models = {}
mongoose.connect(process.env.MONGOOSE_URI)
console.log("connected to mongodb")
// user
const userSchema = new mongoose.Schema({
username: { type: String, required: true, unique: true, trim: true },
authId: { type: String, unique: true, sparse: true },
displayName: { type: String, trim: true },
email: { type: String, trim: true },
friends: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
friend_requests: [{
from: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
date: { type: Date, default: Date.now }
}],
high_score: { type: mongoose.Schema.Types.ObjectId, ref: 'Scores' },
last_online: Date,
lifetime: {
total_games: { type: Number, default: 0 },
total_score: { type: Number, default: 0 },
total_wins: { type: Number, default: 0 }
},
bg_color: String,
button_color: String,
text_color: String
}, { timestamps: true })
models.User = mongoose.model('User', userSchema)
console.log("created user model")
// scores
const scoresSchema = new mongoose.Schema({
username: { type: String, required: true, trim: true },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
score: { type: Number, required: true, min: 0 },
date: { type: Date, default: Date.now },
})
models.Scores = mongoose.model('Scores', scoresSchema)
console.log("created scores model")
// math problems
const mathProblemSchema = new mongoose.Schema({
problem: { type: String, required: true },
answer: { type: Number, required: true },
})
models.MathProblem = mongoose.model('MathProblem', mathProblemSchema)
console.log("created math problem model")
export default models;