3
1

category.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const order = [['id', 'ASC']]
  4. const Category = db.define('category', {
  5. id: {
  6. type: DataTypes.INTEGER,
  7. primaryKey: true,
  8. },
  9. created: DataTypes.INTEGER,
  10. title: DataTypes.TEXT,
  11. description: DataTypes.TEXT,
  12. position: DataTypes.INTEGER,
  13. deleted: DataTypes.BOOLEAN,
  14. archived: DataTypes.BOOLEAN,
  15. })
  16. Category.findAllWithIncludes = function () {
  17. return this.findAll({
  18. order,
  19. include: [
  20. {
  21. model: db.models.thread,
  22. include: [
  23. { model: db.models.post, include: [{ association: 'author' }] },
  24. { association: 'creator' },
  25. ],
  26. },
  27. {
  28. model: db.models.moderation,
  29. //include: [{ association: 'moderator', attributes: ['handle'] }],
  30. },
  31. ],
  32. })
  33. }
  34. Category.findByIdWithIncludes = function (id: number, args?: { where: any }) {
  35. return this.findByPk(id, {
  36. ...args,
  37. include: [
  38. {
  39. model: db.models.thread,
  40. include: [
  41. { model: db.models.post, include: [{ association: 'author' }] },
  42. { association: 'creator' },
  43. ],
  44. },
  45. {
  46. model: db.models.moderation,
  47. //include: [{ association: 'moderator', attributes: ['handle'] }],
  48. },
  49. ],
  50. })
  51. }
  52. Category.findWithIncludes = function (args?: { where: any }) {
  53. return this.findAll({
  54. ...args,
  55. order,
  56. include: [
  57. {
  58. model: db.models.thread,
  59. include: [
  60. { model: db.models.post, include: [{ association: 'author' }] },
  61. { association: 'creator' },
  62. ],
  63. },
  64. {
  65. model: db.models.moderation,
  66. //include: [{ association: 'moderator', attributes: ['handle'] }],
  67. },
  68. ],
  69. })
  70. }
  71. export default Category