member.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 Member = db_1["default"].define('member', {
  17. id: {
  18. type: sequelize_1.DataTypes.INTEGER,
  19. primaryKey: true
  20. },
  21. createdAt: sequelize_1.DataTypes.INTEGER,
  22. handle: sequelize_1.DataTypes.STRING,
  23. about: sequelize_1.DataTypes.TEXT
  24. });
  25. Member.findAllWithIncludes = function () {
  26. return this.findAll({
  27. include: [
  28. { model: db_1["default"].models.post, include: [{ model: db_1["default"].models.thread }] },
  29. { model: db_1["default"].models.thread, include: [{ model: db_1["default"].models.category }] },
  30. { model: db_1["default"].models.proposal, include: [{ association: 'votes' }] },
  31. {
  32. model: db_1["default"].models.account,
  33. include: [
  34. { association: 'validated', attributes: ['id', 'timestamp'] },
  35. ]
  36. },
  37. {
  38. association: 'terms',
  39. include: [
  40. {
  41. association: 'votes',
  42. include: [
  43. {
  44. model: db_1["default"].models.proposal,
  45. include: [{ association: 'author' }]
  46. },
  47. ]
  48. },
  49. { association: 'voters', include: [{ model: db_1["default"].models.member }] },
  50. ]
  51. },
  52. {
  53. association: 'votes',
  54. include: [
  55. {
  56. model: db_1["default"].models.consul,
  57. include: [{ model: db_1["default"].models.member }]
  58. },
  59. ]
  60. },
  61. ]
  62. });
  63. };
  64. Member.findByIdWithIncludes = function (id, args) {
  65. return this.findByPk(id, __assign(__assign({}, args), { include: [
  66. { model: db_1["default"].models.post, include: [{ model: db_1["default"].models.thread }] },
  67. { model: db_1["default"].models.proposal, include: [{ association: 'votes' }] },
  68. {
  69. model: db_1["default"].models.account,
  70. include: [
  71. { association: 'validated', attributes: ['id', 'timestamp'] },
  72. ]
  73. },
  74. {
  75. association: 'terms',
  76. include: [
  77. {
  78. association: 'votes',
  79. include: [
  80. {
  81. model: db_1["default"].models.proposal,
  82. include: [{ association: 'author' }]
  83. },
  84. ]
  85. },
  86. { association: 'voters', include: [{ model: db_1["default"].models.member }] },
  87. ]
  88. },
  89. {
  90. association: 'votes',
  91. include: [
  92. {
  93. model: db_1["default"].models.consul,
  94. include: [{ model: db_1["default"].models.member }]
  95. },
  96. ]
  97. },
  98. ] }));
  99. };
  100. Member.findWithIncludes = function (args) {
  101. return this.findAll(__assign(__assign({}, args), { include: [
  102. { model: db_1["default"].models.post, include: [{ model: db_1["default"].models.thread }] },
  103. { model: db_1["default"].models.proposal, include: [{ association: 'votes' }] },
  104. {
  105. model: db_1["default"].models.account,
  106. include: [
  107. { association: 'validated', attributes: ['id', 'timestamp'] },
  108. ]
  109. },
  110. {
  111. association: 'terms',
  112. include: [
  113. {
  114. association: 'votes',
  115. include: [
  116. {
  117. model: db_1["default"].models.proposal,
  118. include: [{ association: 'author' }]
  119. },
  120. ]
  121. },
  122. { association: 'voters', include: [{ model: db_1["default"].models.member }] },
  123. ]
  124. },
  125. {
  126. association: 'votes',
  127. include: [
  128. {
  129. model: db_1["default"].models.consul,
  130. include: [{ model: db_1["default"].models.member }]
  131. },
  132. ]
  133. },
  134. {
  135. model: db_1["default"].models.account,
  136. include: [
  137. { association: 'validated', attributes: ['id', 'timestamp'] },
  138. ]
  139. },
  140. ] }));
  141. };
  142. exports["default"] = Member;