ojamoto_models 1.0.5 → 1.0.7
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/config/config.js +29 -29
- package/migrations/2026000039-update-status-on-wallet-transaction.js +21 -0
- package/migrations/2026000040-add-product-availability-reminder.js +54 -0
- package/migrations/2026000041-update-status-on-escrow.js +30 -0
- package/migrations/2026000042-create-platform-wallet.js +46 -0
- package/migrations/2026000043-create-platform-income.js +48 -0
- package/models/PlatformIncome.js +64 -0
- package/models/PlatformWallet.js +45 -0
- package/models/Product.js +5 -0
- package/models/ProductAvailabilityReminder.js +52 -0
- package/package.json +1 -1
- package/services/constants.js +2 -0
package/config/config.js
CHANGED
|
@@ -17,36 +17,36 @@ module.exports = {
|
|
|
17
17
|
},
|
|
18
18
|
define: {
|
|
19
19
|
underscored: true,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
charset: "utf8mb4",
|
|
21
|
+
collate: "utf8mb4_general_ci",
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
production: {
|
|
26
|
+
username: process.env.AWS_DB_USERNAME,
|
|
27
|
+
password: process.env.AWS_DB_PASSWORD,
|
|
28
|
+
database: process.env.AWS_DB_NAME,
|
|
29
|
+
host: process.env.AWS_DB_HOST,
|
|
30
|
+
dialect: "mysql",
|
|
31
|
+
dialectOptions: {
|
|
32
|
+
ssl: {
|
|
33
|
+
require: true,
|
|
34
|
+
rejectUnauthorized: false,
|
|
35
|
+
ca: fs.readFileSync(
|
|
36
|
+
path.join(__dirname, "../certificates/global-bundle.pem"),
|
|
37
|
+
),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
pool: {
|
|
41
|
+
max: 5,
|
|
42
|
+
min: 0,
|
|
43
|
+
acquire: 30000,
|
|
44
|
+
idle: 10000,
|
|
45
|
+
},
|
|
46
|
+
define: {
|
|
47
|
+
underscored: true,
|
|
48
|
+
charset: "utf8mb4",
|
|
49
|
+
collate: "utf8mb4_general_ci",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
52
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { WALLET_TRANSACTION_STATUS } = require("../services/constants");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
async up(queryInterface, Sequelize) {
|
|
7
|
+
await queryInterface.changeColumn("wallet_transactions", "status", {
|
|
8
|
+
type: Sequelize.ENUM(...Object.values(WALLET_TRANSACTION_STATUS)),
|
|
9
|
+
allowNull: false,
|
|
10
|
+
defaultValue: WALLET_TRANSACTION_STATUS.PENDING,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
async down(queryInterface, Sequelize) {
|
|
15
|
+
await queryInterface.changeColumn("wallet_transactions", "status", {
|
|
16
|
+
type: Sequelize.ENUM("PENDING", "SUCCESS", "FAILED"),
|
|
17
|
+
allowNull: false,
|
|
18
|
+
defaultValue: "PENDING",
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("product_availability_reminders", {
|
|
6
|
+
product_availability_reminder_id: {
|
|
7
|
+
type: Sequelize.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true,
|
|
10
|
+
allowNull: false,
|
|
11
|
+
},
|
|
12
|
+
product_id: {
|
|
13
|
+
type: Sequelize.INTEGER,
|
|
14
|
+
allowNull: false,
|
|
15
|
+
references: { model: "products", key: "product_id" },
|
|
16
|
+
onDelete: "CASCADE",
|
|
17
|
+
onUpdate: "CASCADE",
|
|
18
|
+
},
|
|
19
|
+
email: {
|
|
20
|
+
type: Sequelize.STRING(255),
|
|
21
|
+
allowNull: false,
|
|
22
|
+
},
|
|
23
|
+
notified_at: {
|
|
24
|
+
type: Sequelize.DATE,
|
|
25
|
+
allowNull: true,
|
|
26
|
+
},
|
|
27
|
+
created_at: {
|
|
28
|
+
type: Sequelize.DATE,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await queryInterface.addIndex("product_availability_reminders", [
|
|
34
|
+
"product_id",
|
|
35
|
+
]);
|
|
36
|
+
await queryInterface.addIndex("product_availability_reminders", [
|
|
37
|
+
"product_id",
|
|
38
|
+
"notified_at",
|
|
39
|
+
]);
|
|
40
|
+
// One reminder per email per product — no duplicate sign-ups
|
|
41
|
+
await queryInterface.addIndex(
|
|
42
|
+
"product_availability_reminders",
|
|
43
|
+
["product_id", "email"],
|
|
44
|
+
{
|
|
45
|
+
unique: true,
|
|
46
|
+
name: "product_availability_reminders_product_email_unique",
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
async down(queryInterface) {
|
|
52
|
+
await queryInterface.dropTable("product_availability_reminders");
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ESCROW_STATUS } = require("../services/constants");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
async up(queryInterface, Sequelize) {
|
|
7
|
+
await queryInterface.changeColumn("escrows", "status", {
|
|
8
|
+
type: Sequelize.ENUM(...Object.values(ESCROW_STATUS)),
|
|
9
|
+
allowNull: false,
|
|
10
|
+
defaultValue: ESCROW_STATUS.PENDING,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
async down(queryInterface, Sequelize) {
|
|
15
|
+
await queryInterface.changeColumn("escrows", "status", {
|
|
16
|
+
type: Sequelize.ENUM(
|
|
17
|
+
"PENDING",
|
|
18
|
+
"FUNDED",
|
|
19
|
+
"ACCEPTED",
|
|
20
|
+
"IN_PROGRESS",
|
|
21
|
+
"DELIVERED",
|
|
22
|
+
"COMPLETED",
|
|
23
|
+
"DISPUTED",
|
|
24
|
+
"CANCELLED",
|
|
25
|
+
),
|
|
26
|
+
allowNull: false,
|
|
27
|
+
defaultValue: "PENDING",
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("platform_wallets", {
|
|
6
|
+
platform_wallet_id: {
|
|
7
|
+
type: Sequelize.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true,
|
|
10
|
+
allowNull: false,
|
|
11
|
+
},
|
|
12
|
+
available_balance: {
|
|
13
|
+
type: Sequelize.DECIMAL(15, 2),
|
|
14
|
+
allowNull: false,
|
|
15
|
+
defaultValue: 0.0,
|
|
16
|
+
},
|
|
17
|
+
currency: {
|
|
18
|
+
type: Sequelize.STRING(3),
|
|
19
|
+
allowNull: false,
|
|
20
|
+
defaultValue: "NGN",
|
|
21
|
+
},
|
|
22
|
+
created_at: {
|
|
23
|
+
type: Sequelize.DATE,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
},
|
|
26
|
+
updated_at: {
|
|
27
|
+
type: Sequelize.DATE,
|
|
28
|
+
allowNull: false,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Seed the single platform wallet row
|
|
33
|
+
await queryInterface.bulkInsert("platform_wallets", [
|
|
34
|
+
{
|
|
35
|
+
available_balance: 0.0,
|
|
36
|
+
currency: "NGN",
|
|
37
|
+
created_at: new Date(),
|
|
38
|
+
updated_at: new Date(),
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
async down(queryInterface) {
|
|
44
|
+
await queryInterface.dropTable("platform_wallets");
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("platform_incomes", {
|
|
6
|
+
platform_income_id: {
|
|
7
|
+
type: Sequelize.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true,
|
|
10
|
+
allowNull: false,
|
|
11
|
+
},
|
|
12
|
+
platform_wallet_id: {
|
|
13
|
+
type: Sequelize.INTEGER,
|
|
14
|
+
allowNull: false,
|
|
15
|
+
references: { model: "platform_wallets", key: "platform_wallet_id" },
|
|
16
|
+
onDelete: "RESTRICT",
|
|
17
|
+
onUpdate: "CASCADE",
|
|
18
|
+
},
|
|
19
|
+
escrow_id: {
|
|
20
|
+
type: Sequelize.INTEGER,
|
|
21
|
+
allowNull: false,
|
|
22
|
+
unique: true,
|
|
23
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
24
|
+
onDelete: "RESTRICT",
|
|
25
|
+
onUpdate: "CASCADE",
|
|
26
|
+
},
|
|
27
|
+
amount: {
|
|
28
|
+
type: Sequelize.DECIMAL(15, 2),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
},
|
|
31
|
+
currency: {
|
|
32
|
+
type: Sequelize.STRING(3),
|
|
33
|
+
allowNull: false,
|
|
34
|
+
defaultValue: "NGN",
|
|
35
|
+
},
|
|
36
|
+
created_at: {
|
|
37
|
+
type: Sequelize.DATE,
|
|
38
|
+
allowNull: false,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await queryInterface.addIndex("platform_incomes", ["platform_wallet_id"]);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
async down(queryInterface) {
|
|
46
|
+
await queryInterface.dropTable("platform_incomes");
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class PlatformIncome extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
PlatformIncome.belongsTo(models.Escrow, {
|
|
9
|
+
foreignKey: "escrow_id",
|
|
10
|
+
as: "escrow",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
PlatformIncome.belongsTo(models.PlatformWallet, {
|
|
14
|
+
foreignKey: "platform_wallet_id",
|
|
15
|
+
as: "platformWallet",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
PlatformIncome.init(
|
|
21
|
+
{
|
|
22
|
+
platform_income_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
primaryKey: true,
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
},
|
|
27
|
+
platform_wallet_id: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
references: { model: "platform_wallets", key: "platform_wallet_id" },
|
|
31
|
+
onDelete: "RESTRICT",
|
|
32
|
+
},
|
|
33
|
+
escrow_id: {
|
|
34
|
+
type: DataTypes.INTEGER,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
unique: true, // one fee record per escrow — prevents double-crediting the same escrow
|
|
37
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
38
|
+
onDelete: "RESTRICT",
|
|
39
|
+
},
|
|
40
|
+
amount: {
|
|
41
|
+
type: DataTypes.DECIMAL(15, 2),
|
|
42
|
+
allowNull: false,
|
|
43
|
+
comment:
|
|
44
|
+
"The platform_fee earned from this specific escrow — immutable record",
|
|
45
|
+
},
|
|
46
|
+
currency: {
|
|
47
|
+
type: DataTypes.STRING(3),
|
|
48
|
+
allowNull: false,
|
|
49
|
+
defaultValue: "NGN",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
sequelize,
|
|
54
|
+
modelName: "PlatformIncome",
|
|
55
|
+
tableName: "platform_incomes",
|
|
56
|
+
timestamps: true,
|
|
57
|
+
createdAt: "created_at",
|
|
58
|
+
updatedAt: false,
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
PlatformIncome.removeAttribute("id");
|
|
63
|
+
return PlatformIncome;
|
|
64
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class PlatformWallet extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
PlatformWallet.hasMany(models.PlatformIncome, {
|
|
9
|
+
foreignKey: "platform_wallet_id",
|
|
10
|
+
as: "incomeRecords",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
PlatformWallet.init(
|
|
16
|
+
{
|
|
17
|
+
platform_wallet_id: {
|
|
18
|
+
type: DataTypes.INTEGER,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
},
|
|
22
|
+
available_balance: {
|
|
23
|
+
type: DataTypes.DECIMAL(15, 2),
|
|
24
|
+
allowNull: false,
|
|
25
|
+
defaultValue: 0.0,
|
|
26
|
+
},
|
|
27
|
+
currency: {
|
|
28
|
+
type: DataTypes.STRING(3),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
defaultValue: "NGN",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
sequelize,
|
|
35
|
+
modelName: "PlatformWallet",
|
|
36
|
+
tableName: "platform_wallets",
|
|
37
|
+
timestamps: true,
|
|
38
|
+
createdAt: "created_at",
|
|
39
|
+
updatedAt: "updated_at",
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
PlatformWallet.removeAttribute("id");
|
|
44
|
+
return PlatformWallet;
|
|
45
|
+
};
|
package/models/Product.js
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class ProductAvailabilityReminder extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
ProductAvailabilityReminder.belongsTo(models.Product, {
|
|
9
|
+
foreignKey: "product_id",
|
|
10
|
+
as: "product",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ProductAvailabilityReminder.init(
|
|
16
|
+
{
|
|
17
|
+
product_availability_reminder_id: {
|
|
18
|
+
type: DataTypes.INTEGER,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
},
|
|
22
|
+
product_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
references: { model: "products", key: "product_id" },
|
|
26
|
+
onDelete: "CASCADE",
|
|
27
|
+
},
|
|
28
|
+
email: {
|
|
29
|
+
type: DataTypes.STRING(255),
|
|
30
|
+
allowNull: false,
|
|
31
|
+
validate: { isEmail: true },
|
|
32
|
+
},
|
|
33
|
+
notified_at: {
|
|
34
|
+
type: DataTypes.DATE,
|
|
35
|
+
allowNull: true,
|
|
36
|
+
comment:
|
|
37
|
+
"Set once the restock email has been sent — prevents duplicate notifications",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
sequelize,
|
|
42
|
+
modelName: "ProductAvailabilityReminder",
|
|
43
|
+
tableName: "product_availability_reminders",
|
|
44
|
+
timestamps: true,
|
|
45
|
+
createdAt: "created_at",
|
|
46
|
+
updatedAt: false,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
ProductAvailabilityReminder.removeAttribute("id");
|
|
51
|
+
return ProductAvailabilityReminder;
|
|
52
|
+
};
|
package/package.json
CHANGED
package/services/constants.js
CHANGED
|
@@ -105,6 +105,7 @@ module.exports = {
|
|
|
105
105
|
PENDING: "PENDING",
|
|
106
106
|
SUCCESS: "SUCCESS",
|
|
107
107
|
FAILED: "FAILED",
|
|
108
|
+
EXPIRED: "EXPIRED",
|
|
108
109
|
},
|
|
109
110
|
|
|
110
111
|
// - escrows.status ───────────────────────────────────────────────────────
|
|
@@ -117,6 +118,7 @@ module.exports = {
|
|
|
117
118
|
COMPLETED: "COMPLETED",
|
|
118
119
|
DISPUTED: "DISPUTED",
|
|
119
120
|
CANCELLED: "CANCELLED",
|
|
121
|
+
REJECTED: "REJECTED",
|
|
120
122
|
},
|
|
121
123
|
|
|
122
124
|
// - disputes.reason ──────────────────────────────────────────────────────
|