post.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 Post = db_1["default"].define('post', {
  17. id: {
  18. type: sequelize_1.DataTypes.INTEGER,
  19. primaryKey: true
  20. },
  21. text: sequelize_1.DataTypes.TEXT,
  22. createdAt: sequelize_1.DataTypes.INTEGER
  23. });
  24. Post.findAllWithIncludes = function () {
  25. return this.findAll({
  26. include: [
  27. { model: db_1["default"].models.thread, include: [{ model: db_1["default"].models.category }] },
  28. { association: 'author' },
  29. { association: 'moderator' },
  30. ]
  31. });
  32. };
  33. Post.findByIdWithIncludes = function (id, args) {
  34. return this.findByPk(id, __assign(__assign({}, args), { include: [
  35. { model: db_1["default"].models.thread, include: [{ model: db_1["default"].models.category }] },
  36. { association: 'moderator' },
  37. ] }));
  38. };
  39. Post.findWithIncludes = function (args) {
  40. return this.findAll(__assign(__assign({}, args), { include: [
  41. { model: db_1["default"].models.thread, include: [{ model: db_1["default"].models.category }] },
  42. { model: db_1["default"].models.thread },
  43. { association: 'moderator' },
  44. ] }));
  45. };
  46. exports["default"] = Post;