ojamoto_models 1.0.14 → 1.0.15
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/migrations/2026000054-create-product-rating.js +73 -0
- package/migrations/2026000055-create-notification-preferences.js +54 -0
- package/models/NotificationPreference.js +59 -0
- package/models/Product.js +14 -0
- package/models/ProductRating.js +54 -0
- package/models/User.js +6 -0
- package/package.json +1 -1
- package/services/constants.js +13 -1
- /package/models/{Bank → Bank.js} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("product_ratings", {
|
|
6
|
+
product_rating_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
|
+
buyer_id: {
|
|
20
|
+
type: Sequelize.INTEGER,
|
|
21
|
+
allowNull: false,
|
|
22
|
+
references: { model: "users", key: "user_id" },
|
|
23
|
+
onDelete: "CASCADE",
|
|
24
|
+
onUpdate: "CASCADE",
|
|
25
|
+
},
|
|
26
|
+
rating: {
|
|
27
|
+
type: Sequelize.TINYINT,
|
|
28
|
+
allowNull: false,
|
|
29
|
+
},
|
|
30
|
+
comment: {
|
|
31
|
+
type: Sequelize.TEXT,
|
|
32
|
+
allowNull: true,
|
|
33
|
+
},
|
|
34
|
+
created_at: {
|
|
35
|
+
type: Sequelize.DATE,
|
|
36
|
+
allowNull: false,
|
|
37
|
+
},
|
|
38
|
+
updated_at: {
|
|
39
|
+
type: Sequelize.DATE,
|
|
40
|
+
allowNull: false,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Add to Product table
|
|
45
|
+
await queryInterface.addColumn("products", "avg_rating", {
|
|
46
|
+
type: Sequelize.DECIMAL(3, 2),
|
|
47
|
+
allowNull: true,
|
|
48
|
+
after: "revalidation_prompted_at",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await queryInterface.addColumn("products", "ratings_count", {
|
|
52
|
+
type: Sequelize.INTEGER,
|
|
53
|
+
allowNull: false,
|
|
54
|
+
defaultValue: 0,
|
|
55
|
+
after: "avg_rating",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await queryInterface.addIndex("product_ratings", ["product_id"]);
|
|
59
|
+
|
|
60
|
+
await queryInterface.addIndex(
|
|
61
|
+
"product_ratings",
|
|
62
|
+
["product_id", "buyer_id"],
|
|
63
|
+
{
|
|
64
|
+
unique: true,
|
|
65
|
+
name: "product_ratings_product_buyer_unique",
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async down(queryInterface) {
|
|
71
|
+
await queryInterface.dropTable("product_ratings");
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up(queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.createTable("notification_preferences", {
|
|
6
|
+
notification_preference_id: {
|
|
7
|
+
type: Sequelize.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true,
|
|
10
|
+
allowNull: false,
|
|
11
|
+
},
|
|
12
|
+
user_id: {
|
|
13
|
+
type: Sequelize.INTEGER,
|
|
14
|
+
allowNull: false,
|
|
15
|
+
unique: true,
|
|
16
|
+
references: { model: "users", key: "user_id" },
|
|
17
|
+
onDelete: "CASCADE",
|
|
18
|
+
onUpdate: "CASCADE",
|
|
19
|
+
},
|
|
20
|
+
push_enabled: {
|
|
21
|
+
type: Sequelize.BOOLEAN,
|
|
22
|
+
allowNull: false,
|
|
23
|
+
defaultValue: true,
|
|
24
|
+
},
|
|
25
|
+
in_app_enabled: {
|
|
26
|
+
type: Sequelize.BOOLEAN,
|
|
27
|
+
allowNull: false,
|
|
28
|
+
defaultValue: true,
|
|
29
|
+
},
|
|
30
|
+
email_enabled: {
|
|
31
|
+
type: Sequelize.BOOLEAN,
|
|
32
|
+
allowNull: false,
|
|
33
|
+
defaultValue: true,
|
|
34
|
+
},
|
|
35
|
+
sms_enabled: {
|
|
36
|
+
type: Sequelize.BOOLEAN,
|
|
37
|
+
allowNull: false,
|
|
38
|
+
defaultValue: true,
|
|
39
|
+
},
|
|
40
|
+
created_at: {
|
|
41
|
+
type: Sequelize.DATE,
|
|
42
|
+
allowNull: false,
|
|
43
|
+
},
|
|
44
|
+
updated_at: {
|
|
45
|
+
type: Sequelize.DATE,
|
|
46
|
+
allowNull: false,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
async down(queryInterface) {
|
|
52
|
+
await queryInterface.dropTable("notification_preferences");
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { Model, DataTypes } = require("sequelize");
|
|
3
|
+
|
|
4
|
+
module.exports = (sequelize) => {
|
|
5
|
+
class NotificationPreference extends Model {
|
|
6
|
+
static associate(models) {
|
|
7
|
+
NotificationPreference.belongsTo(models.User, {
|
|
8
|
+
foreignKey: "user_id",
|
|
9
|
+
as: "user",
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
NotificationPreference.init(
|
|
15
|
+
{
|
|
16
|
+
notification_preference_id: {
|
|
17
|
+
type: DataTypes.INTEGER,
|
|
18
|
+
primaryKey: true,
|
|
19
|
+
autoIncrement: true,
|
|
20
|
+
},
|
|
21
|
+
user_id: {
|
|
22
|
+
type: DataTypes.INTEGER,
|
|
23
|
+
allowNull: false,
|
|
24
|
+
unique: true,
|
|
25
|
+
},
|
|
26
|
+
push_enabled: {
|
|
27
|
+
type: DataTypes.BOOLEAN,
|
|
28
|
+
allowNull: false,
|
|
29
|
+
defaultValue: true,
|
|
30
|
+
},
|
|
31
|
+
in_app_enabled: {
|
|
32
|
+
type: DataTypes.BOOLEAN,
|
|
33
|
+
allowNull: false,
|
|
34
|
+
defaultValue: true,
|
|
35
|
+
},
|
|
36
|
+
email_enabled: {
|
|
37
|
+
type: DataTypes.BOOLEAN,
|
|
38
|
+
allowNull: false,
|
|
39
|
+
defaultValue: true,
|
|
40
|
+
},
|
|
41
|
+
sms_enabled: {
|
|
42
|
+
type: DataTypes.BOOLEAN,
|
|
43
|
+
allowNull: false,
|
|
44
|
+
defaultValue: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
sequelize,
|
|
49
|
+
modelName: "NotificationPreference",
|
|
50
|
+
tableName: "notification_preferences",
|
|
51
|
+
timestamps: true,
|
|
52
|
+
createdAt: "created_at",
|
|
53
|
+
updatedAt: "updated_at",
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
NotificationPreference.removeAttribute("id");
|
|
58
|
+
return NotificationPreference;
|
|
59
|
+
};
|
package/models/Product.js
CHANGED
|
@@ -35,6 +35,11 @@ module.exports = (sequelize) => {
|
|
|
35
35
|
foreignKey: "product_id",
|
|
36
36
|
as: "stockAdjustments",
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
Product.hasMany(models.ProductRating, {
|
|
40
|
+
foreignKey: "product_id",
|
|
41
|
+
as: "productRatings",
|
|
42
|
+
});
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
|
|
@@ -139,6 +144,15 @@ module.exports = (sequelize) => {
|
|
|
139
144
|
allowNull: true,
|
|
140
145
|
comment: "Timestamp of the last revalidation prompt",
|
|
141
146
|
},
|
|
147
|
+
avg_rating: {
|
|
148
|
+
type: DataTypes.DECIMAL(3, 2),
|
|
149
|
+
allowNull: true,
|
|
150
|
+
},
|
|
151
|
+
ratings_count: {
|
|
152
|
+
type: DataTypes.INTEGER,
|
|
153
|
+
allowNull: false,
|
|
154
|
+
defaultValue: 0,
|
|
155
|
+
},
|
|
142
156
|
},
|
|
143
157
|
{
|
|
144
158
|
sequelize,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { Model, DataTypes } = require("sequelize");
|
|
3
|
+
|
|
4
|
+
module.exports = (sequelize) => {
|
|
5
|
+
class ProductRating extends Model {
|
|
6
|
+
static associate(models) {
|
|
7
|
+
ProductRating.belongsTo(models.Product, {
|
|
8
|
+
foreignKey: "product_id",
|
|
9
|
+
as: "product",
|
|
10
|
+
});
|
|
11
|
+
ProductRating.belongsTo(models.User, {
|
|
12
|
+
foreignKey: "buyer_id",
|
|
13
|
+
as: "buyer",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ProductRating.init(
|
|
19
|
+
{
|
|
20
|
+
product_rating_id: {
|
|
21
|
+
type: DataTypes.INTEGER,
|
|
22
|
+
primaryKey: true,
|
|
23
|
+
autoIncrement: true,
|
|
24
|
+
},
|
|
25
|
+
product_id: {
|
|
26
|
+
type: DataTypes.INTEGER,
|
|
27
|
+
allowNull: false,
|
|
28
|
+
},
|
|
29
|
+
buyer_id: {
|
|
30
|
+
type: DataTypes.INTEGER,
|
|
31
|
+
allowNull: false,
|
|
32
|
+
},
|
|
33
|
+
rating: {
|
|
34
|
+
type: DataTypes.TINYINT,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
comment: {
|
|
38
|
+
type: DataTypes.TEXT,
|
|
39
|
+
allowNull: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
sequelize,
|
|
44
|
+
modelName: "ProductRating",
|
|
45
|
+
tableName: "product_ratings",
|
|
46
|
+
timestamps: true,
|
|
47
|
+
createdAt: "created_at",
|
|
48
|
+
updatedAt: "updated_at",
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
ProductRating.removeAttribute("id");
|
|
53
|
+
return ProductRating;
|
|
54
|
+
};
|
package/models/User.js
CHANGED
|
@@ -115,6 +115,12 @@ module.exports = (sequelize) => {
|
|
|
115
115
|
foreignKey: "user_id",
|
|
116
116
|
as: "bankAccount",
|
|
117
117
|
});
|
|
118
|
+
|
|
119
|
+
// Notification
|
|
120
|
+
User.hasOne(models.NotificationPreference, {
|
|
121
|
+
foreignKey: "user_id",
|
|
122
|
+
as: "notificationPreference",
|
|
123
|
+
});
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
|
package/package.json
CHANGED
package/services/constants.js
CHANGED
|
@@ -94,8 +94,9 @@ module.exports = {
|
|
|
94
94
|
},
|
|
95
95
|
|
|
96
96
|
PHONE_OTP: {
|
|
97
|
+
LENGTH: 6,
|
|
97
98
|
MAX_ATTEMPTS: 3,
|
|
98
|
-
EXPIRY_MINUTES:
|
|
99
|
+
EXPIRY_MINUTES: 10,
|
|
99
100
|
RESEND_COOLDOWN_SECONDS: 60,
|
|
100
101
|
},
|
|
101
102
|
|
|
@@ -260,6 +261,17 @@ module.exports = {
|
|
|
260
261
|
OTHER: "OTHER",
|
|
261
262
|
},
|
|
262
263
|
|
|
264
|
+
BANK_NAME_MATCH_THRESHOLD: 0.8, // 80%
|
|
265
|
+
|
|
266
|
+
NOTIFICATION_PREFERENCE: {
|
|
267
|
+
PUSH_NOTIFICATION: "PUSH_NOTIFICATION",
|
|
268
|
+
IN_APP_NOTIFICATION: "IN_APP_NOTIFICATION",
|
|
269
|
+
EMAIL: "EMAIL",
|
|
270
|
+
SMS: "SMS",
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
////////////////////////////////////////////////////
|
|
274
|
+
|
|
263
275
|
// - Generic status IDs (legacy support) ──────────────────────────────────
|
|
264
276
|
STATUS_ID: {
|
|
265
277
|
ACTIVE: 1,
|
/package/models/{Bank → Bank.js}
RENAMED
|
File without changes
|