Spaces:
Runtime error
Runtime error
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; | |