-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy paththreads.js
More file actions
46 lines (41 loc) · 1.56 KB
/
threads.js
File metadata and controls
46 lines (41 loc) · 1.56 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
/**
* threads are top-level text entires in a Discussion. Similar to likes and reports, they use
* a "subject_id/type" relation column which could potentially be improved with standalone relational
* tables. Currently the only type is "slide" but this could be changed to support discussions for
* projects, codeblocks, etc
*/
module.exports = function(sequelize, db) {
const t = sequelize.define("threads",
{
id: {
type: db.INTEGER,
primaryKey: true,
autoIncrement: true
},
title: db.TEXT,
content: db.TEXT,
date: db.DATE,
// the type of entity this discussion refers to. only slide currently, but could be expanded
subject_type: db.TEXT,
// the id of the entity this dicussion refers to.
subject_id: db.TEXT,
// user id
uid: db.STRING,
// threads can be banned by admins, store the status here
status: db.TEXT
},
{
freezeTableName: true,
timestamps: false
}
);
t.associate = models => {
t.belongsTo(models.userprofiles, {foreignKey: "uid", targetKey: "uid", as: "userprofile"});
t.belongsTo(models.users, {foreignKey: "uid", targetKey: "id", as: "user"});
t.belongsTo(models.slides, {foreignKey: "subject_id", targetKey: "id", as: "slide"});
t.hasMany(models.comments, {foreignKey: "thread_id", sourceKey: "id", as: "commentlist"});
t.hasMany(models.likes, {foreignKey: "likeid", sourceKey: "id", as: "likelist"});
t.hasMany(models.reports, {foreignKey: "report_id", sourceKey: "id", as: "reportlist"});
};
return t;
};