thread.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Thread = db_1["default"].define('thread', {
  17. id: {
  18. type: sequelize_1.DataTypes.INTEGER,
  19. primaryKey: true
  20. },
  21. createdAt: sequelize_1.DataTypes.INTEGER,
  22. title: sequelize_1.DataTypes.TEXT,
  23. nrInCategory: sequelize_1.DataTypes.INTEGER
  24. });
  25. Thread.findAllWithIncludes = function () {
  26. return this.findAll({
  27. include: [
  28. { model: db_1["default"].models.category },
  29. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  30. { association: 'creator' },
  31. {
  32. model: db_1["default"].models.moderation
  33. },
  34. ]
  35. });
  36. };
  37. Thread.findByIdWithIncludes = function (id, args) {
  38. return this.findByPk(id, __assign(__assign({}, args), { include: [
  39. { model: db_1["default"].models.category },
  40. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  41. { association: 'creator' },
  42. {
  43. model: db_1["default"].models.moderation
  44. },
  45. ] }));
  46. };
  47. Thread.findWithIncludes = function (args) {
  48. return this.findAll(__assign(__assign({}, args), { include: [
  49. { model: db_1["default"].models.category },
  50. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  51. { association: 'creator' },
  52. {
  53. model: db_1["default"].models.moderation
  54. },
  55. ] }));
  56. };
  57. exports["default"] = Thread;