12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import db from '../db'
- import { DataTypes } from 'sequelize'
- const Era = db.define('era', {
- id: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- },
- waiting: DataTypes.INTEGER,
- active: DataTypes.INTEGER,
- slots: DataTypes.INTEGER,
- timestamp: DataTypes.DATE,
- })
- Era.findAllWithIncludes = function () {
- return this.findAll({
- include: [
- {
- model: db.models.block,
- attributes: ['id', 'blocktime', 'timestamp'],
- include: [
- {
- association: 'validator',
- attributes: ['key'],
- include: [
- { model: db.models.member, attributes: ['id', 'handle'] },
- ],
- },
- { model: db.models.event },
- ],
- },
- ],
- })
- }
- Era.findByIdWithIncludes = function (id: number) {
- return this.findByPk(id, {
- include: [
- {
- model: db.models.block,
- attributes: ['id', 'blocktime', 'timestamp'],
- include: [
- {
- association: 'validator',
- attributes: ['key'],
- include: [
- { model: db.models.member, attributes: ['id', 'handle'] },
- ],
- },
- { model: db.models.event },
- ],
- },
- ],
- })
- }
- Era.findWithIncludes = function (args: { where: any }) {
- return this.findAll({
- ...args,
- include: [
- {
- model: db.models.block,
- attributes: ['id', 'blocktime', 'timestamp'],
- include: [
- {
- association: 'validator',
- attributes: ['key'],
- include: [
- { model: db.models.member, attributes: ['id', 'handle'] },
- ],
- },
- { model: db.models.event },
- ],
- },
- ],
- })
- }
- export default Era
|