3
1

era.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. stake: DataTypes.DECIMAL,
  13. })
  14. Era.findAllWithIncludes = function () {
  15. return this.findAll({
  16. include: [
  17. {
  18. model: db.models.block,
  19. attributes: ['id', 'blocktime', 'timestamp'],
  20. include: [
  21. {
  22. association: 'validator',
  23. attributes: ['key'],
  24. include: [
  25. { model: db.models.member, attributes: ['id', 'handle'] },
  26. ],
  27. },
  28. { model: db.models.event },
  29. ],
  30. },
  31. ],
  32. })
  33. }
  34. Era.findByIdWithIncludes = function (id: number) {
  35. return this.findByPk(id, {
  36. include: [
  37. {
  38. model: db.models.block,
  39. attributes: ['id', 'blocktime', 'timestamp'],
  40. include: [
  41. {
  42. association: 'validator',
  43. attributes: ['key'],
  44. include: [
  45. { model: db.models.member, attributes: ['id', 'handle'] },
  46. ],
  47. },
  48. { model: db.models.event },
  49. ],
  50. },
  51. ],
  52. })
  53. }
  54. Era.findWithIncludes = function (args: { where: any }) {
  55. return this.findAll({
  56. ...args,
  57. include: [
  58. {
  59. model: db.models.block,
  60. attributes: ['id', 'blocktime', 'timestamp'],
  61. include: [
  62. {
  63. association: 'validator',
  64. attributes: ['key'],
  65. include: [
  66. { model: db.models.member, attributes: ['id', 'handle'] },
  67. ],
  68. },
  69. { model: db.models.event },
  70. ],
  71. },
  72. ],
  73. })
  74. }
  75. export default Era