-
Notifications
You must be signed in to change notification settings - Fork 17
/
model.js
96 lines (86 loc) · 2.35 KB
/
model.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
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
var Sequelize = require('sequelize');
var config = require("./config.json");
var sequelize = new Sequelize(
config.mysql_db, config.mysql_user, config.mysql_pass, {
dialect: 'mysql',
logging: false,
underscored: true,
timezone: config.timezone
});
exports.sql = sequelize;
// Tables
exports.Session = sequelize.define("session", {
"name": Sequelize.STRING,
"email": Sequelize.STRING,
"user_id": Sequelize.STRING,
"session_key": {type: Sequelize.STRING, unique: true},
"authenticated": Sequelize.BOOLEAN,
"owner": Sequelize.BOOLEAN
}, {
underscored: true
});
exports.TA = sequelize.define("tas", {
"email": Sequelize.STRING,
"full_name": Sequelize.STRING,
"video_chat_url": Sequelize.STRING,
"semester": Sequelize.STRING,
"time_helped": Sequelize.INTEGER,
"num_helped": Sequelize.INTEGER,
"time_today": Sequelize.INTEGER,
"num_today": Sequelize.INTEGER,
"admin": Sequelize.BOOLEAN
}, {
tableName: 'tas',
underscored: true
});
exports.Entry = sequelize.define("entry", {
"user_id": Sequelize.STRING,
"name": Sequelize.STRING,
"semester": Sequelize.STRING,
"entry_time": Sequelize.DATE,
"help_time": Sequelize.DATE,
"exit_time": Sequelize.DATE,
"wait_estimate": Sequelize.INTEGER,
"status": Sequelize.INTEGER, //0: on queue, 1: being helped, 2: helped
"question": Sequelize.STRING,
"cooldown_override": Sequelize.BOOLEAN,
"update_requested": Sequelize.BOOLEAN
}, {
timestamps: false,
underscored: true
});
exports.Topic = sequelize.define("topic", {
"name": Sequelize.STRING,
"out_date": Sequelize.DATE,
"due_date": Sequelize.DATE,
"semester": Sequelize.STRING
}, {
underscored: true
});
exports.Option = sequelize.define("option", {
"key": {type: Sequelize.STRING, unique: true},
"value": Sequelize.STRING
}, {
underscored: true
});
// Relationships
exports.Entry.belongsTo(exports.Session, {
foreignKey: "session_id"
});
exports.Entry.belongsTo(exports.Topic, {
foreignKey: "topic_id"
});
exports.Topic.hasMany(exports.Entry);
exports.Entry.belongsTo(exports.TA, {
as: "TA",
foreignKey: "ta_id"
});
exports.Session.belongsTo(exports.TA, {
as: "TA",
foreignKey: "ta_id"
});
exports.TA.belongsTo(exports.Entry, {
as: 'helping_entry',
foreignKey: 'helping_id',
constraints: false
});