tasks-backend/db/models/index.js
2019-07-13 13:10:56 +02:00

44 lines
1004 B
JavaScript
Executable File

const Task = require('./task')
const Project = require('./project')
const User = require('./user')
const Article = require('./article')
const Tag = require('./tag')
const Comment = require('./comment')
const Vote = require('./vote')
User.hasMany(Article)
User.hasMany(Comment)
User.hasMany(Vote)
Project.hasMany(Task)
Task.belongsTo(Project)
Article.hasMany(Comment)
Article.belongsToMany(Tag, { through: 'articleTags' })
Article.belongsTo(User)
Tag.belongsToMany(Article, { through: 'articleTags' })
Comment.belongsTo(Article)
Comment.belongsTo(User)
Comment.hasMany(Vote)
Comment.belongsTo(Comment, { as: 'parent' })
Comment.hasMany(Comment, {
as: { singular: 'reply', plural: 'replies' },
foreignKey: 'parentId',
})
Vote.belongsTo(Comment)
Vote.belongsTo(User)
User.belongsToMany(Project, { through: 'projectUser' })
Project.hasMany(User)
Task.belongsToMany(User, { through: 'userTask' })
User.hasMany(Task)
module.exports = {
Task,
Project,
User,
Article,
Tag,
Comment,
Vote,
}