category.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Category = db_1["default"].define('category', {
  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. description: sequelize_1.DataTypes.TEXT,
  24. position: sequelize_1.DataTypes.INTEGER,
  25. deleted: sequelize_1.DataTypes.BOOLEAN,
  26. archived: sequelize_1.DataTypes.BOOLEAN
  27. });
  28. Category.findAllWithIncludes = function () {
  29. return this.findAll({
  30. include: [
  31. {
  32. model: db_1["default"].models.thread,
  33. include: [
  34. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  35. { association: 'creator' },
  36. ]
  37. },
  38. {
  39. model: db_1["default"].models.moderation
  40. },
  41. ]
  42. });
  43. };
  44. Category.findByIdWithIncludes = function (id, args) {
  45. return this.findByPk(id, __assign(__assign({}, args), { include: [
  46. {
  47. model: db_1["default"].models.thread,
  48. include: [
  49. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  50. { association: 'creator' },
  51. ]
  52. },
  53. {
  54. model: db_1["default"].models.moderation
  55. },
  56. ] }));
  57. };
  58. Category.findWithIncludes = function (args) {
  59. return this.findAll(__assign(__assign({}, args), { include: [
  60. {
  61. model: db_1["default"].models.thread,
  62. include: [
  63. { model: db_1["default"].models.post, include: [{ association: 'author' }] },
  64. { association: 'creator' },
  65. ]
  66. },
  67. {
  68. model: db_1["default"].models.moderation
  69. },
  70. ] }));
  71. };
  72. exports["default"] = Category;