moderation.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Moderation = db.define('moderation', {
  4. created: DataTypes.INTEGER,
  5. createdAt: DataTypes.DATE,
  6. rationale: DataTypes.TEXT,
  7. })
  8. Moderation.findAllWithIncludes = function () {
  9. return this.findAll({
  10. include: [
  11. { model: db.models.category },
  12. { model: db.models.post, include: [{ association: 'author' }] },
  13. { association: 'creator' },
  14. { association: 'moderator' },
  15. ],
  16. })
  17. }
  18. Moderation.findByIdWithIncludes = function (id: number, args?: { where: any }) {
  19. return this.findByPk(id, {
  20. ...args,
  21. include: [
  22. { model: db.models.category },
  23. { model: db.models.post, include: [{ association: 'author' }] },
  24. { association: 'creator' },
  25. { association: 'moderator' },
  26. ],
  27. })
  28. }
  29. Moderation.findWithIncludes = function (args?: { where: any }) {
  30. return this.findAll({
  31. ...args,
  32. include: [
  33. { model: db.models.category },
  34. { model: db.models.post, include: [{ association: 'author' }] },
  35. { association: 'creator' },
  36. { association: 'moderator' },
  37. ],
  38. })
  39. }
  40. export default Moderation