dip-dobit-shared-model 1.0.8 → 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,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
+ };
@@ -30,6 +30,16 @@ module.exports = (sequelize) => {
30
30
  onUpdate: "CASCADE",
31
31
  onDelete: "CASCADE",
32
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
+ },
33
43
  loginTime: {
34
44
  type: DataTypes.DATE,
35
45
  allowNull: false,
@@ -18,6 +18,10 @@ module.exports = (sequelize) => {
18
18
  as: "authRecords",
19
19
  foreignKey: "dobitUserId",
20
20
  });
21
+ DobitUsers.hasMany(models.Transactions, {
22
+ as: "transactions",
23
+ foreignKey: "dobitUserId",
24
+ });
21
25
  }
22
26
  }
23
27
 
@@ -30,7 +34,7 @@ module.exports = (sequelize) => {
30
34
  allowNull: false,
31
35
  },
32
36
  appUserId: {
33
- type: DataTypes.STRING,
37
+ type: DataTypes.BIGINT.UNSIGNED,
34
38
  allowNull: false,
35
39
  unique: true,
36
40
  },
@@ -62,6 +66,10 @@ module.exports = (sequelize) => {
62
66
  type: DataTypes.STRING,
63
67
  allowNull: false,
64
68
  },
69
+ pin: {
70
+ type: DataTypes.STRING,
71
+ allowNull: true,
72
+ },
65
73
  nin: {
66
74
  type: DataTypes.STRING,
67
75
  allowNull: true,
@@ -80,6 +88,26 @@ module.exports = (sequelize) => {
80
88
  type: DataTypes.STRING,
81
89
  allowNull: true,
82
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,
110
+ },
83
111
  userCreatedby: {
84
112
  type: DataTypes.INTEGER.UNSIGNED,
85
113
  allowNull: true,
@@ -30,6 +30,16 @@ module.exports = (sequelize) => {
30
30
  onUpdate: "CASCADE",
31
31
  onDelete: "CASCADE",
32
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
+ },
33
43
  email: {
34
44
  type: DataTypes.STRING,
35
45
  allowNull: false,
@@ -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.8",
3
+ "version": "1.0.9",
4
4
  "main": "models/index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",