-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.mjs
More file actions
52 lines (50 loc) · 1.38 KB
/
db.mjs
File metadata and controls
52 lines (50 loc) · 1.38 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
import mongoose from 'mongoose'
// is the environment variable, NODE_ENV, set to PRODUCTION?
import fs from 'fs';
import path from 'path';
import url from 'url';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
let dbconf;
if (process.env.NODE_ENV === 'PRODUCTION') {
const fn = path.join(__dirname, 'config.json');
const minec = fs.readFileSync(fn);
const conf = JSON.parse(minec);
dbconf = conf.dbconf;
} else {
// if we're not in PRODUCTION mode, then use
dbconf = 'mongodb://localhost/js10193';
}
const UserSchema = new mongoose.Schema({
username: { type:String, required:true },
email: { type:String, unique:true },
password: { type:String, required:true },
Fights: [{ type : String}]
});
const nextEvent = new mongoose.Schema({
EventId:String,
Name:String,
DateTime: Number,
Status: String,
Active: Boolean,
bouts: [{type : String}]
})
const Events = new mongoose.Schema({
EventId:String,
Name:String,
DateTime: Number,
Status: String,
Active: Boolean,
bouts: [{type : String}]
});
const bouts = new mongoose.Schema({
FightId: String,
Fighter1: String,
Fighter2: String,
Order: Number,
WinnerStatus: Boolean
})
const User = mongoose.model("User", UserSchema);
const Entire = mongoose.model("Entire", Events);
const Fight = mongoose.model("bouts",bouts)
const live = mongoose.model("liveFight",nextEvent)
mongoose.connect(dbconf);