3
1

thread.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Thread = db.define('thread', {
  4. id: {
  5. type: DataTypes.INTEGER,
  6. primaryKey: true,
  7. },
  8. createdAt: DataTypes.INTEGER,
  9. title: DataTypes.TEXT,
  10. nrInCategory: DataTypes.INTEGER,
  11. })
  12. Thread.findAllWithIncludes = function () {
  13. return this.findAll({
  14. include: [
  15. { model: db.models.category },
  16. { model: db.models.post, include: [{ association: 'author' }] },
  17. { association: 'creator' },
  18. {
  19. model: db.models.moderation,
  20. //include: [{ association: 'moderator', attributes: ['handle'] }],
  21. },
  22. ],
  23. })
  24. }
  25. Thread.findByIdWithIncludes = function (id: number, args?: { where: any }) {
  26. return this.findByPk(id, {
  27. ...args,
  28. include: [
  29. { model: db.models.category },
  30. { model: db.models.post, include: [{ association: 'author' }] },
  31. { association: 'creator' },
  32. {
  33. model: db.models.moderation,
  34. //include: [{ association: 'moderator', attributes: ['handle'] }],
  35. },
  36. ],
  37. })
  38. }
  39. Thread.findWithIncludes = function (args?: { where: any }) {
  40. return this.findAll({
  41. ...args,
  42. include: [
  43. { model: db.models.category },
  44. { model: db.models.post, include: [{ association: 'author' }] },
  45. { association: 'creator' },
  46. {
  47. model: db.models.moderation,
  48. //include: [{ association: 'moderator', attributes: ['handle'] }],
  49. },
  50. ],
  51. })
  52. }
  53. export default Thread