dip-dobit-shared-model 1.0.7 → 1.0.8
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.
- package/migrations/20260507180000-add-field-to-dobituser-table.js +57 -0
- package/migrations/20260508163000-create-table-AuthRecords.js +78 -0
- package/migrations/20260508225000-create-table-DobitUserOTPs.js +48 -0
- package/migrations/20260509001000-change-data-in-DobitUser.js +35 -0
- package/models/authRecords.js +83 -0
- package/models/dobitUser.js +21 -9
- package/models/dobitUserOTP.js +57 -0
- package/package.json +1 -1
|
@@ -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,83 @@
|
|
|
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
|
+
loginTime: {
|
|
34
|
+
type: DataTypes.DATE,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
defaultValue: DataTypes.NOW,
|
|
37
|
+
},
|
|
38
|
+
lastLoginTime: {
|
|
39
|
+
type: DataTypes.DATE,
|
|
40
|
+
allowNull: true,
|
|
41
|
+
},
|
|
42
|
+
deviceId: {
|
|
43
|
+
type: DataTypes.STRING,
|
|
44
|
+
allowNull: true,
|
|
45
|
+
},
|
|
46
|
+
deviceName: {
|
|
47
|
+
type: DataTypes.STRING,
|
|
48
|
+
allowNull: true,
|
|
49
|
+
},
|
|
50
|
+
deviceType: {
|
|
51
|
+
type: DataTypes.ENUM("ios", "android", "web", "other"),
|
|
52
|
+
allowNull: true,
|
|
53
|
+
},
|
|
54
|
+
ipAddress: {
|
|
55
|
+
type: DataTypes.STRING,
|
|
56
|
+
allowNull: true,
|
|
57
|
+
},
|
|
58
|
+
location: {
|
|
59
|
+
type: DataTypes.STRING,
|
|
60
|
+
allowNull: true,
|
|
61
|
+
},
|
|
62
|
+
pushNotificationId: {
|
|
63
|
+
type: DataTypes.STRING,
|
|
64
|
+
allowNull: true,
|
|
65
|
+
},
|
|
66
|
+
isActive: {
|
|
67
|
+
type: DataTypes.BOOLEAN,
|
|
68
|
+
allowNull: false,
|
|
69
|
+
defaultValue: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
sequelize,
|
|
74
|
+
modelName: "AuthRecords",
|
|
75
|
+
tableName: "AuthRecords",
|
|
76
|
+
timestamps: true,
|
|
77
|
+
paranoid: true,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
AuthRecords.removeAttribute("id");
|
|
82
|
+
return AuthRecords;
|
|
83
|
+
};
|
package/models/dobitUser.js
CHANGED
|
@@ -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,10 @@ 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
|
+
});
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -26,6 +29,11 @@ module.exports = (sequelize) => {
|
|
|
26
29
|
autoIncrement: true,
|
|
27
30
|
allowNull: false,
|
|
28
31
|
},
|
|
32
|
+
appUserId: {
|
|
33
|
+
type: DataTypes.STRING,
|
|
34
|
+
allowNull: false,
|
|
35
|
+
unique: true,
|
|
36
|
+
},
|
|
29
37
|
firstName: {
|
|
30
38
|
type: DataTypes.STRING,
|
|
31
39
|
allowNull: false,
|
|
@@ -38,9 +46,7 @@ module.exports = (sequelize) => {
|
|
|
38
46
|
type: DataTypes.STRING,
|
|
39
47
|
allowNull: false,
|
|
40
48
|
unique: true,
|
|
41
|
-
validate: {
|
|
42
|
-
isEmail: true,
|
|
43
|
-
},
|
|
49
|
+
validate: { isEmail: true },
|
|
44
50
|
},
|
|
45
51
|
username: {
|
|
46
52
|
type: DataTypes.STRING,
|
|
@@ -64,13 +70,21 @@ module.exports = (sequelize) => {
|
|
|
64
70
|
statusId: {
|
|
65
71
|
type: DataTypes.INTEGER.UNSIGNED,
|
|
66
72
|
allowNull: false,
|
|
67
|
-
defaultValue: STATUS_ID.
|
|
73
|
+
defaultValue: STATUS_ID.INACTIVE,
|
|
74
|
+
},
|
|
75
|
+
deviceId: {
|
|
76
|
+
type: DataTypes.STRING,
|
|
77
|
+
allowNull: true,
|
|
78
|
+
},
|
|
79
|
+
pushNotificationId: {
|
|
80
|
+
type: DataTypes.STRING,
|
|
81
|
+
allowNull: true,
|
|
68
82
|
},
|
|
69
83
|
userCreatedby: {
|
|
70
84
|
type: DataTypes.INTEGER.UNSIGNED,
|
|
71
85
|
allowNull: true,
|
|
72
86
|
references: {
|
|
73
|
-
model: "
|
|
87
|
+
model: "PortalUsers",
|
|
74
88
|
key: "portalUserId",
|
|
75
89
|
},
|
|
76
90
|
},
|
|
@@ -78,7 +92,7 @@ module.exports = (sequelize) => {
|
|
|
78
92
|
type: DataTypes.INTEGER.UNSIGNED,
|
|
79
93
|
allowNull: true,
|
|
80
94
|
references: {
|
|
81
|
-
model: "
|
|
95
|
+
model: "PortalUsers",
|
|
82
96
|
key: "portalUserId",
|
|
83
97
|
},
|
|
84
98
|
},
|
|
@@ -95,5 +109,3 @@ module.exports = (sequelize) => {
|
|
|
95
109
|
DobitUsers.removeAttribute("id");
|
|
96
110
|
return DobitUsers;
|
|
97
111
|
};
|
|
98
|
-
|
|
99
|
-
// firstName, lastName, email, username, phoneNumber, password, nin
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
email: {
|
|
34
|
+
type: DataTypes.STRING,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
otp: {
|
|
38
|
+
type: DataTypes.STRING,
|
|
39
|
+
allowNull: false,
|
|
40
|
+
},
|
|
41
|
+
expiresAt: {
|
|
42
|
+
type: DataTypes.DATE,
|
|
43
|
+
allowNull: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
sequelize,
|
|
48
|
+
modelName: "DobitUserOTP",
|
|
49
|
+
tableName: "DobitUserOTPs",
|
|
50
|
+
timestamps: true,
|
|
51
|
+
paranoid: false,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
DobitUserOTP.removeAttribute("id");
|
|
56
|
+
return DobitUserOTP;
|
|
57
|
+
};
|