ojamoto_models 1.0.15 → 1.0.17

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.
@@ -0,0 +1,29 @@
1
+ ("use strict");
2
+
3
+ const { PLATFORM_INCOME_SOURCE } = require("../services/constants");
4
+
5
+ module.exports = {
6
+ async up(queryInterface, Sequelize) {
7
+ await queryInterface.addColumn("platform_incomes", "source", {
8
+ type: Sequelize.STRING(20),
9
+ allowNull: true,
10
+ after: "currency",
11
+ comment:
12
+ "Where this income came from: ESCROW_FEE | SUBSCRIPTION | WITHDRAWAL_FEE",
13
+ });
14
+
15
+ await queryInterface.sequelize.query(
16
+ `UPDATE platform_incomes SET source = :source WHERE source IS NULL`,
17
+ { replacements: { source: PLATFORM_INCOME_SOURCE.ESCROW_FEE } },
18
+ );
19
+
20
+ await queryInterface.changeColumn("platform_incomes", "source", {
21
+ type: Sequelize.STRING(20),
22
+ allowNull: false,
23
+ });
24
+ },
25
+
26
+ async down(queryInterface) {
27
+ await queryInterface.removeColumn("platform_incomes", "source");
28
+ },
29
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface) {
5
+ await queryInterface.sequelize.query(`
6
+ ALTER TABLE platform_incomes
7
+ MODIFY COLUMN escrow_id INT NULL;
8
+ `);
9
+ },
10
+
11
+ async down(queryInterface) {
12
+ await queryInterface.sequelize.query(`
13
+ ALTER TABLE platform_incomes
14
+ MODIFY COLUMN escrow_id INT NOT NULL;
15
+ `);
16
+ },
17
+ };
@@ -0,0 +1,34 @@
1
+ ("use strict");
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.addColumn("users", "google_id", {
6
+ type: Sequelize.STRING(255),
7
+ allowNull: true,
8
+ unique: true,
9
+ after: "totp_secret",
10
+ });
11
+
12
+ await queryInterface.addColumn("users", "auth_provider", {
13
+ type: Sequelize.ENUM("LOCAL", "GOOGLE"),
14
+ allowNull: false,
15
+ defaultValue: "LOCAL",
16
+ after: "google_id",
17
+ });
18
+
19
+ await queryInterface.changeColumn("users", "password_hash", {
20
+ type: Sequelize.STRING(255),
21
+ allowNull: true, // Google-only accounts never set one
22
+ after: "auth_provider",
23
+ });
24
+ },
25
+
26
+ async down(queryInterface) {
27
+ await queryInterface.removeColumn("users", "google_id");
28
+ await queryInterface.removeColumn("users", "auth_provider");
29
+ await queryInterface.changeColumn("users", "password_hash", {
30
+ type: Sequelize.STRING(255),
31
+ allowNull: false,
32
+ });
33
+ },
34
+ };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { Model, DataTypes } = require("sequelize");
4
+ const { PLATFORM_INCOME_SOURCE } = require("../services/constants");
4
5
 
5
6
  module.exports = (sequelize) => {
6
7
  class PlatformIncome extends Model {
@@ -32,8 +33,8 @@ module.exports = (sequelize) => {
32
33
  },
33
34
  escrow_id: {
34
35
  type: DataTypes.INTEGER,
35
- allowNull: false,
36
- unique: true, // one fee record per escrow — prevents double-crediting the same escrow
36
+ allowNull: true,
37
+ unique: true, // enforces uniqueness only among non-null values — multiple NULLs (non-escrow income) are allowed
37
38
  references: { model: "escrows", key: "escrow_id" },
38
39
  onDelete: "RESTRICT",
39
40
  },
@@ -48,6 +49,13 @@ module.exports = (sequelize) => {
48
49
  allowNull: false,
49
50
  defaultValue: "NGN",
50
51
  },
52
+ source: {
53
+ type: DataTypes.STRING(20),
54
+ allowNull: false,
55
+ validate: { isIn: [Object.values(PLATFORM_INCOME_SOURCE)] },
56
+ comment:
57
+ "Where this income came from: ESCROW_FEE | SUBSCRIPTION | WITHDRAWAL_FEE",
58
+ },
51
59
  },
52
60
  {
53
61
  sequelize,
package/models/User.js CHANGED
@@ -166,7 +166,7 @@ module.exports = (sequelize) => {
166
166
  },
167
167
  password_hash: {
168
168
  type: DataTypes.STRING(255),
169
- allowNull: false,
169
+ allowNull: true, // Google-only accounts never set one
170
170
  },
171
171
  transaction_pin_hash: {
172
172
  type: DataTypes.STRING(255),
@@ -230,6 +230,16 @@ module.exports = (sequelize) => {
230
230
  type: DataTypes.STRING,
231
231
  allowNull: true,
232
232
  },
233
+ google_id: {
234
+ type: DataTypes.STRING(255),
235
+ allowNull: true,
236
+ unique: true,
237
+ },
238
+ auth_provider: {
239
+ type: DataTypes.ENUM("LOCAL", "GOOGLE"),
240
+ allowNull: false,
241
+ defaultValue: "LOCAL",
242
+ },
233
243
  },
234
244
  {
235
245
  sequelize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ojamoto_models",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -270,6 +270,14 @@ module.exports = {
270
270
  SMS: "SMS",
271
271
  },
272
272
 
273
+ WITHDRAWAL_FEE_FOR_BUYERS: 50,
274
+
275
+ PLATFORM_INCOME_SOURCE: {
276
+ ESCROW_FEE: "ESCROW_FEE",
277
+ SUBSCRIPTION: "SUBSCRIPTION",
278
+ WITHDRAWAL_FEE: "WITHDRAWAL_FEE",
279
+ },
280
+
273
281
  ////////////////////////////////////////////////////
274
282
 
275
283
  // - Generic status IDs (legacy support) ──────────────────────────────────