narinder1231 commited on
Commit
f11f54f
·
1 Parent(s): 7ef526e

create model for error log

Browse files
src/models/errorLog.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ DataTypes,
3
+ Model,
4
+ InferAttributes,
5
+ InferCreationAttributes,
6
+ CreationOptional,
7
+ } from 'sequelize';
8
+ import { sequelize } from './index';
9
+ import { ErrorLogInterface } from '../shared/interfaces/errorLog.interface';
10
+ import Invoice from './invoice';
11
+
12
+
13
+ class ErrorLog extends Model<InferAttributes<ErrorLog>, InferCreationAttributes<ErrorLog>>implements ErrorLogInterface {
14
+ declare id?: CreationOptional<number>;
15
+ declare invoice_id: number;
16
+ declare error_type: string;
17
+ declare error_details: string;
18
+ }
19
+
20
+ ErrorLog.init(
21
+ {
22
+ id: {
23
+ type: DataTypes.INTEGER,
24
+ primaryKey: true,
25
+ autoIncrement: true
26
+ },
27
+ invoice_id: {
28
+ type: DataTypes.INTEGER,
29
+ references: {
30
+ model: 'Invoices',
31
+ key: 'id'
32
+ },
33
+ onDelete: 'CASCADE'
34
+ },
35
+ error_type: {
36
+ type: DataTypes.STRING
37
+ },
38
+ error_details: {
39
+ type: DataTypes.TEXT
40
+ },
41
+ },
42
+ {
43
+ sequelize,
44
+ tableName: 'error_log',
45
+ underscored: true,
46
+ freezeTableName: true,
47
+ timestamps: true,
48
+ createdAt: "created_at",
49
+ updatedAt: "updated_at"
50
+ }
51
+ );
52
+
53
+ ErrorLog.belongsTo(Invoice, { foreignKey: 'invoice_id' });
54
+
55
+ export default ErrorLog
src/shared/interfaces/errorLog.interface.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ export interface ErrorLogInterface {
2
+ id?: number,
3
+ invoice_id: number,
4
+ error_type: string,
5
+ error_details: string,
6
+ }