1
0

era.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Era = db.define('era', {
  4. id: {
  5. type: DataTypes.INTEGER,
  6. primaryKey: true,
  7. },
  8. waiting: DataTypes.INTEGER,
  9. active: DataTypes.INTEGER,
  10. slots: DataTypes.INTEGER,
  11. timestamp: DataTypes.DATE,
  12. })
  13. Era.findAllWithIncludes = function () {
  14. return this.findAll({
  15. include: [
  16. {
  17. model: db.models.block,
  18. attributes: ['id', 'blocktime', 'timestamp'],
  19. include: [
  20. {
  21. association: 'validator',
  22. attributes: ['key'],
  23. include: [
  24. { model: db.models.member, attributes: ['id', 'handle'] },
  25. ],
  26. },
  27. { model: db.models.event },
  28. ],
  29. },
  30. ],
  31. })
  32. }
  33. Era.findByIdWithIncludes = function (id: number) {
  34. return this.findByPk(id, {
  35. include: [
  36. {
  37. model: db.models.block,
  38. attributes: ['id', 'blocktime', 'timestamp'],
  39. include: [
  40. {
  41. association: 'validator',
  42. attributes: ['key'],
  43. include: [
  44. { model: db.models.member, attributes: ['id', 'handle'] },
  45. ],
  46. },
  47. { model: db.models.event },
  48. ],
  49. },
  50. ],
  51. })
  52. }
  53. Era.findWithIncludes = function (args: { where: any }) {
  54. return this.findAll({
  55. ...args,
  56. include: [
  57. {
  58. model: db.models.block,
  59. attributes: ['id', 'blocktime', 'timestamp'],
  60. include: [
  61. {
  62. association: 'validator',
  63. attributes: ['key'],
  64. include: [
  65. { model: db.models.member, attributes: ['id', 'handle'] },
  66. ],
  67. },
  68. { model: db.models.event },
  69. ],
  70. },
  71. ],
  72. })
  73. }
  74. export default Era