ojamoto_models 1.0.8 → 1.0.10

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,55 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.addColumn("products", "low_stock_threshold", {
6
+ type: Sequelize.INTEGER,
7
+ allowNull: false,
8
+ defaultValue: 2,
9
+ });
10
+
11
+ await queryInterface.addColumn("products", "units_sold_online", {
12
+ type: Sequelize.INTEGER,
13
+ allowNull: false,
14
+ defaultValue: 0,
15
+ });
16
+
17
+ await queryInterface.addColumn("products", "units_sold_offline", {
18
+ type: Sequelize.INTEGER,
19
+ allowNull: false,
20
+ defaultValue: 0,
21
+ });
22
+
23
+ await queryInterface.addColumn("products", "last_sold_at", {
24
+ type: Sequelize.DATE,
25
+ allowNull: true,
26
+ comment:
27
+ "Set on any real sale (online completion or logged offline sale) — NOT on restock/correction",
28
+ });
29
+
30
+ await queryInterface.addColumn("products", "low_stock_notified_at", {
31
+ type: Sequelize.DATE,
32
+ allowNull: true,
33
+ comment: "Cleared automatically once stock rises back above threshold",
34
+ });
35
+
36
+ await queryInterface.addColumn("products", "revalidation_prompted_at", {
37
+ type: Sequelize.DATE,
38
+ allowNull: true,
39
+ });
40
+ },
41
+
42
+ async down(queryInterface) {
43
+ await queryInterface.removeColumn("products", "low_stock_threshold");
44
+
45
+ await queryInterface.removeColumn("products", "units_sold_online");
46
+
47
+ await queryInterface.removeColumn("products", "units_sold_offline");
48
+
49
+ await queryInterface.removeColumn("products", "last_sold_at");
50
+
51
+ await queryInterface.removeColumn("products", "low_stock_notified_at");
52
+
53
+ await queryInterface.removeColumn("products", "revalidation_prompted_at");
54
+ },
55
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable("stock_adjustments", {
6
+ stock_adjustment_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
+ seller_id: {
20
+ type: Sequelize.INTEGER,
21
+ allowNull: false,
22
+ references: { model: "users", key: "user_id" },
23
+ onDelete: "CASCADE",
24
+ onUpdate: "CASCADE",
25
+ comment: "Denormalized for quick per-seller queries",
26
+ },
27
+ type: {
28
+ type: Sequelize.STRING(50),
29
+ allowNull: false,
30
+ },
31
+ quantity_change: {
32
+ type: Sequelize.INTEGER,
33
+ allowNull: false,
34
+ comment: "Signed — negative for reductions",
35
+ },
36
+ previous_stock: {
37
+ type: Sequelize.INTEGER,
38
+ allowNull: false,
39
+ },
40
+ new_stock: {
41
+ type: Sequelize.INTEGER,
42
+ allowNull: false,
43
+ },
44
+ note: {
45
+ type: Sequelize.TEXT,
46
+ allowNull: true,
47
+ },
48
+ created_at: {
49
+ type: Sequelize.DATE,
50
+ allowNull: false,
51
+ },
52
+ });
53
+
54
+ await queryInterface.addIndex("stock_adjustments", ["product_id"]);
55
+
56
+ await queryInterface.addIndex("stock_adjustments", ["seller_id"]);
57
+ },
58
+
59
+ async down(queryInterface) {
60
+ await queryInterface.dropTable("stock_adjustments");
61
+ },
62
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.addColumn("users", "cac_verified", {
6
+ type: Sequelize.BOOLEAN,
7
+ allowNull: false,
8
+ defaultValue: false,
9
+ after: "nin_verified",
10
+ comment: "Business sellers only",
11
+ });
12
+
13
+ await queryInterface.addColumn("kyc_verifications", "cac_data_json", {
14
+ type: Sequelize.JSON,
15
+ allowNull: true,
16
+ after: "bank_data_json",
17
+ comment: "Raw CAC API response from provider",
18
+ });
19
+
20
+ await queryInterface.addColumn(
21
+ "kyc_verifications",
22
+ "verification_attempts",
23
+ {
24
+ type: Sequelize.INTEGER,
25
+ allowNull: false,
26
+ defaultValue: 0,
27
+ after: "cac_data_json",
28
+ },
29
+ );
30
+ },
31
+ async down(queryInterface) {
32
+ await queryInterface.removeColumn("users", "cac_verified");
33
+ await queryInterface.removeColumn("kyc_verifications", "cac_data_json");
34
+ await queryInterface.removeColumn(
35
+ "kyc_verifications",
36
+ "verification_attempts",
37
+ );
38
+ },
39
+ };
@@ -37,6 +37,15 @@ module.exports = (sequelize) => {
37
37
  allowNull: true,
38
38
  comment: "Resolved account name and bank details",
39
39
  },
40
+ cac_data_json: {
41
+ type: DataTypes.JSON,
42
+ allowNull: true,
43
+ },
44
+ verification_attempts: {
45
+ type: DataTypes.INTEGER,
46
+ allowNull: false,
47
+ defaultValue: 0,
48
+ },
40
49
  verification_status: {
41
50
  type: DataTypes.ENUM(...Object.values(KYC_STATUS)),
42
51
  allowNull: false,
package/models/Product.js CHANGED
@@ -30,6 +30,11 @@ module.exports = (sequelize) => {
30
30
  foreignKey: "product_id",
31
31
  as: "availabilityReminders",
32
32
  });
33
+
34
+ Product.hasMany(models.StockAdjustment, {
35
+ foreignKey: "product_id",
36
+ as: "stockAdjustments",
37
+ });
33
38
  }
34
39
  }
35
40
 
@@ -104,6 +109,36 @@ module.exports = (sequelize) => {
104
109
  allowNull: false,
105
110
  defaultValue: PRODUCT_STATUS.DRAFT,
106
111
  },
112
+ low_stock_threshold: {
113
+ type: DataTypes.INTEGER,
114
+ allowNull: false,
115
+ defaultValue: 2,
116
+ },
117
+ units_sold_online: {
118
+ type: DataTypes.INTEGER,
119
+ allowNull: false,
120
+ defaultValue: 0,
121
+ },
122
+ units_sold_offline: {
123
+ type: DataTypes.INTEGER,
124
+ allowNull: false,
125
+ defaultValue: 0,
126
+ },
127
+ last_sold_at: {
128
+ type: DataTypes.DATE,
129
+ allowNull: true,
130
+ comment: "Timestamp of the last sale",
131
+ },
132
+ low_stock_notified_at: {
133
+ type: DataTypes.DATE,
134
+ allowNull: true,
135
+ comment: "Timestamp of the last low stock notification",
136
+ },
137
+ revalidation_prompted_at: {
138
+ type: DataTypes.DATE,
139
+ allowNull: true,
140
+ comment: "Timestamp of the last revalidation prompt",
141
+ },
107
142
  },
108
143
  {
109
144
  sequelize,
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ const { Model, DataTypes } = require("sequelize");
4
+ const { STOCK_ADJUSTMENT_TYPE } = require("../services/constants");
5
+
6
+ module.exports = (sequelize) => {
7
+ class StockAdjustment extends Model {
8
+ static associate(models) {
9
+ StockAdjustment.belongsTo(models.Product, {
10
+ foreignKey: "product_id",
11
+ as: "product",
12
+ });
13
+
14
+ StockAdjustment.belongsTo(models.User, {
15
+ foreignKey: "seller_id",
16
+ as: "seller",
17
+ });
18
+ }
19
+ }
20
+
21
+ StockAdjustment.init(
22
+ {
23
+ stock_adjustment_id: {
24
+ type: DataTypes.INTEGER,
25
+ primaryKey: true,
26
+ autoIncrement: true,
27
+ },
28
+ product_id: {
29
+ type: DataTypes.INTEGER,
30
+ allowNull: false,
31
+ },
32
+ seller_id: {
33
+ type: DataTypes.INTEGER,
34
+ allowNull: false,
35
+ },
36
+ type: {
37
+ type: DataTypes.ENUM(...Object.values(STOCK_ADJUSTMENT_TYPE)),
38
+ allowNull: false,
39
+ },
40
+ quantity_change: {
41
+ type: DataTypes.INTEGER,
42
+ allowNull: false,
43
+ },
44
+ previous_stock: {
45
+ type: DataTypes.INTEGER,
46
+ allowNull: false,
47
+ },
48
+ new_stock: {
49
+ type: DataTypes.INTEGER,
50
+ allowNull: false,
51
+ },
52
+ note: {
53
+ type: DataTypes.TEXT,
54
+ allowNull: true,
55
+ },
56
+ },
57
+ {
58
+ sequelize,
59
+ modelName: "StockAdjustment",
60
+ tableName: "stock_adjustments",
61
+ timestamps: true,
62
+ createdAt: "created_at",
63
+ updatedAt: false,
64
+ },
65
+ );
66
+
67
+ StockAdjustment.removeAttribute("id");
68
+ return StockAdjustment;
69
+ };
package/models/User.js CHANGED
@@ -184,7 +184,13 @@ module.exports = (sequelize) => {
184
184
  nin_verified: {
185
185
  type: DataTypes.BOOLEAN,
186
186
  defaultValue: false,
187
- comment: "Sellers only",
187
+ comment: "Buyers and Individual Sellers",
188
+ },
189
+ cac_verified: {
190
+ type: DataTypes.BOOLEAN,
191
+ allowNull: false,
192
+ defaultValue: false,
193
+ comment: "Business sellers only",
188
194
  },
189
195
  bank_verified: {
190
196
  type: DataTypes.BOOLEAN,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ojamoto_models",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -161,4 +161,13 @@ module.exports = {
161
161
  ACCEPTED: "ACCEPTED",
162
162
  REJECTED: "REJECTED",
163
163
  },
164
+
165
+ STOCK_ADJUSTMENT_TYPE: {
166
+ RESTOCK: "RESTOCK",
167
+ SALE_OFFLINE: "SALE_OFFLINE",
168
+ DAMAGE: "DAMAGE",
169
+ CORRECTION: "CORRECTION",
170
+ BULK_UPDATE: "BULK_UPDATE",
171
+ OTHER: "OTHER",
172
+ },
164
173
  };