councilseat.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Seat = db.define('consul', {
  4. stake: DataTypes.INTEGER,
  5. })
  6. Seat.findAllWithIncludes = function () {
  7. return this.findAll({
  8. include: [
  9. { model: db.models.council },
  10. { model: db.models.member },
  11. {
  12. association: 'votes',
  13. include: [{ model: db.models.proposal, attributes: ['title'] }],
  14. },
  15. {
  16. association: 'voters',
  17. include: [{ model: db.models.member, attributes: ['handle'] }],
  18. },
  19. ],
  20. })
  21. }
  22. Seat.findByIdWithIncludes = function (id: number, args?: { where: any }) {
  23. return this.findByPk(id, {
  24. ...args,
  25. include: [
  26. { model: db.models.council },
  27. { model: db.models.member },
  28. {
  29. association: 'votes',
  30. include: [{ model: db.models.proposal, attributes: ['title'] }],
  31. },
  32. {
  33. association: 'voters',
  34. include: [{ model: db.models.member, attributes: ['handle'] }],
  35. },
  36. ],
  37. })
  38. }
  39. Seat.findWithIncludes = function (args: { where: any }) {
  40. return this.findAll({
  41. ...args,
  42. include: [
  43. { model: db.models.council },
  44. { model: db.models.member },
  45. {
  46. association: 'votes',
  47. include: [{ model: db.models.proposal, attributes: ['title'] }],
  48. },
  49. {
  50. association: 'voters',
  51. include: [{ model: db.models.member, attributes: ['handle'] }],
  52. },
  53. ],
  54. })
  55. }
  56. export default Seat