council.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. exports.__esModule = true;
  14. var db_1 = require("../db");
  15. var sequelize_1 = require("sequelize");
  16. var Council = db_1["default"].define('council', {
  17. round: {
  18. type: sequelize_1.DataTypes.INTEGER,
  19. primaryKey: true
  20. },
  21. start: sequelize_1.DataTypes.INTEGER,
  22. startDate: sequelize_1.DataTypes.DATE,
  23. end: sequelize_1.DataTypes.INTEGER,
  24. endDate: sequelize_1.DataTypes.DATE
  25. });
  26. Council.findAllWithIncludes = function () {
  27. return this.findAll({
  28. include: [
  29. {
  30. model: db_1["default"].models.consul,
  31. include: [
  32. { model: db_1["default"].models.member, attributes: ['handle'] },
  33. {
  34. association: 'votes',
  35. include: [{ model: db_1["default"].models.proposal, attributes: ['title'] }]
  36. },
  37. {
  38. association: 'voters',
  39. include: [{ model: db_1["default"].models.member, attributes: ['handle'] }]
  40. },
  41. ]
  42. },
  43. ]
  44. });
  45. };
  46. Council.findByIdWithIncludes = function (id, args) {
  47. return this.findByPk(id, __assign(__assign({}, args), { include: [
  48. {
  49. model: db_1["default"].models.consul,
  50. include: [
  51. { model: db_1["default"].models.member, attributes: ['handle'] },
  52. {
  53. association: 'votes',
  54. include: [{ model: db_1["default"].models.proposal, attributes: ['title'] }]
  55. },
  56. {
  57. association: 'voters',
  58. include: [{ model: db_1["default"].models.member, attributes: ['handle'] }]
  59. },
  60. ]
  61. },
  62. ] }));
  63. };
  64. Council.findWithIncludes = function (args) {
  65. return this.findAll(__assign(__assign({}, args), { include: [
  66. {
  67. model: db_1["default"].models.consul,
  68. include: [
  69. { model: db_1["default"].models.member, attributes: ['handle'] },
  70. {
  71. association: 'votes',
  72. include: [{ model: db_1["default"].models.proposal, attributes: ['title'] }]
  73. },
  74. {
  75. association: 'voters',
  76. include: [{ model: db_1["default"].models.member, attributes: ['handle'] }]
  77. },
  78. ]
  79. },
  80. ] }));
  81. };
  82. exports["default"] = Council;