ojamoto_models 1.0.6 → 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/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,29 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ const tableDescription = await queryInterface.describeTable("admin_users");
6
+
7
+ if (!tableDescription.country_calling_code) {
8
+ await queryInterface.addColumn("admin_users", "country_calling_code", {
9
+ type: Sequelize.STRING,
10
+ allowNull: true,
11
+ after: "phone",
12
+ });
13
+ }
14
+
15
+ await queryInterface.changeColumn("admin_users", "phone", {
16
+ type: Sequelize.STRING(10),
17
+ allowNull: false,
18
+ });
19
+ },
20
+
21
+ down: async (queryInterface) => {
22
+ await queryInterface.changeColumn("admin_users", "phone", {
23
+ type: Sequelize.STRING(20),
24
+ allowNull: false,
25
+ });
26
+
27
+ await queryInterface.removeColumn("admin_users", "country_calling_code");
28
+ },
29
+ };
@@ -71,10 +71,14 @@ module.exports = (sequelize) => {
71
71
  validate: { isEmail: true },
72
72
  },
73
73
  phone: {
74
- type: DataTypes.STRING(20),
74
+ type: DataTypes.STRING(10),
75
75
  allowNull: false,
76
76
  unique: true,
77
77
  },
78
+ country_calling_code: {
79
+ type: DataTypes.STRING(3),
80
+ allowNull: false,
81
+ },
78
82
  password_hash: {
79
83
  type: DataTypes.STRING(255),
80
84
  allowNull: false,
@@ -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.8",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -22,6 +22,8 @@
22
22
  "homepage": "https://github.com/ojamoto/ojamoto_models#readme",
23
23
  "description": "",
24
24
  "dependencies": {
25
+ "bcrypt": "^6.0.0",
26
+ "crypto": "^1.0.1",
25
27
  "dotenv": "^17.4.2",
26
28
  "mysql2": "^3.23.2",
27
29
  "sequelize": "^6.37.8",
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ const bcrypt = require("bcrypt");
4
+ const crypto = require("crypto");
5
+ const { ADMIN_ROLE, ADMIN_STATUS } = require("../services/constants");
6
+
7
+ module.exports = {
8
+ async up(queryInterface) {
9
+ const email = process.env.SUPER_ADMIN_EMAIL;
10
+ const tempPassword = process.env.SUPER_ADMIN_TEMP_PASSWORD;
11
+
12
+ if (!email || !tempPassword) {
13
+ throw new Error(
14
+ "SUPER_ADMIN_EMAIL and SUPER_ADMIN_TEMP_PASSWORD must be set in your environment before running this seeder",
15
+ );
16
+ }
17
+
18
+ const existing = await queryInterface.sequelize.query(
19
+ `SELECT admin_id FROM admin_users WHERE email = :email LIMIT 1`,
20
+ {
21
+ replacements: { email },
22
+ type: queryInterface.sequelize.QueryTypes.SELECT,
23
+ },
24
+ );
25
+
26
+ if (existing.length > 0) {
27
+ console.log("Super admin already exists — skipping seed");
28
+ return;
29
+ }
30
+
31
+ const password_hash = await bcrypt.hash(tempPassword, 12);
32
+
33
+ await queryInterface.bulkInsert("admin_users", [
34
+ {
35
+ uuid: crypto.randomUUID(),
36
+ first_name: process.env.SUPER_ADMIN_FIRST_NAME || "Super",
37
+ last_name: process.env.SUPER_ADMIN_LAST_NAME || "Admin",
38
+ email,
39
+ phone: process.env.SUPER_ADMIN_PHONE || "8085202397",
40
+ country_calling_code:
41
+ process.env.SUPER_ADMIN_COUNTRY_CALLING_CODE || "234",
42
+ password_hash,
43
+ must_change_password: true,
44
+ role: ADMIN_ROLE.SUPER_ADMIN,
45
+ status: ADMIN_STATUS.ACTIVE,
46
+ two_factor_enabled: true,
47
+ totp_secret: null,
48
+ created_by: null,
49
+ created_at: new Date(),
50
+ updated_at: new Date(),
51
+ },
52
+ ]);
53
+ },
54
+
55
+ async down(queryInterface) {
56
+ const email = process.env.SUPER_ADMIN_EMAIL;
57
+ if (!email) return;
58
+
59
+ await queryInterface.bulkDelete("admin_users", { email });
60
+ },
61
+ };
@@ -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 ──────────────────────────────────────────────────────