File size: 2,137 Bytes
40f79e1
 
4810dcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40f79e1
4810dcd
 
 
 
40f79e1
881dd8e
40f79e1
4810dcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Model, DataTypes } from 'sequelize';
import { sequelize } from './index';

import Invoice from './invoice';
import { InvoiceActivityLogInterface } from 'shared/interfaces/InvoiceActivityLog.interface';
import User from './users';


class InvoiceActivityLog extends Model<InvoiceActivityLogInterface> implements InvoiceActivityLogInterface {
    public id!: number;
    public invoice_id!: number;
    public user_id!: number;
    public activity_type!: string;
    public field_name!: string;
    public old_value?: string;
    public new_value?: string;
    public created_at?: Date;

    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;
}

InvoiceActivityLog.init(
    {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true,
        },
        invoice_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'invoices',
                key: 'id',
            },
            onUpdate: 'CASCADE',
            onDelete: 'CASCADE',
        },
        user_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'users',
                key: 'id',
            },
            onUpdate: 'CASCADE',
            onDelete: 'CASCADE',
        },
        activity_type: {
            type: DataTypes.STRING(50),
            allowNull: false,
        },
        field_name: {
            type: DataTypes.STRING(100),
            allowNull: false,
        },
        old_value: {
            type: DataTypes.TEXT,
        },
        new_value: {
            type: DataTypes.TEXT,
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW,
        },
    },
    {
        sequelize,
        tableName: 'invoice_activity_logs',
        timestamps: false,
    }
);

InvoiceActivityLog.belongsTo(Invoice, { foreignKey: 'invoice_id' });
InvoiceActivityLog.belongsTo(User, { foreignKey: 'user_id' , as : 'user'} );

export default InvoiceActivityLog;