block.ts 913 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Block = db.define('block', {
  4. id: {
  5. type: DataTypes.INTEGER,
  6. primaryKey: true,
  7. },
  8. hash: DataTypes.STRING,
  9. timestamp: DataTypes.DATE,
  10. blocktime: DataTypes.INTEGER,
  11. })
  12. Block.findAllWithIncludes = function () {
  13. return this.findAll({
  14. include: [
  15. { model: db.models.era },
  16. { model: db.models.event },
  17. { association: 'validator' },
  18. ],
  19. })
  20. }
  21. Block.findByIdWithIncludes = function (id: number) {
  22. return this.findByPk(id, {
  23. include: [
  24. { model: db.models.era },
  25. { model: db.models.event },
  26. { association: 'validator' },
  27. ],
  28. })
  29. }
  30. Block.findWithIncludes = function (args: { where: any }) {
  31. return this.findAll({
  32. ...args,
  33. include: [
  34. { model: db.models.era },
  35. { model: db.models.event },
  36. { association: 'validator' },
  37. ],
  38. })
  39. }
  40. export default Block