1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import db from '../db'
- import { DataTypes } from 'sequelize'
- const order = [['id', 'ASC']]
- const Thread = db.define('thread', {
- id: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- },
- created: DataTypes.INTEGER,
- title: DataTypes.TEXT,
- nrInCategory: DataTypes.INTEGER,
- })
- Thread.findAllWithIncludes = function () {
- return this.findAll({
- order,
- include: [
- { model: db.models.category },
- { model: db.models.post, include: [{ association: 'author' }] },
- { association: 'creator' },
- {
- model: db.models.moderation,
- //include: [{ association: 'moderator', attributes: ['handle'] }],
- },
- ],
- })
- }
- Thread.findByIdWithIncludes = function (id: number, args?: { where: any }) {
- return this.findByPk(id, {
- ...args,
- include: [
- { model: db.models.category },
- { model: db.models.post, include: [{ association: 'author' }] },
- { association: 'creator' },
- {
- model: db.models.moderation,
- //include: [{ association: 'moderator', attributes: ['handle'] }],
- },
- ],
- })
- }
- Thread.findWithIncludes = function (args?: { where: any }) {
- return this.findAll({
- ...args,
- order,
- include: [
- { model: db.models.category },
- { model: db.models.post, include: [{ association: 'author' }] },
- { association: 'creator' },
- {
- model: db.models.moderation,
- //include: [{ association: 'moderator', attributes: ['handle'] }],
- },
- ],
- })
- }
- export default Thread
|