ojamoto_models 1.0.6 → 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 CHANGED
@@ -17,36 +17,36 @@ module.exports = {
17
17
  },
18
18
  define: {
19
19
  underscored: true,
20
- Charset: "utf8mb4",
21
- Collate: "utf8mb4_general_ci",
20
+ charset: "utf8mb4",
21
+ collate: "utf8mb4_general_ci",
22
22
  },
23
23
  },
24
24
 
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
- // },
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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ojamoto_models",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -118,6 +118,7 @@ module.exports = {
118
118
  COMPLETED: "COMPLETED",
119
119
  DISPUTED: "DISPUTED",
120
120
  CANCELLED: "CANCELLED",
121
+ REJECTED: "REJECTED",
121
122
  },
122
123
 
123
124
  // - disputes.reason ──────────────────────────────────────────────────────