ojamoto_models 1.0.0
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/.vscode/settings.json +3 -0
- package/LICENSE +21 -0
- package/certificates/global-bundle.pem +2736 -0
- package/config/config.js +52 -0
- package/index.js +3 -0
- package/migrations/2026000001-create-users.js +97 -0
- package/migrations/2026000002-create-and-seed-roles.js +43 -0
- package/migrations/2026000003-create-admin-users.js +83 -0
- package/migrations/2026000004-create-devices.js +67 -0
- package/migrations/2026000005-create-products.js +87 -0
- package/migrations/2026000006-create-addresses.js +74 -0
- package/migrations/2026000007-create-wallets.js +44 -0
- package/migrations/2026000008-create-kyc-verification.js +51 -0
- package/migrations/2026000009-create-seller-profiles.js +80 -0
- package/migrations/2026000010-create-user-roles.js +48 -0
- package/migrations/2026000011-create-sessions.js +61 -0
- package/migrations/2026000012-create-escrows.js +80 -0
- package/migrations/2026000013-create-wallet-transactions.js +70 -0
- package/migrations/2026000014-create-product-images.js +43 -0
- package/migrations/2026000015-create-escrow-events.js +50 -0
- package/migrations/2026000016-create-logistics.js +55 -0
- package/migrations/2026000017-create-ratings.js +56 -0
- package/migrations/2026000018-create-disputes.js +84 -0
- package/migrations/2026000019-create-dispute-evidence.js +50 -0
- package/migrations/2026000020-create-dispute-messages.js +44 -0
- package/migrations/2026000021-create-notifications.js +50 -0
- package/migrations/2026000022-create-audit-logs.js +57 -0
- package/migrations/2026000023-create-webhook-logs.js +46 -0
- package/migrations/2026000024-create-user-otps.js +75 -0
- package/migrations/2026000025-create-password-reset-otps.js +43 -0
- package/migrations/2026000026-create-seller-badges.js +43 -0
- package/migrations/2026000027-add-fulltext-index-for-search.js +15 -0
- package/migrations/2026000028-create-admin-notifications.js +53 -0
- package/migrations/2026000029-create-pin-reset-otp.js +30 -0
- package/models/Address.js +76 -0
- package/models/AdminNotification.js +59 -0
- package/models/AdminUser.js +115 -0
- package/models/AuditLog.js +70 -0
- package/models/Device.js +82 -0
- package/models/Dispute.js +109 -0
- package/models/DisputeEvidence.js +62 -0
- package/models/DisputeMessage.js +57 -0
- package/models/Escrow.js +110 -0
- package/models/EscrowEvent.js +63 -0
- package/models/KycVerification.js +62 -0
- package/models/Logistics.js +62 -0
- package/models/Notification.js +58 -0
- package/models/PasswordResetOTP.js +52 -0
- package/models/PinResetOTP.js +48 -0
- package/models/Product.js +100 -0
- package/models/ProductImage.js +54 -0
- package/models/Rating.js +74 -0
- package/models/Role.js +43 -0
- package/models/SellerBadges.js +45 -0
- package/models/SellerProfile.js +92 -0
- package/models/Session.js +67 -0
- package/models/User.js +198 -0
- package/models/UserOTP.js +84 -0
- package/models/UserRole.js +42 -0
- package/models/Wallet.js +63 -0
- package/models/WalletTransaction.js +81 -0
- package/models/WebhookLog.js +52 -0
- package/models/index.js +23 -0
- package/package.json +30 -0
- package/services/constants.js +162 -0
package/models/Device.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class Device extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
Device.belongsTo(models.User, {
|
|
9
|
+
foreignKey: "user_id",
|
|
10
|
+
as: "user",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
Device.hasMany(models.Session, {
|
|
14
|
+
foreignKey: "device_id",
|
|
15
|
+
as: "sessions",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Device.init(
|
|
21
|
+
{
|
|
22
|
+
device_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
primaryKey: true,
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
},
|
|
27
|
+
user_id: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
references: { model: "users", key: "user_id" },
|
|
31
|
+
onDelete: "CASCADE",
|
|
32
|
+
},
|
|
33
|
+
device_name: {
|
|
34
|
+
type: DataTypes.STRING(100),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
device_type: {
|
|
38
|
+
type: DataTypes.STRING(50),
|
|
39
|
+
allowNull: false,
|
|
40
|
+
comment: "mobile | desktop | tablet",
|
|
41
|
+
},
|
|
42
|
+
user_device_id: {
|
|
43
|
+
type: DataTypes.STRING(100),
|
|
44
|
+
allowNull: false,
|
|
45
|
+
},
|
|
46
|
+
push_notification_id: {
|
|
47
|
+
type: DataTypes.STRING(100),
|
|
48
|
+
allowNull: false,
|
|
49
|
+
},
|
|
50
|
+
browser: {
|
|
51
|
+
type: DataTypes.STRING(100),
|
|
52
|
+
allowNull: true,
|
|
53
|
+
},
|
|
54
|
+
ip_address: {
|
|
55
|
+
type: DataTypes.STRING(45),
|
|
56
|
+
allowNull: false,
|
|
57
|
+
comment: "IPv4 or IPv6",
|
|
58
|
+
},
|
|
59
|
+
location: {
|
|
60
|
+
type: DataTypes.STRING(500),
|
|
61
|
+
allowNull: false,
|
|
62
|
+
comment: "City, Country",
|
|
63
|
+
},
|
|
64
|
+
trusted: {
|
|
65
|
+
type: DataTypes.BOOLEAN,
|
|
66
|
+
defaultValue: false,
|
|
67
|
+
comment: "User-approved device",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
sequelize,
|
|
72
|
+
modelName: "Device",
|
|
73
|
+
tableName: "devices",
|
|
74
|
+
timestamps: true,
|
|
75
|
+
createdAt: "created_at",
|
|
76
|
+
updatedAt: false,
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
Device.removeAttribute("id");
|
|
81
|
+
return Device;
|
|
82
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const {
|
|
5
|
+
DISPUTE_REASON,
|
|
6
|
+
DISPUTE_STATUS,
|
|
7
|
+
DISPUTE_RESOLUTION,
|
|
8
|
+
} = require("../services/constants");
|
|
9
|
+
|
|
10
|
+
module.exports = (sequelize) => {
|
|
11
|
+
class Dispute extends Model {
|
|
12
|
+
static associate(models) {
|
|
13
|
+
Dispute.belongsTo(models.Escrow, {
|
|
14
|
+
foreignKey: "escrow_id",
|
|
15
|
+
as: "escrow",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
Dispute.belongsTo(models.User, {
|
|
19
|
+
foreignKey: "opened_by",
|
|
20
|
+
as: "opener",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// assigned_admin references admin_users, not users
|
|
24
|
+
Dispute.belongsTo(models.AdminUser, {
|
|
25
|
+
foreignKey: "assigned_admin",
|
|
26
|
+
as: "assignedAdmin",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Dispute.hasMany(models.DisputeEvidence, {
|
|
30
|
+
foreignKey: "dispute_id",
|
|
31
|
+
as: "evidence",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
Dispute.hasMany(models.DisputeMessage, {
|
|
35
|
+
foreignKey: "dispute_id",
|
|
36
|
+
as: "messages",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Dispute.init(
|
|
42
|
+
{
|
|
43
|
+
dispute_id: {
|
|
44
|
+
type: DataTypes.INTEGER,
|
|
45
|
+
primaryKey: true,
|
|
46
|
+
autoIncrement: true,
|
|
47
|
+
},
|
|
48
|
+
escrow_id: {
|
|
49
|
+
type: DataTypes.INTEGER,
|
|
50
|
+
allowNull: false,
|
|
51
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
52
|
+
onDelete: "RESTRICT",
|
|
53
|
+
},
|
|
54
|
+
opened_by: {
|
|
55
|
+
type: DataTypes.INTEGER,
|
|
56
|
+
allowNull: false,
|
|
57
|
+
references: { model: "users", key: "user_id" },
|
|
58
|
+
onDelete: "RESTRICT",
|
|
59
|
+
comment: "Buyer or seller who opened the dispute",
|
|
60
|
+
},
|
|
61
|
+
reason: {
|
|
62
|
+
type: DataTypes.ENUM(...Object.values(DISPUTE_REASON)),
|
|
63
|
+
allowNull: false,
|
|
64
|
+
},
|
|
65
|
+
description: {
|
|
66
|
+
type: DataTypes.TEXT,
|
|
67
|
+
allowNull: false,
|
|
68
|
+
comment: "Buyer/seller's initial explanation when opening the dispute",
|
|
69
|
+
},
|
|
70
|
+
assigned_admin: {
|
|
71
|
+
type: DataTypes.INTEGER,
|
|
72
|
+
allowNull: true,
|
|
73
|
+
references: { model: "admin_users", key: "admin_id" },
|
|
74
|
+
onDelete: "SET NULL",
|
|
75
|
+
comment: "NULL until assigned by super admin",
|
|
76
|
+
},
|
|
77
|
+
status: {
|
|
78
|
+
type: DataTypes.ENUM(...Object.values(DISPUTE_STATUS)),
|
|
79
|
+
allowNull: false,
|
|
80
|
+
defaultValue: DISPUTE_STATUS.OPEN,
|
|
81
|
+
},
|
|
82
|
+
resolution: {
|
|
83
|
+
type: DataTypes.ENUM(...Object.values(DISPUTE_RESOLUTION)),
|
|
84
|
+
allowNull: true,
|
|
85
|
+
defaultValue: null,
|
|
86
|
+
},
|
|
87
|
+
resolution_note: {
|
|
88
|
+
type: DataTypes.TEXT,
|
|
89
|
+
allowNull: true,
|
|
90
|
+
comment: "Admin explanation of decision",
|
|
91
|
+
},
|
|
92
|
+
resolved_at: {
|
|
93
|
+
type: DataTypes.DATE,
|
|
94
|
+
allowNull: true,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
sequelize,
|
|
99
|
+
modelName: "Dispute",
|
|
100
|
+
tableName: "disputes",
|
|
101
|
+
timestamps: true,
|
|
102
|
+
createdAt: "created_at",
|
|
103
|
+
updatedAt: false,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
Dispute.removeAttribute("id");
|
|
108
|
+
return Dispute;
|
|
109
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { EVIDENCE_FILE_TYPE } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class DisputeEvidence extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
DisputeEvidence.belongsTo(models.Dispute, {
|
|
10
|
+
foreignKey: "dispute_id",
|
|
11
|
+
as: "dispute",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
DisputeEvidence.belongsTo(models.User, {
|
|
15
|
+
foreignKey: "uploaded_by",
|
|
16
|
+
as: "uploader",
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
DisputeEvidence.init(
|
|
22
|
+
{
|
|
23
|
+
dispute_evidence_id: {
|
|
24
|
+
type: DataTypes.INTEGER,
|
|
25
|
+
primaryKey: true,
|
|
26
|
+
autoIncrement: true,
|
|
27
|
+
},
|
|
28
|
+
dispute_id: {
|
|
29
|
+
type: DataTypes.INTEGER,
|
|
30
|
+
allowNull: false,
|
|
31
|
+
references: { model: "disputes", key: "dispute_id" },
|
|
32
|
+
onDelete: "CASCADE",
|
|
33
|
+
},
|
|
34
|
+
uploaded_by: {
|
|
35
|
+
type: DataTypes.INTEGER,
|
|
36
|
+
allowNull: false,
|
|
37
|
+
references: { model: "users", key: "user_id" },
|
|
38
|
+
onDelete: "RESTRICT",
|
|
39
|
+
},
|
|
40
|
+
file_url: {
|
|
41
|
+
type: DataTypes.STRING(500),
|
|
42
|
+
allowNull: false,
|
|
43
|
+
comment: "AWS S3 URL",
|
|
44
|
+
},
|
|
45
|
+
file_type: {
|
|
46
|
+
type: DataTypes.ENUM(...Object.values(EVIDENCE_FILE_TYPE)),
|
|
47
|
+
allowNull: false,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
sequelize,
|
|
52
|
+
modelName: "DisputeEvidence",
|
|
53
|
+
tableName: "dispute_evidence",
|
|
54
|
+
timestamps: true,
|
|
55
|
+
createdAt: "created_at",
|
|
56
|
+
updatedAt: false,
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
DisputeEvidence.removeAttribute("id");
|
|
61
|
+
return DisputeEvidence;
|
|
62
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class DisputeMessage extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
DisputeMessage.belongsTo(models.Dispute, {
|
|
9
|
+
foreignKey: "dispute_id",
|
|
10
|
+
as: "dispute",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
DisputeMessage.belongsTo(models.User, {
|
|
14
|
+
foreignKey: "sender_id",
|
|
15
|
+
as: "sender",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
DisputeMessage.init(
|
|
21
|
+
{
|
|
22
|
+
dispute_message_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
primaryKey: true,
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
},
|
|
27
|
+
dispute_id: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
references: { model: "disputes", key: "dispute_id" },
|
|
31
|
+
onDelete: "CASCADE",
|
|
32
|
+
},
|
|
33
|
+
sender_id: {
|
|
34
|
+
type: DataTypes.INTEGER,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
references: { model: "users", key: "user_id" },
|
|
37
|
+
onDelete: "RESTRICT",
|
|
38
|
+
comment: "Buyer or seller user id",
|
|
39
|
+
},
|
|
40
|
+
message: {
|
|
41
|
+
type: DataTypes.TEXT,
|
|
42
|
+
allowNull: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
sequelize,
|
|
47
|
+
modelName: "DisputeMessage",
|
|
48
|
+
tableName: "dispute_messages",
|
|
49
|
+
timestamps: true,
|
|
50
|
+
createdAt: "created_at",
|
|
51
|
+
updatedAt: false,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
DisputeMessage.removeAttribute("id");
|
|
56
|
+
return DisputeMessage;
|
|
57
|
+
};
|
package/models/Escrow.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { ESCROW_STATUS } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class Escrow extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
Escrow.belongsTo(models.User, {
|
|
10
|
+
foreignKey: "buyer_id",
|
|
11
|
+
as: "buyer",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
Escrow.belongsTo(models.User, {
|
|
15
|
+
foreignKey: "seller_id",
|
|
16
|
+
as: "seller",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
Escrow.belongsTo(models.Product, {
|
|
20
|
+
foreignKey: "product_id",
|
|
21
|
+
as: "product",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
Escrow.hasMany(models.EscrowEvent, {
|
|
25
|
+
foreignKey: "escrow_id",
|
|
26
|
+
as: "events",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Escrow.hasOne(models.Dispute, {
|
|
30
|
+
foreignKey: "escrow_id",
|
|
31
|
+
as: "dispute",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
Escrow.hasOne(models.Logistics, {
|
|
35
|
+
foreignKey: "escrow_id",
|
|
36
|
+
as: "logistics",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
Escrow.hasOne(models.Rating, {
|
|
40
|
+
foreignKey: "escrow_id",
|
|
41
|
+
as: "rating",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Escrow.init(
|
|
47
|
+
{
|
|
48
|
+
escrow_id: {
|
|
49
|
+
type: DataTypes.INTEGER,
|
|
50
|
+
primaryKey: true,
|
|
51
|
+
autoIncrement: true,
|
|
52
|
+
},
|
|
53
|
+
buyer_id: {
|
|
54
|
+
type: DataTypes.INTEGER,
|
|
55
|
+
allowNull: false,
|
|
56
|
+
references: { model: "users", key: "user_id" },
|
|
57
|
+
onDelete: "RESTRICT",
|
|
58
|
+
},
|
|
59
|
+
seller_id: {
|
|
60
|
+
type: DataTypes.INTEGER,
|
|
61
|
+
allowNull: false,
|
|
62
|
+
references: { model: "users", key: "user_id" },
|
|
63
|
+
onDelete: "RESTRICT",
|
|
64
|
+
},
|
|
65
|
+
product_id: {
|
|
66
|
+
type: DataTypes.INTEGER,
|
|
67
|
+
allowNull: false,
|
|
68
|
+
references: { model: "products", key: "product_id" },
|
|
69
|
+
onDelete: "RESTRICT",
|
|
70
|
+
},
|
|
71
|
+
amount: {
|
|
72
|
+
type: DataTypes.DECIMAL(15, 2),
|
|
73
|
+
allowNull: false,
|
|
74
|
+
comment: "Agreed transaction value",
|
|
75
|
+
},
|
|
76
|
+
platform_fee: {
|
|
77
|
+
type: DataTypes.DECIMAL(15, 2),
|
|
78
|
+
allowNull: false,
|
|
79
|
+
defaultValue: 0.0,
|
|
80
|
+
comment: "AutoParts NG escrow fee",
|
|
81
|
+
},
|
|
82
|
+
currency: {
|
|
83
|
+
type: DataTypes.STRING(3),
|
|
84
|
+
allowNull: false,
|
|
85
|
+
defaultValue: "NGN",
|
|
86
|
+
},
|
|
87
|
+
status: {
|
|
88
|
+
type: DataTypes.ENUM(...Object.values(ESCROW_STATUS)),
|
|
89
|
+
allowNull: false,
|
|
90
|
+
defaultValue: ESCROW_STATUS.PENDING,
|
|
91
|
+
},
|
|
92
|
+
delivery_deadline: {
|
|
93
|
+
type: DataTypes.DATEONLY,
|
|
94
|
+
allowNull: true,
|
|
95
|
+
comment: "Auto-release trigger date if buyer does not confirm",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
sequelize,
|
|
100
|
+
modelName: "Escrow",
|
|
101
|
+
tableName: "escrows",
|
|
102
|
+
timestamps: true,
|
|
103
|
+
createdAt: "created_at",
|
|
104
|
+
updatedAt: "updated_at",
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
Escrow.removeAttribute("id");
|
|
109
|
+
return Escrow;
|
|
110
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class EscrowEvent extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
EscrowEvent.belongsTo(models.Escrow, {
|
|
9
|
+
foreignKey: "escrow_id",
|
|
10
|
+
as: "escrow",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
EscrowEvent.belongsTo(models.User, {
|
|
14
|
+
foreignKey: "created_by",
|
|
15
|
+
as: "actor",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
EscrowEvent.init(
|
|
21
|
+
{
|
|
22
|
+
escrow_event_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
primaryKey: true,
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
},
|
|
27
|
+
escrow_id: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
31
|
+
onDelete: "CASCADE",
|
|
32
|
+
},
|
|
33
|
+
event_type: {
|
|
34
|
+
type: DataTypes.STRING(100),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
comment: "FUNDED | ACCEPTED | DELIVERED | RELEASED etc.",
|
|
37
|
+
},
|
|
38
|
+
description: {
|
|
39
|
+
type: DataTypes.TEXT,
|
|
40
|
+
allowNull: true,
|
|
41
|
+
comment: "Human-readable event detail",
|
|
42
|
+
},
|
|
43
|
+
created_by: {
|
|
44
|
+
type: DataTypes.INTEGER,
|
|
45
|
+
allowNull: true,
|
|
46
|
+
references: { model: "users", key: "user_id" },
|
|
47
|
+
onDelete: "SET NULL",
|
|
48
|
+
comment: "User or system actor (null = system)",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
sequelize,
|
|
53
|
+
modelName: "EscrowEvent",
|
|
54
|
+
tableName: "escrow_events",
|
|
55
|
+
timestamps: true,
|
|
56
|
+
createdAt: "created_at",
|
|
57
|
+
updatedAt: false,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
EscrowEvent.removeAttribute("id");
|
|
62
|
+
return EscrowEvent;
|
|
63
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { KYC_STATUS, KYC_PROVIDER } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class KycVerification extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
KycVerification.belongsTo(models.User, {
|
|
10
|
+
foreignKey: "user_id",
|
|
11
|
+
as: "user",
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
KycVerification.init(
|
|
17
|
+
{
|
|
18
|
+
kyc_verification_id: {
|
|
19
|
+
type: DataTypes.INTEGER,
|
|
20
|
+
primaryKey: true,
|
|
21
|
+
autoIncrement: true,
|
|
22
|
+
},
|
|
23
|
+
user_id: {
|
|
24
|
+
type: DataTypes.INTEGER,
|
|
25
|
+
allowNull: false,
|
|
26
|
+
unique: true,
|
|
27
|
+
references: { model: "users", key: "user_id" },
|
|
28
|
+
onDelete: "CASCADE",
|
|
29
|
+
},
|
|
30
|
+
nin_data_json: {
|
|
31
|
+
type: DataTypes.JSON,
|
|
32
|
+
allowNull: true,
|
|
33
|
+
comment: "Raw NIN API response from provider",
|
|
34
|
+
},
|
|
35
|
+
bank_data_json: {
|
|
36
|
+
type: DataTypes.JSON,
|
|
37
|
+
allowNull: true,
|
|
38
|
+
comment: "Resolved account name and bank details",
|
|
39
|
+
},
|
|
40
|
+
verification_status: {
|
|
41
|
+
type: DataTypes.ENUM(...Object.values(KYC_STATUS)),
|
|
42
|
+
allowNull: false,
|
|
43
|
+
defaultValue: KYC_STATUS.PENDING,
|
|
44
|
+
},
|
|
45
|
+
provider: {
|
|
46
|
+
type: DataTypes.ENUM(...Object.values(KYC_PROVIDER)),
|
|
47
|
+
allowNull: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
sequelize,
|
|
52
|
+
modelName: "KycVerification",
|
|
53
|
+
tableName: "kyc_verifications",
|
|
54
|
+
timestamps: true,
|
|
55
|
+
createdAt: "created_at",
|
|
56
|
+
updatedAt: false,
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
KycVerification.removeAttribute("id");
|
|
61
|
+
return KycVerification;
|
|
62
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { LOGISTICS_STATUS } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class Logistics extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
Logistics.belongsTo(models.Escrow, {
|
|
10
|
+
foreignKey: "escrow_id",
|
|
11
|
+
as: "escrow",
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Logistics.init(
|
|
17
|
+
{
|
|
18
|
+
logistics_id: {
|
|
19
|
+
type: DataTypes.INTEGER,
|
|
20
|
+
primaryKey: true,
|
|
21
|
+
autoIncrement: true,
|
|
22
|
+
},
|
|
23
|
+
escrow_id: {
|
|
24
|
+
type: DataTypes.INTEGER,
|
|
25
|
+
allowNull: false,
|
|
26
|
+
unique: true,
|
|
27
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
28
|
+
onDelete: "RESTRICT",
|
|
29
|
+
},
|
|
30
|
+
provider: {
|
|
31
|
+
type: DataTypes.STRING(100),
|
|
32
|
+
allowNull: false,
|
|
33
|
+
comment: "GIG | DHL | FedEx",
|
|
34
|
+
},
|
|
35
|
+
tracking_number: {
|
|
36
|
+
type: DataTypes.STRING(100),
|
|
37
|
+
allowNull: false,
|
|
38
|
+
},
|
|
39
|
+
status: {
|
|
40
|
+
type: DataTypes.ENUM(...Object.values(LOGISTICS_STATUS)),
|
|
41
|
+
allowNull: false,
|
|
42
|
+
defaultValue: LOGISTICS_STATUS.SHIPPED,
|
|
43
|
+
},
|
|
44
|
+
delivery_proof_url: {
|
|
45
|
+
type: DataTypes.STRING(500),
|
|
46
|
+
allowNull: true,
|
|
47
|
+
comment: "AWS S3 URL — photo or waybill",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
sequelize,
|
|
52
|
+
modelName: "Logistics",
|
|
53
|
+
tableName: "logistics",
|
|
54
|
+
timestamps: true,
|
|
55
|
+
createdAt: "created_at",
|
|
56
|
+
updatedAt: "updated_at",
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
Logistics.removeAttribute("id");
|
|
61
|
+
return Logistics;
|
|
62
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class Notification extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
Notification.belongsTo(models.User, {
|
|
9
|
+
foreignKey: "user_id",
|
|
10
|
+
as: "user",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Notification.init(
|
|
16
|
+
{
|
|
17
|
+
notification_id: {
|
|
18
|
+
type: DataTypes.INTEGER,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
},
|
|
22
|
+
user_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
references: { model: "users", key: "user_id" },
|
|
26
|
+
onDelete: "CASCADE",
|
|
27
|
+
},
|
|
28
|
+
type: {
|
|
29
|
+
type: DataTypes.STRING(100),
|
|
30
|
+
allowNull: false,
|
|
31
|
+
comment: "ESCROW_FUNDED | PAYMENT_RELEASED | DISPUTE_OPENED etc.",
|
|
32
|
+
},
|
|
33
|
+
title: {
|
|
34
|
+
type: DataTypes.STRING(255),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
message: {
|
|
38
|
+
type: DataTypes.TEXT,
|
|
39
|
+
allowNull: false,
|
|
40
|
+
},
|
|
41
|
+
read_status: {
|
|
42
|
+
type: DataTypes.BOOLEAN,
|
|
43
|
+
defaultValue: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
sequelize,
|
|
48
|
+
modelName: "Notification",
|
|
49
|
+
tableName: "notifications",
|
|
50
|
+
timestamps: true,
|
|
51
|
+
createdAt: "created_at",
|
|
52
|
+
updatedAt: false,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
Notification.removeAttribute("id");
|
|
57
|
+
return Notification;
|
|
58
|
+
};
|