/ src / models / GivenEventModel.ts
GivenEventModel.ts
 1  import type {
 2    InferAttributes,
 3    InferCreationAttributes,
 4    Sequelize,
 5  } from 'sequelize';
 6  import { DataTypes, Model } from 'sequelize';
 7  import type { AccountId, Address, BigIntString } from '../core/types';
 8  import getSchema from '../utils/getSchema';
 9  import { COMMON_EVENT_INIT_ATTRIBUTES } from '../core/constants';
10  import type { IEventModel } from '../events/types';
11  
12  export default class GivenEventModel
13    extends Model<
14      InferAttributes<GivenEventModel>,
15      InferCreationAttributes<GivenEventModel>
16    >
17    implements IEventModel
18  {
19    declare public accountId: AccountId; // Sender of the Give
20    declare public receiver: AccountId;
21    declare public erc20: Address;
22    declare public amt: BigIntString;
23    declare public logIndex: number;
24    declare public blockNumber: number;
25    declare public blockTimestamp: Date;
26    declare public transactionHash: string;
27  
28    public static initialize(sequelize: Sequelize): void {
29      this.init(
30        {
31          accountId: {
32            allowNull: false,
33            type: DataTypes.STRING,
34          },
35          receiver: {
36            allowNull: false,
37            type: DataTypes.STRING,
38          },
39          erc20: {
40            allowNull: false,
41            type: DataTypes.STRING,
42          },
43          amt: {
44            allowNull: false,
45            type: DataTypes.STRING,
46          },
47          ...COMMON_EVENT_INIT_ATTRIBUTES,
48        },
49        {
50          sequelize,
51          schema: getSchema(),
52          tableName: 'given_events',
53          underscored: true,
54          timestamps: true,
55          indexes: [
56            {
57              fields: ['accountId'],
58              name: `idx_given_events_accountId`,
59            },
60            {
61              fields: ['receiver'],
62              name: `idx_given_events_receiver`,
63            },
64            {
65              fields: ['erc20'],
66              name: `idx_given_events_erc20`,
67            },
68            {
69              fields: ['transactionHash', 'logIndex'],
70              name: `idx_given_events_transactionHash_logIndex`,
71            },
72          ],
73        },
74      );
75    }
76  }