proposal.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Proposal = db_1["default"].define('proposal', {
  17. id: {
  18. type: sequelize_1.DataTypes.INTEGER,
  19. primaryKey: true
  20. },
  21. createdAt: sequelize_1.DataTypes.INTEGER,
  22. finalizedAt: sequelize_1.DataTypes.INTEGER,
  23. title: sequelize_1.DataTypes.STRING,
  24. type: sequelize_1.DataTypes.STRING,
  25. stage: sequelize_1.DataTypes.STRING,
  26. result: sequelize_1.DataTypes.STRING,
  27. executed: sequelize_1.DataTypes.STRING,
  28. parameters: sequelize_1.DataTypes.STRING,
  29. description: sequelize_1.DataTypes.TEXT
  30. });
  31. Proposal.findAllWithIncludes = function () {
  32. return this.findAll({
  33. include: [
  34. { association: 'author', attributes: ['handle'] },
  35. {
  36. association: 'posts',
  37. include: [{ association: 'author', attributes: ['handle'] }]
  38. },
  39. {
  40. association: 'votes',
  41. attributes: ['id', 'vote'],
  42. include: [{ model: db_1["default"].models.member, attributes: ['id', 'handle'] }]
  43. },
  44. ]
  45. });
  46. };
  47. Proposal.findByIdWithIncludes = function (id, args) {
  48. return this.findByPk(id, __assign(__assign({}, args), { include: [
  49. { association: 'author', attributes: ['handle'] },
  50. {
  51. association: 'posts',
  52. include: [{ association: 'author', attributes: ['handle'] }]
  53. },
  54. {
  55. association: 'votes',
  56. attributes: ['id', 'vote'],
  57. include: [{ model: db_1["default"].models.member, attributes: ['id', 'handle'] }]
  58. },
  59. ] }));
  60. };
  61. Proposal.findWithIncludes = function (args) {
  62. return this.findAll(__assign(__assign({}, args), { include: [
  63. { association: 'author', attributes: ['handle'] },
  64. {
  65. association: 'posts',
  66. include: [{ association: 'author', attributes: ['handle'] }]
  67. },
  68. {
  69. association: 'votes',
  70. attributes: ['id', 'vote'],
  71. include: [{ association: 'author', attributes: ['id', 'handle'] }]
  72. },
  73. ] }));
  74. };
  75. exports["default"] = Proposal;