dip-dobit-shared-model 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ const tableDescription = await queryInterface.describeTable("DobitUsers");
6
+
7
+ if (!tableDescription.appUserId) {
8
+ await queryInterface.addColumn("DobitUsers", "appUserId", {
9
+ type: Sequelize.INTEGER.UNSIGNED,
10
+ allowNull: true,
11
+ // unique: true,
12
+ after: "dobitUserId",
13
+ });
14
+ }
15
+
16
+ if (!tableDescription.deviceId) {
17
+ await queryInterface.addColumn("DobitUsers", "deviceId", {
18
+ type: Sequelize.STRING,
19
+ allowNull: true,
20
+ after: "statusId",
21
+ });
22
+ }
23
+
24
+ if (!tableDescription.pushNotificationId) {
25
+ await queryInterface.addColumn("DobitUsers", "pushNotificationId", {
26
+ type: Sequelize.STRING,
27
+ allowNull: true,
28
+ after: "deviceId",
29
+ });
30
+ }
31
+ },
32
+
33
+ down: async (queryInterface) => {
34
+ await queryInterface.removeColumn("DobitUsers", "appUserId");
35
+ await queryInterface.removeColumn("DobitUsers", "deviceId");
36
+ await queryInterface.removeColumn("DobitUsers", "pushNotificationId");
37
+ },
38
+ };
39
+
40
+ // "use strict";
41
+
42
+ // module.exports = {
43
+ // up: async (queryInterface, Sequelize) => {
44
+ // await queryInterface.addColumn("DobitUsers", "appUserId", {
45
+ // type: Sequelize.INTEGER.UNSIGNED,
46
+ // allowNull: false,
47
+ // unique: true,
48
+ // after: "dobitUserId",
49
+ // onUpdate: "CASCADE",
50
+ // onDelete: "NO ACTION",
51
+ // });
52
+ // },
53
+
54
+ // down: async (queryInterface, Sequelize) => {
55
+ // await queryInterface.removeColumn("DobitUsers", "appUserId");
56
+ // },
57
+ // };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable("AuthRecords", {
6
+ authRecordId: {
7
+ type: Sequelize.INTEGER.UNSIGNED,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ allowNull: false,
11
+ },
12
+ dobitUserId: {
13
+ type: Sequelize.INTEGER.UNSIGNED,
14
+ allowNull: false,
15
+ references: {
16
+ model: "DobitUsers",
17
+ key: "dobitUserId",
18
+ },
19
+ onUpdate: "CASCADE",
20
+ onDelete: "CASCADE",
21
+ },
22
+ loginTime: {
23
+ type: Sequelize.DATE,
24
+ allowNull: false,
25
+ defaultValue: Sequelize.NOW,
26
+ },
27
+ lastLoginTime: {
28
+ type: Sequelize.DATE,
29
+ allowNull: true,
30
+ },
31
+ deviceId: {
32
+ type: Sequelize.STRING,
33
+ allowNull: true,
34
+ },
35
+ deviceName: {
36
+ type: Sequelize.STRING,
37
+ allowNull: true,
38
+ },
39
+ deviceType: {
40
+ type: Sequelize.ENUM("ios", "android", "web", "other"),
41
+ allowNull: true,
42
+ },
43
+ ipAddress: {
44
+ type: Sequelize.STRING,
45
+ allowNull: true,
46
+ },
47
+ location: {
48
+ type: Sequelize.STRING,
49
+ allowNull: true,
50
+ },
51
+ pushNotificationId: {
52
+ type: Sequelize.STRING,
53
+ allowNull: true,
54
+ },
55
+ isActive: {
56
+ type: Sequelize.BOOLEAN,
57
+ allowNull: false,
58
+ defaultValue: true,
59
+ },
60
+ createdAt: {
61
+ allowNull: false,
62
+ type: Sequelize.DATE,
63
+ },
64
+ updatedAt: {
65
+ allowNull: false,
66
+ type: Sequelize.DATE,
67
+ },
68
+ deletedAt: {
69
+ type: Sequelize.DATE,
70
+ allowNull: true,
71
+ },
72
+ });
73
+ },
74
+
75
+ async down(queryInterface) {
76
+ await queryInterface.dropTable("AuthRecords");
77
+ },
78
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable("DobitUserOTPs", {
6
+ otpId: {
7
+ type: Sequelize.INTEGER.UNSIGNED,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ allowNull: false,
11
+ },
12
+ dobitUserId: {
13
+ type: Sequelize.INTEGER.UNSIGNED,
14
+ allowNull: false,
15
+ references: {
16
+ model: "DobitUsers",
17
+ key: "dobitUserId",
18
+ },
19
+ onUpdate: "CASCADE",
20
+ onDelete: "CASCADE",
21
+ },
22
+ email: {
23
+ type: Sequelize.STRING,
24
+ allowNull: false,
25
+ },
26
+ otp: {
27
+ type: Sequelize.STRING,
28
+ allowNull: false,
29
+ },
30
+ expiresAt: {
31
+ type: Sequelize.DATE,
32
+ allowNull: false,
33
+ },
34
+ createdAt: {
35
+ type: Sequelize.DATE,
36
+ allowNull: false,
37
+ },
38
+ updatedAt: {
39
+ type: Sequelize.DATE,
40
+ allowNull: false,
41
+ },
42
+ });
43
+ },
44
+
45
+ async down(queryInterface) {
46
+ await queryInterface.dropTable("DobitUserOTPs");
47
+ },
48
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ // Change appUserId from INTEGER to STRING
6
+ await queryInterface.changeColumn("DobitUsers", "appUserId", {
7
+ type: Sequelize.STRING,
8
+ allowNull: true, // temporarily allow null during conversion
9
+ unique: true,
10
+ });
11
+
12
+ // Change statusId default from ACTIVE to INACTIVE
13
+ await queryInterface.changeColumn("DobitUsers", "statusId", {
14
+ type: Sequelize.INTEGER.UNSIGNED,
15
+ allowNull: false,
16
+ defaultValue: 2, // STATUS_ID.INACTIVE
17
+ });
18
+ },
19
+
20
+ async down(queryInterface, Sequelize) {
21
+ // Revert appUserId back to INTEGER
22
+ await queryInterface.changeColumn("DobitUsers", "appUserId", {
23
+ type: Sequelize.INTEGER.UNSIGNED,
24
+ allowNull: true,
25
+ unique: true,
26
+ });
27
+
28
+ // Revert statusId default back to ACTIVE
29
+ await queryInterface.changeColumn("DobitUsers", "statusId", {
30
+ type: Sequelize.INTEGER.UNSIGNED,
31
+ allowNull: false,
32
+ defaultValue: 1, // STATUS_ID.ACTIVE
33
+ });
34
+ },
35
+ };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ const tableDescription = await queryInterface.describeTable("DobitUsers");
6
+ const columnsToAdd = [];
7
+
8
+ if (!tableDescription.pin) {
9
+ columnsToAdd.push(
10
+ queryInterface.addColumn("DobitUsers", "pin", {
11
+ type: Sequelize.STRING,
12
+ allowNull: true,
13
+ after: "password",
14
+ }),
15
+ );
16
+ }
17
+
18
+ if (!tableDescription.biometrics) {
19
+ columnsToAdd.push(
20
+ queryInterface.addColumn("DobitUsers", "biometrics", {
21
+ type: Sequelize.BOOLEAN,
22
+ allowNull: false,
23
+ defaultValue: false,
24
+ after: "pushNotificationId",
25
+ }),
26
+ );
27
+ }
28
+
29
+ if (!tableDescription.pushNotification) {
30
+ columnsToAdd.push(
31
+ queryInterface.addColumn("DobitUsers", "pushNotification", {
32
+ type: Sequelize.BOOLEAN,
33
+ allowNull: false,
34
+ defaultValue: true,
35
+ after: "biometrics",
36
+ }),
37
+ );
38
+ }
39
+
40
+ if (!tableDescription.emailNotification) {
41
+ columnsToAdd.push(
42
+ queryInterface.addColumn("DobitUsers", "emailNotification", {
43
+ type: Sequelize.BOOLEAN,
44
+ allowNull: false,
45
+ defaultValue: true,
46
+ after: "pushNotification",
47
+ }),
48
+ );
49
+ }
50
+
51
+ if (!tableDescription.promotionalOffers) {
52
+ columnsToAdd.push(
53
+ queryInterface.addColumn("DobitUsers", "promotionalOffers", {
54
+ type: Sequelize.BOOLEAN,
55
+ allowNull: false,
56
+ defaultValue: true,
57
+ after: "emailNotification",
58
+ }),
59
+ );
60
+ }
61
+
62
+ if (columnsToAdd.length > 0) {
63
+ await Promise.all(columnsToAdd);
64
+ }
65
+
66
+ // Change appUserId from STRING to BIGINT
67
+ if (tableDescription.appUserId) {
68
+ await queryInterface.changeColumn("DobitUsers", "appUserId", {
69
+ type: Sequelize.BIGINT.UNSIGNED,
70
+ allowNull: true,
71
+ unique: true,
72
+ });
73
+ }
74
+ },
75
+
76
+ async down(queryInterface, Sequelize) {
77
+ await queryInterface.removeColumn("DobitUsers", "pin");
78
+ await queryInterface.removeColumn("DobitUsers", "biometrics");
79
+ await queryInterface.removeColumn("DobitUsers", "pushNotification");
80
+ await queryInterface.removeColumn("DobitUsers", "emailNotification");
81
+ await queryInterface.removeColumn("DobitUsers", "promotionalOffers");
82
+
83
+ await queryInterface.changeColumn("DobitUsers", "appUserId", {
84
+ type: Sequelize.STRING,
85
+ allowNull: true,
86
+ unique: true,
87
+ });
88
+ },
89
+ };
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable("Transactions", {
6
+ transactionId: {
7
+ type: Sequelize.INTEGER.UNSIGNED,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ allowNull: false,
11
+ },
12
+ transactionRef: {
13
+ type: Sequelize.STRING,
14
+ allowNull: false,
15
+ unique: true,
16
+ },
17
+ dobitUserId: {
18
+ type: Sequelize.INTEGER.UNSIGNED,
19
+ allowNull: false,
20
+ references: {
21
+ model: "DobitUsers",
22
+ key: "dobitUserId",
23
+ },
24
+ onUpdate: "CASCADE",
25
+ onDelete: "RESTRICT",
26
+ },
27
+ serviceType: {
28
+ type: Sequelize.ENUM(
29
+ "airtime",
30
+ "data",
31
+ "electricity",
32
+ "cable_tv",
33
+ "internet",
34
+ "water",
35
+ "betting",
36
+ "education",
37
+ "other",
38
+ ),
39
+ allowNull: false,
40
+ },
41
+ provider: {
42
+ type: Sequelize.STRING,
43
+ allowNull: false,
44
+ },
45
+ recipient: {
46
+ type: Sequelize.STRING,
47
+ allowNull: false,
48
+ },
49
+ packageName: {
50
+ type: Sequelize.STRING,
51
+ allowNull: true,
52
+ },
53
+ amount: {
54
+ type: Sequelize.DECIMAL(10, 2),
55
+ allowNull: false,
56
+ },
57
+ discount: {
58
+ type: Sequelize.DECIMAL(10, 2),
59
+ allowNull: true,
60
+ defaultValue: 0.0,
61
+ },
62
+ amountCharged: {
63
+ type: Sequelize.DECIMAL(10, 2),
64
+ allowNull: false,
65
+ },
66
+ gatewayRef: {
67
+ type: Sequelize.STRING,
68
+ allowNull: true,
69
+ },
70
+ gatewayResponse: {
71
+ type: Sequelize.STRING,
72
+ allowNull: true,
73
+ },
74
+ status: {
75
+ type: Sequelize.ENUM("pending", "successful", "failed", "reversed"),
76
+ allowNull: false,
77
+ defaultValue: "pending",
78
+ },
79
+ token: {
80
+ type: Sequelize.STRING,
81
+ allowNull: true,
82
+ },
83
+ metadata: {
84
+ type: Sequelize.JSON,
85
+ allowNull: true,
86
+ },
87
+ deviceId: {
88
+ type: Sequelize.STRING,
89
+ allowNull: true,
90
+ },
91
+ ipAddress: {
92
+ type: Sequelize.STRING,
93
+ allowNull: true,
94
+ },
95
+ createdAt: {
96
+ type: Sequelize.DATE,
97
+ allowNull: false,
98
+ },
99
+ updatedAt: {
100
+ type: Sequelize.DATE,
101
+ allowNull: false,
102
+ },
103
+ deletedAt: {
104
+ type: Sequelize.DATE,
105
+ allowNull: true,
106
+ },
107
+ });
108
+ },
109
+
110
+ async down(queryInterface) {
111
+ await queryInterface.dropTable("Transactions");
112
+ },
113
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ const tableDescription = await queryInterface.describeTable("AuthRecords");
6
+
7
+ if (!tableDescription.appUserId) {
8
+ await queryInterface.addColumn("AuthRecords", "appUserId", {
9
+ type: Sequelize.BIGINT.UNSIGNED,
10
+ allowNull: true, // temporarily allow null for existing rows
11
+ after: "dobitUserId",
12
+ references: {
13
+ model: "DobitUsers",
14
+ key: "appUserId",
15
+ },
16
+ onUpdate: "CASCADE",
17
+ onDelete: "CASCADE",
18
+ });
19
+ }
20
+ },
21
+
22
+ async down(queryInterface) {
23
+ await queryInterface.removeColumn("AuthRecords", "appUserId");
24
+ },
25
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ const tableDescription =
6
+ await queryInterface.describeTable("DobitUserOTPs");
7
+
8
+ // Add appUserId column without inline references
9
+ if (!tableDescription.appUserId) {
10
+ await queryInterface.addColumn("DobitUserOTPs", "appUserId", {
11
+ type: Sequelize.BIGINT.UNSIGNED,
12
+ allowNull: true,
13
+ after: "dobitUserId",
14
+ });
15
+
16
+ await queryInterface.addConstraint("DobitUserOTPs", {
17
+ fields: ["appUserId"],
18
+ type: "foreign key",
19
+ name: "DobitUserOTPs_appUserId_fk",
20
+ references: {
21
+ table: "DobitUsers",
22
+ field: "appUserId",
23
+ },
24
+ onUpdate: "CASCADE",
25
+ onDelete: "CASCADE",
26
+ });
27
+ }
28
+
29
+ // Add dobitUserId column without inline references
30
+ if (!tableDescription.dobitUserId) {
31
+ await queryInterface.addColumn("DobitUserOTPs", "dobitUserId", {
32
+ type: Sequelize.INTEGER.UNSIGNED,
33
+ allowNull: true,
34
+ after: "otpId",
35
+ });
36
+
37
+ await queryInterface.addConstraint("DobitUserOTPs", {
38
+ fields: ["dobitUserId"],
39
+ type: "foreign key",
40
+ name: "DobitUserOTPs_dobitUserId_fk",
41
+ references: {
42
+ table: "DobitUsers",
43
+ field: "dobitUserId",
44
+ },
45
+ onUpdate: "CASCADE",
46
+ onDelete: "CASCADE",
47
+ });
48
+ }
49
+ },
50
+
51
+ async down(queryInterface) {
52
+ await queryInterface.removeConstraint(
53
+ "DobitUserOTPs",
54
+ "DobitUserOTPs_appUserId_fk",
55
+ );
56
+ await queryInterface.removeColumn("DobitUserOTPs", "appUserId");
57
+
58
+ await queryInterface.removeConstraint(
59
+ "DobitUserOTPs",
60
+ "DobitUserOTPs_dobitUserId_fk",
61
+ );
62
+ await queryInterface.removeColumn("DobitUserOTPs", "dobitUserId");
63
+ },
64
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ const { Model, DataTypes } = require("sequelize");
4
+
5
+ module.exports = (sequelize) => {
6
+ class AuthRecords extends Model {
7
+ static associate(models) {
8
+ AuthRecords.belongsTo(models.DobitUsers, {
9
+ as: "user",
10
+ foreignKey: "dobitUserId",
11
+ });
12
+ }
13
+ }
14
+
15
+ AuthRecords.init(
16
+ {
17
+ authRecordId: {
18
+ type: DataTypes.INTEGER.UNSIGNED,
19
+ primaryKey: true,
20
+ autoIncrement: true,
21
+ allowNull: false,
22
+ },
23
+ dobitUserId: {
24
+ type: DataTypes.INTEGER.UNSIGNED,
25
+ allowNull: false,
26
+ references: {
27
+ model: "DobitUsers",
28
+ key: "dobitUserId",
29
+ },
30
+ onUpdate: "CASCADE",
31
+ onDelete: "CASCADE",
32
+ },
33
+ appUserId: {
34
+ type: DataTypes.BIGINT.UNSIGNED,
35
+ allowNull: false,
36
+ references: {
37
+ model: "DobitUsers",
38
+ key: "appUserId",
39
+ },
40
+ onUpdate: "CASCADE",
41
+ onDelete: "CASCADE",
42
+ },
43
+ loginTime: {
44
+ type: DataTypes.DATE,
45
+ allowNull: false,
46
+ defaultValue: DataTypes.NOW,
47
+ },
48
+ lastLoginTime: {
49
+ type: DataTypes.DATE,
50
+ allowNull: true,
51
+ },
52
+ deviceId: {
53
+ type: DataTypes.STRING,
54
+ allowNull: true,
55
+ },
56
+ deviceName: {
57
+ type: DataTypes.STRING,
58
+ allowNull: true,
59
+ },
60
+ deviceType: {
61
+ type: DataTypes.ENUM("ios", "android", "web", "other"),
62
+ allowNull: true,
63
+ },
64
+ ipAddress: {
65
+ type: DataTypes.STRING,
66
+ allowNull: true,
67
+ },
68
+ location: {
69
+ type: DataTypes.STRING,
70
+ allowNull: true,
71
+ },
72
+ pushNotificationId: {
73
+ type: DataTypes.STRING,
74
+ allowNull: true,
75
+ },
76
+ isActive: {
77
+ type: DataTypes.BOOLEAN,
78
+ allowNull: false,
79
+ defaultValue: true,
80
+ },
81
+ },
82
+ {
83
+ sequelize,
84
+ modelName: "AuthRecords",
85
+ tableName: "AuthRecords",
86
+ timestamps: true,
87
+ paranoid: true,
88
+ },
89
+ );
90
+
91
+ AuthRecords.removeAttribute("id");
92
+ return AuthRecords;
93
+ };
@@ -6,7 +6,6 @@ const { STATUS_ID } = require("../service/constants");
6
6
  module.exports = (sequelize) => {
7
7
  class DobitUsers extends Model {
8
8
  static associate(models) {
9
- // define association here
10
9
  DobitUsers.belongsTo(models.PortalUsers, {
11
10
  as: "createdBy",
12
11
  foreignKey: "userCreatedby",
@@ -15,6 +14,14 @@ module.exports = (sequelize) => {
15
14
  as: "updatedBy",
16
15
  foreignKey: "userUpdatedby",
17
16
  });
17
+ DobitUsers.hasMany(models.AuthRecords, {
18
+ as: "authRecords",
19
+ foreignKey: "dobitUserId",
20
+ });
21
+ DobitUsers.hasMany(models.Transactions, {
22
+ as: "transactions",
23
+ foreignKey: "dobitUserId",
24
+ });
18
25
  }
19
26
  }
20
27
 
@@ -26,6 +33,11 @@ module.exports = (sequelize) => {
26
33
  autoIncrement: true,
27
34
  allowNull: false,
28
35
  },
36
+ appUserId: {
37
+ type: DataTypes.BIGINT.UNSIGNED,
38
+ allowNull: false,
39
+ unique: true,
40
+ },
29
41
  firstName: {
30
42
  type: DataTypes.STRING,
31
43
  allowNull: false,
@@ -38,9 +50,7 @@ module.exports = (sequelize) => {
38
50
  type: DataTypes.STRING,
39
51
  allowNull: false,
40
52
  unique: true,
41
- validate: {
42
- isEmail: true,
43
- },
53
+ validate: { isEmail: true },
44
54
  },
45
55
  username: {
46
56
  type: DataTypes.STRING,
@@ -56,6 +66,10 @@ module.exports = (sequelize) => {
56
66
  type: DataTypes.STRING,
57
67
  allowNull: false,
58
68
  },
69
+ pin: {
70
+ type: DataTypes.STRING,
71
+ allowNull: true,
72
+ },
59
73
  nin: {
60
74
  type: DataTypes.STRING,
61
75
  allowNull: true,
@@ -64,13 +78,41 @@ module.exports = (sequelize) => {
64
78
  statusId: {
65
79
  type: DataTypes.INTEGER.UNSIGNED,
66
80
  allowNull: false,
67
- defaultValue: STATUS_ID.ACTIVE,
81
+ defaultValue: STATUS_ID.INACTIVE,
82
+ },
83
+ deviceId: {
84
+ type: DataTypes.STRING,
85
+ allowNull: true,
86
+ },
87
+ pushNotificationId: {
88
+ type: DataTypes.STRING,
89
+ allowNull: true,
90
+ },
91
+ biometrics: {
92
+ type: DataTypes.BOOLEAN,
93
+ allowNull: false,
94
+ defaultValue: false,
95
+ },
96
+ pushNotification: {
97
+ type: DataTypes.BOOLEAN,
98
+ allowNull: false,
99
+ defaultValue: true,
100
+ },
101
+ emailNotification: {
102
+ type: DataTypes.BOOLEAN,
103
+ allowNull: false,
104
+ defaultValue: true,
105
+ },
106
+ promotionalOffers: {
107
+ type: DataTypes.BOOLEAN,
108
+ allowNull: false,
109
+ defaultValue: true,
68
110
  },
69
111
  userCreatedby: {
70
112
  type: DataTypes.INTEGER.UNSIGNED,
71
113
  allowNull: true,
72
114
  references: {
73
- model: "PortalUser",
115
+ model: "PortalUsers",
74
116
  key: "portalUserId",
75
117
  },
76
118
  },
@@ -78,7 +120,7 @@ module.exports = (sequelize) => {
78
120
  type: DataTypes.INTEGER.UNSIGNED,
79
121
  allowNull: true,
80
122
  references: {
81
- model: "PortalUser",
123
+ model: "PortalUsers",
82
124
  key: "portalUserId",
83
125
  },
84
126
  },
@@ -95,5 +137,3 @@ module.exports = (sequelize) => {
95
137
  DobitUsers.removeAttribute("id");
96
138
  return DobitUsers;
97
139
  };
98
-
99
- // firstName, lastName, email, username, phoneNumber, password, nin
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ const { Model, DataTypes } = require("sequelize");
4
+
5
+ module.exports = (sequelize) => {
6
+ class DobitUserOTP extends Model {
7
+ static associate(models) {
8
+ DobitUserOTP.belongsTo(models.DobitUsers, {
9
+ as: "user",
10
+ foreignKey: "dobitUserId",
11
+ });
12
+ }
13
+ }
14
+
15
+ DobitUserOTP.init(
16
+ {
17
+ otpId: {
18
+ type: DataTypes.INTEGER.UNSIGNED,
19
+ primaryKey: true,
20
+ autoIncrement: true,
21
+ allowNull: false,
22
+ },
23
+ dobitUserId: {
24
+ type: DataTypes.INTEGER.UNSIGNED,
25
+ allowNull: false,
26
+ references: {
27
+ model: "DobitUsers",
28
+ key: "dobitUserId",
29
+ },
30
+ onUpdate: "CASCADE",
31
+ onDelete: "CASCADE",
32
+ },
33
+ appUserId: {
34
+ type: DataTypes.BIGINT.UNSIGNED,
35
+ allowNull: false,
36
+ references: {
37
+ model: "DobitUsers",
38
+ key: "appUserId",
39
+ },
40
+ onUpdate: "CASCADE",
41
+ onDelete: "CASCADE",
42
+ },
43
+ email: {
44
+ type: DataTypes.STRING,
45
+ allowNull: false,
46
+ },
47
+ otp: {
48
+ type: DataTypes.STRING,
49
+ allowNull: false,
50
+ },
51
+ expiresAt: {
52
+ type: DataTypes.DATE,
53
+ allowNull: false,
54
+ },
55
+ },
56
+ {
57
+ sequelize,
58
+ modelName: "DobitUserOTP",
59
+ tableName: "DobitUserOTPs",
60
+ timestamps: true,
61
+ paranoid: false,
62
+ },
63
+ );
64
+
65
+ DobitUserOTP.removeAttribute("id");
66
+ return DobitUserOTP;
67
+ };
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ const { Model, DataTypes } = require("sequelize");
4
+
5
+ module.exports = (sequelize) => {
6
+ class Transactions extends Model {
7
+ static associate(models) {
8
+ Transactions.belongsTo(models.DobitUsers, {
9
+ as: "user",
10
+ foreignKey: "dobitUserId",
11
+ });
12
+ }
13
+ }
14
+
15
+ Transactions.init(
16
+ {
17
+ transactionId: {
18
+ type: DataTypes.INTEGER.UNSIGNED,
19
+ primaryKey: true,
20
+ autoIncrement: true,
21
+ allowNull: false,
22
+ },
23
+ transactionRef: {
24
+ type: DataTypes.STRING,
25
+ allowNull: false,
26
+ unique: true,
27
+ },
28
+ dobitUserId: {
29
+ type: DataTypes.INTEGER.UNSIGNED,
30
+ allowNull: false,
31
+ references: {
32
+ model: "DobitUsers",
33
+ key: "dobitUserId",
34
+ },
35
+ onUpdate: "CASCADE",
36
+ onDelete: "RESTRICT",
37
+ },
38
+ appUserId: {
39
+ type: DataTypes.BIGINT.UNSIGNED,
40
+ allowNull: false,
41
+ references: { model: "DobitUsers", key: "appUserId" },
42
+ onUpdate: "CASCADE",
43
+ onDelete: "RESTRICT",
44
+ },
45
+ // Bills payment type: airtime, data, electricity, cable, etc.
46
+ serviceType: {
47
+ type: DataTypes.ENUM(
48
+ "airtime",
49
+ "data",
50
+ "electricity",
51
+ "cable_tv",
52
+ "internet",
53
+ "water",
54
+ "betting",
55
+ "education",
56
+ "other",
57
+ ),
58
+ allowNull: false,
59
+ },
60
+ // Network or provider: MTN, Airtel, DSTV, EKEDC, etc.
61
+ provider: {
62
+ type: DataTypes.STRING,
63
+ allowNull: false,
64
+ },
65
+ // Phone number, meter number, smartcard number, etc.
66
+ recipient: {
67
+ type: DataTypes.STRING,
68
+ allowNull: false,
69
+ },
70
+ // Data bundle, TV package, electricity token, etc.
71
+ packageName: {
72
+ type: DataTypes.STRING,
73
+ allowNull: true,
74
+ },
75
+ amount: {
76
+ type: DataTypes.DECIMAL(10, 2),
77
+ allowNull: false,
78
+ },
79
+ // Cashback or discount applied
80
+ discount: {
81
+ type: DataTypes.DECIMAL(10, 2),
82
+ allowNull: true,
83
+ defaultValue: 0.0,
84
+ },
85
+ // Final amount charged after discount
86
+ amountCharged: {
87
+ type: DataTypes.DECIMAL(10, 2),
88
+ allowNull: false,
89
+ },
90
+ // Response from payment gateway
91
+ gatewayRef: {
92
+ type: DataTypes.STRING,
93
+ allowNull: true,
94
+ },
95
+ gatewayResponse: {
96
+ type: DataTypes.STRING,
97
+ allowNull: true,
98
+ },
99
+ status: {
100
+ type: DataTypes.ENUM("pending", "successful", "failed", "reversed"),
101
+ allowNull: false,
102
+ defaultValue: "pending",
103
+ },
104
+ // Token or PIN returned for electricity payments
105
+ token: {
106
+ type: DataTypes.STRING,
107
+ allowNull: true,
108
+ },
109
+ // Extra metadata from provider response (units, bonus, etc.)
110
+ metadata: {
111
+ type: DataTypes.JSON,
112
+ allowNull: true,
113
+ },
114
+ // Device used to make the transaction
115
+ deviceId: {
116
+ type: DataTypes.STRING,
117
+ allowNull: true,
118
+ },
119
+ ipAddress: {
120
+ type: DataTypes.STRING,
121
+ allowNull: true,
122
+ },
123
+ },
124
+ {
125
+ sequelize,
126
+ modelName: "Transactions",
127
+ tableName: "Transactions",
128
+ timestamps: true,
129
+ paranoid: true,
130
+ },
131
+ );
132
+
133
+ Transactions.removeAttribute("id");
134
+ return Transactions;
135
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dip-dobit-shared-model",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "models/index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",