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