Bansari Akhani commited on
Commit
4810dcd
·
1 Parent(s): 464e8df

add migration for invoice activity logs

Browse files
src/db/migrations/20240801160712-create-invoice-activity-logs-table.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('sequelize-cli').Migration} */
4
+ module.exports = {
5
+ up: async (queryInterface, Sequelize) => {
6
+ await queryInterface.createTable('invoice_activity_logs', {
7
+ id: {
8
+ allowNull: false,
9
+ autoIncrement: true,
10
+ primaryKey: true,
11
+ type: Sequelize.INTEGER
12
+ },
13
+ invoice_id: {
14
+ type: Sequelize.INTEGER,
15
+ allowNull: false,
16
+ references: {
17
+ model: 'invoices',
18
+ key: 'id',
19
+ },
20
+ onUpdate: 'CASCADE',
21
+ onDelete: 'CASCADE',
22
+ },
23
+ user_id: {
24
+ type: Sequelize.INTEGER,
25
+ allowNull: false,
26
+ references: {
27
+ model: 'users',
28
+ key: 'id',
29
+ },
30
+ onUpdate: 'CASCADE',
31
+ onDelete: 'CASCADE',
32
+ },
33
+ activity_type: {
34
+ type: Sequelize.STRING(50),
35
+ allowNull: false,
36
+ },
37
+ field_name: {
38
+ type: Sequelize.STRING(100),
39
+ allowNull: false,
40
+ },
41
+ old_value: {
42
+ type: Sequelize.TEXT,
43
+ },
44
+ new_value: {
45
+ type: Sequelize.TEXT,
46
+ },
47
+ created_at: {
48
+ allowNull: false,
49
+ type: Sequelize.DATE,
50
+ defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
51
+ }
52
+ });
53
+ },
54
+
55
+ down: async (queryInterface, Sequelize) => {
56
+ await queryInterface.dropTable('invoice_activity_logs');
57
+ }
58
+ };
59
+
src/models/activityLogs.ts ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Model, DataTypes, Optional } from 'sequelize';
2
+ import { Sequelize } from 'sequelize-typescript';
3
+
4
+ import Invoice from './invoice';
5
+ import { InvoiceActivityLogInterface } from 'shared/interfaces/InvoiceActivityLog.interface';
6
+ import User from './users';
7
+
8
+
9
+ class InvoiceActivityLog extends Model<InvoiceActivityLogInterface> implements InvoiceActivityLogInterface {
10
+ public id!: number;
11
+ public invoice_id!: number;
12
+ public user_id!: number;
13
+ public activity_type!: string;
14
+ public field_name!: string;
15
+ public old_value?: string;
16
+ public new_value?: string;
17
+ public created_at?: Date;
18
+
19
+ public readonly createdAt!: Date;
20
+ public readonly updatedAt!: Date;
21
+ }
22
+
23
+ InvoiceActivityLog.belongsTo(Invoice, { foreignKey: 'invoice_id' });
24
+ InvoiceActivityLog.belongsTo(User, { foreignKey: 'user_id' });
25
+
26
+ InvoiceActivityLog.init(
27
+ {
28
+ id: {
29
+ type: DataTypes.INTEGER,
30
+ autoIncrement: true,
31
+ primaryKey: true,
32
+ },
33
+ invoice_id: {
34
+ type: DataTypes.INTEGER,
35
+ allowNull: false,
36
+ references: {
37
+ model: 'invoices',
38
+ key: 'id',
39
+ },
40
+ onUpdate: 'CASCADE',
41
+ onDelete: 'CASCADE',
42
+ },
43
+ user_id: {
44
+ type: DataTypes.INTEGER,
45
+ allowNull: false,
46
+ references: {
47
+ model: 'users',
48
+ key: 'id',
49
+ },
50
+ onUpdate: 'CASCADE',
51
+ onDelete: 'CASCADE',
52
+ },
53
+ activity_type: {
54
+ type: DataTypes.STRING(50),
55
+ allowNull: false,
56
+ },
57
+ field_name: {
58
+ type: DataTypes.STRING(100),
59
+ allowNull: false,
60
+ },
61
+ old_value: {
62
+ type: DataTypes.TEXT,
63
+ },
64
+ new_value: {
65
+ type: DataTypes.TEXT,
66
+ },
67
+ created_at: {
68
+ type: DataTypes.DATE,
69
+ allowNull: false,
70
+ defaultValue: DataTypes.NOW,
71
+ },
72
+ },
73
+ {
74
+ sequelize,
75
+ tableName: 'activity_logs',
76
+ timestamps: false,
77
+ }
78
+ );
79
+
80
+ export default InvoiceActivityLog;
src/shared/interfaces/InvoiceActivityLog.interface.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ export interface InvoiceActivityLogInterface {
2
+ id?: number;
3
+ invoice_id: number;
4
+ user_id: number;
5
+ activity_type: string;
6
+ field_name: string;
7
+ old_value?: string;
8
+ new_value?: string;
9
+ created_at?: Date;
10
+ }