ojamoto_models 1.0.0 → 1.0.2
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/2026000030-create-admin-sessions.js.js +45 -0
- package/migrations/2026000031-add-totp-secret-to-admin-users.js +15 -0
- package/migrations/2026000032-add-totp-secret-to-users.js +15 -0
- package/migrations/2026000033-add-passwaord-change-to-admin-user.js +15 -0
- package/migrations/2026000034-add-fields-to-user.js +25 -0
- package/migrations/2026000035-add-field-to-wallet-transactions.js +22 -0
- package/models/AdminSession.js +55 -0
- package/models/AdminUser.js +132 -115
- package/models/AuditLog.js +70 -70
- package/models/Device.js +82 -82
- package/models/Dispute.js +109 -109
- package/models/DisputeEvidence.js +62 -62
- package/models/DisputeMessage.js +57 -57
- package/models/Escrow.js +110 -110
- package/models/EscrowEvent.js +63 -63
- package/models/KycVerification.js +62 -62
- package/models/Logistics.js +62 -62
- package/models/Notification.js +58 -58
- package/models/Product.js +100 -100
- package/models/ProductImage.js +54 -54
- package/models/Rating.js +74 -74
- package/models/Role.js +43 -43
- package/models/SellerProfile.js +92 -92
- package/models/Session.js +67 -67
- package/models/User.js +210 -198
- package/models/UserRole.js +42 -42
- package/models/Wallet.js +63 -63
- package/models/WalletTransaction.js +85 -81
- package/models/WebhookLog.js +52 -52
- package/package.json +1 -1
package/models/Notification.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Model, DataTypes } = require("sequelize");
|
|
4
|
-
|
|
5
|
-
module.exports = (sequelize) => {
|
|
6
|
-
class Notification extends Model {
|
|
7
|
-
static associate(models) {
|
|
8
|
-
Notification.belongsTo(models.User, {
|
|
9
|
-
foreignKey: "user_id",
|
|
10
|
-
as: "user",
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Notification.init(
|
|
16
|
-
{
|
|
17
|
-
notification_id: {
|
|
18
|
-
type: DataTypes.INTEGER,
|
|
19
|
-
primaryKey: true,
|
|
20
|
-
autoIncrement: true,
|
|
21
|
-
},
|
|
22
|
-
user_id: {
|
|
23
|
-
type: DataTypes.INTEGER,
|
|
24
|
-
allowNull: false,
|
|
25
|
-
references: { model: "users", key: "user_id" },
|
|
26
|
-
onDelete: "CASCADE",
|
|
27
|
-
},
|
|
28
|
-
type: {
|
|
29
|
-
type: DataTypes.STRING(100),
|
|
30
|
-
allowNull: false,
|
|
31
|
-
comment: "ESCROW_FUNDED | PAYMENT_RELEASED | DISPUTE_OPENED etc.",
|
|
32
|
-
},
|
|
33
|
-
title: {
|
|
34
|
-
type: DataTypes.STRING(255),
|
|
35
|
-
allowNull: false,
|
|
36
|
-
},
|
|
37
|
-
message: {
|
|
38
|
-
type: DataTypes.TEXT,
|
|
39
|
-
allowNull: false,
|
|
40
|
-
},
|
|
41
|
-
read_status: {
|
|
42
|
-
type: DataTypes.BOOLEAN,
|
|
43
|
-
defaultValue: false,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
sequelize,
|
|
48
|
-
modelName: "Notification",
|
|
49
|
-
tableName: "notifications",
|
|
50
|
-
timestamps: true,
|
|
51
|
-
createdAt: "created_at",
|
|
52
|
-
updatedAt: false,
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
Notification.removeAttribute("id");
|
|
57
|
-
return Notification;
|
|
58
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class Notification extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
Notification.belongsTo(models.User, {
|
|
9
|
+
foreignKey: "user_id",
|
|
10
|
+
as: "user",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Notification.init(
|
|
16
|
+
{
|
|
17
|
+
notification_id: {
|
|
18
|
+
type: DataTypes.INTEGER,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
},
|
|
22
|
+
user_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
references: { model: "users", key: "user_id" },
|
|
26
|
+
onDelete: "CASCADE",
|
|
27
|
+
},
|
|
28
|
+
type: {
|
|
29
|
+
type: DataTypes.STRING(100),
|
|
30
|
+
allowNull: false,
|
|
31
|
+
comment: "ESCROW_FUNDED | PAYMENT_RELEASED | DISPUTE_OPENED etc.",
|
|
32
|
+
},
|
|
33
|
+
title: {
|
|
34
|
+
type: DataTypes.STRING(255),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
message: {
|
|
38
|
+
type: DataTypes.TEXT,
|
|
39
|
+
allowNull: false,
|
|
40
|
+
},
|
|
41
|
+
read_status: {
|
|
42
|
+
type: DataTypes.BOOLEAN,
|
|
43
|
+
defaultValue: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
sequelize,
|
|
48
|
+
modelName: "Notification",
|
|
49
|
+
tableName: "notifications",
|
|
50
|
+
timestamps: true,
|
|
51
|
+
createdAt: "created_at",
|
|
52
|
+
updatedAt: false,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
Notification.removeAttribute("id");
|
|
57
|
+
return Notification;
|
|
58
|
+
};
|
package/models/Product.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Model, DataTypes } = require("sequelize");
|
|
4
|
-
const { PRODUCT_CONDITION, PRODUCT_STATUS } = require("../services/constants");
|
|
5
|
-
|
|
6
|
-
module.exports = (sequelize) => {
|
|
7
|
-
class Product extends Model {
|
|
8
|
-
static associate(models) {
|
|
9
|
-
Product.belongsTo(models.User, {
|
|
10
|
-
foreignKey: "seller_id",
|
|
11
|
-
as: "seller",
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
Product.hasMany(models.ProductImage, {
|
|
15
|
-
foreignKey: "product_id",
|
|
16
|
-
as: "images",
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
Product.hasMany(models.Escrow, {
|
|
20
|
-
foreignKey: "product_id",
|
|
21
|
-
as: "escrows",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
Product.init(
|
|
27
|
-
{
|
|
28
|
-
product_id: {
|
|
29
|
-
type: DataTypes.INTEGER,
|
|
30
|
-
primaryKey: true,
|
|
31
|
-
autoIncrement: true,
|
|
32
|
-
},
|
|
33
|
-
seller_id: {
|
|
34
|
-
type: DataTypes.INTEGER,
|
|
35
|
-
allowNull: false,
|
|
36
|
-
references: { model: "users", key: "user_id" },
|
|
37
|
-
onDelete: "CASCADE",
|
|
38
|
-
},
|
|
39
|
-
name: {
|
|
40
|
-
type: DataTypes.STRING(255),
|
|
41
|
-
allowNull: false,
|
|
42
|
-
},
|
|
43
|
-
description: {
|
|
44
|
-
type: DataTypes.TEXT,
|
|
45
|
-
allowNull: true,
|
|
46
|
-
},
|
|
47
|
-
price: {
|
|
48
|
-
type: DataTypes.DECIMAL(15, 2),
|
|
49
|
-
allowNull: false,
|
|
50
|
-
},
|
|
51
|
-
currency: {
|
|
52
|
-
type: DataTypes.STRING(3),
|
|
53
|
-
allowNull: false,
|
|
54
|
-
defaultValue: "NGN",
|
|
55
|
-
},
|
|
56
|
-
category: {
|
|
57
|
-
type: DataTypes.STRING(100),
|
|
58
|
-
allowNull: true,
|
|
59
|
-
comment: "Engine | Brake | Suspension etc.",
|
|
60
|
-
},
|
|
61
|
-
brand: {
|
|
62
|
-
type: DataTypes.STRING(100),
|
|
63
|
-
allowNull: true,
|
|
64
|
-
comment: "Toyota, Ford, Bosch etc.",
|
|
65
|
-
},
|
|
66
|
-
model: {
|
|
67
|
-
type: DataTypes.STRING(100),
|
|
68
|
-
allowNull: true,
|
|
69
|
-
comment: "Camry, F-150 etc.",
|
|
70
|
-
},
|
|
71
|
-
condition: {
|
|
72
|
-
type: DataTypes.ENUM(...Object.values(PRODUCT_CONDITION)),
|
|
73
|
-
allowNull: false,
|
|
74
|
-
},
|
|
75
|
-
stock: {
|
|
76
|
-
type: DataTypes.INTEGER,
|
|
77
|
-
allowNull: false,
|
|
78
|
-
defaultValue: 1,
|
|
79
|
-
},
|
|
80
|
-
status: {
|
|
81
|
-
type: DataTypes.ENUM(...Object.values(PRODUCT_STATUS)),
|
|
82
|
-
allowNull: false,
|
|
83
|
-
defaultValue: PRODUCT_STATUS.DRAFT,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
sequelize,
|
|
88
|
-
modelName: "Product",
|
|
89
|
-
tableName: "products",
|
|
90
|
-
timestamps: true,
|
|
91
|
-
paranoid: true,
|
|
92
|
-
createdAt: "created_at",
|
|
93
|
-
updatedAt: "updated_at",
|
|
94
|
-
deletedAt: "deleted_at",
|
|
95
|
-
},
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
Product.removeAttribute("id");
|
|
99
|
-
return Product;
|
|
100
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { PRODUCT_CONDITION, PRODUCT_STATUS } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class Product extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
Product.belongsTo(models.User, {
|
|
10
|
+
foreignKey: "seller_id",
|
|
11
|
+
as: "seller",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
Product.hasMany(models.ProductImage, {
|
|
15
|
+
foreignKey: "product_id",
|
|
16
|
+
as: "images",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
Product.hasMany(models.Escrow, {
|
|
20
|
+
foreignKey: "product_id",
|
|
21
|
+
as: "escrows",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Product.init(
|
|
27
|
+
{
|
|
28
|
+
product_id: {
|
|
29
|
+
type: DataTypes.INTEGER,
|
|
30
|
+
primaryKey: true,
|
|
31
|
+
autoIncrement: true,
|
|
32
|
+
},
|
|
33
|
+
seller_id: {
|
|
34
|
+
type: DataTypes.INTEGER,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
references: { model: "users", key: "user_id" },
|
|
37
|
+
onDelete: "CASCADE",
|
|
38
|
+
},
|
|
39
|
+
name: {
|
|
40
|
+
type: DataTypes.STRING(255),
|
|
41
|
+
allowNull: false,
|
|
42
|
+
},
|
|
43
|
+
description: {
|
|
44
|
+
type: DataTypes.TEXT,
|
|
45
|
+
allowNull: true,
|
|
46
|
+
},
|
|
47
|
+
price: {
|
|
48
|
+
type: DataTypes.DECIMAL(15, 2),
|
|
49
|
+
allowNull: false,
|
|
50
|
+
},
|
|
51
|
+
currency: {
|
|
52
|
+
type: DataTypes.STRING(3),
|
|
53
|
+
allowNull: false,
|
|
54
|
+
defaultValue: "NGN",
|
|
55
|
+
},
|
|
56
|
+
category: {
|
|
57
|
+
type: DataTypes.STRING(100),
|
|
58
|
+
allowNull: true,
|
|
59
|
+
comment: "Engine | Brake | Suspension etc.",
|
|
60
|
+
},
|
|
61
|
+
brand: {
|
|
62
|
+
type: DataTypes.STRING(100),
|
|
63
|
+
allowNull: true,
|
|
64
|
+
comment: "Toyota, Ford, Bosch etc.",
|
|
65
|
+
},
|
|
66
|
+
model: {
|
|
67
|
+
type: DataTypes.STRING(100),
|
|
68
|
+
allowNull: true,
|
|
69
|
+
comment: "Camry, F-150 etc.",
|
|
70
|
+
},
|
|
71
|
+
condition: {
|
|
72
|
+
type: DataTypes.ENUM(...Object.values(PRODUCT_CONDITION)),
|
|
73
|
+
allowNull: false,
|
|
74
|
+
},
|
|
75
|
+
stock: {
|
|
76
|
+
type: DataTypes.INTEGER,
|
|
77
|
+
allowNull: false,
|
|
78
|
+
defaultValue: 1,
|
|
79
|
+
},
|
|
80
|
+
status: {
|
|
81
|
+
type: DataTypes.ENUM(...Object.values(PRODUCT_STATUS)),
|
|
82
|
+
allowNull: false,
|
|
83
|
+
defaultValue: PRODUCT_STATUS.DRAFT,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
sequelize,
|
|
88
|
+
modelName: "Product",
|
|
89
|
+
tableName: "products",
|
|
90
|
+
timestamps: true,
|
|
91
|
+
paranoid: true,
|
|
92
|
+
createdAt: "created_at",
|
|
93
|
+
updatedAt: "updated_at",
|
|
94
|
+
deletedAt: "deleted_at",
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
Product.removeAttribute("id");
|
|
99
|
+
return Product;
|
|
100
|
+
};
|
package/models/ProductImage.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Model, DataTypes } = require("sequelize");
|
|
4
|
-
|
|
5
|
-
module.exports = (sequelize) => {
|
|
6
|
-
class ProductImage extends Model {
|
|
7
|
-
static associate(models) {
|
|
8
|
-
ProductImage.belongsTo(models.Product, {
|
|
9
|
-
foreignKey: "product_id",
|
|
10
|
-
as: "product",
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
ProductImage.init(
|
|
16
|
-
{
|
|
17
|
-
product_image_id: {
|
|
18
|
-
type: DataTypes.INTEGER,
|
|
19
|
-
primaryKey: true,
|
|
20
|
-
autoIncrement: true,
|
|
21
|
-
},
|
|
22
|
-
product_id: {
|
|
23
|
-
type: DataTypes.INTEGER,
|
|
24
|
-
allowNull: false,
|
|
25
|
-
references: { model: "products", key: "product_id" },
|
|
26
|
-
onDelete: "CASCADE",
|
|
27
|
-
},
|
|
28
|
-
image_url: {
|
|
29
|
-
type: DataTypes.STRING(500),
|
|
30
|
-
allowNull: false,
|
|
31
|
-
comment: "AWS S3 URL",
|
|
32
|
-
},
|
|
33
|
-
position: {
|
|
34
|
-
type: DataTypes.INTEGER,
|
|
35
|
-
defaultValue: 0,
|
|
36
|
-
comment: "Display order",
|
|
37
|
-
},
|
|
38
|
-
ai_metadata: {
|
|
39
|
-
type: DataTypes.JSON,
|
|
40
|
-
allowNull: true,
|
|
41
|
-
comment: "Brand, model, condition extracted by AI analysis",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
sequelize,
|
|
46
|
-
modelName: "ProductImage",
|
|
47
|
-
tableName: "product_images",
|
|
48
|
-
timestamps: false,
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
ProductImage.removeAttribute("id");
|
|
53
|
-
return ProductImage;
|
|
54
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class ProductImage extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
ProductImage.belongsTo(models.Product, {
|
|
9
|
+
foreignKey: "product_id",
|
|
10
|
+
as: "product",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ProductImage.init(
|
|
16
|
+
{
|
|
17
|
+
product_image_id: {
|
|
18
|
+
type: DataTypes.INTEGER,
|
|
19
|
+
primaryKey: true,
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
},
|
|
22
|
+
product_id: {
|
|
23
|
+
type: DataTypes.INTEGER,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
references: { model: "products", key: "product_id" },
|
|
26
|
+
onDelete: "CASCADE",
|
|
27
|
+
},
|
|
28
|
+
image_url: {
|
|
29
|
+
type: DataTypes.STRING(500),
|
|
30
|
+
allowNull: false,
|
|
31
|
+
comment: "AWS S3 URL",
|
|
32
|
+
},
|
|
33
|
+
position: {
|
|
34
|
+
type: DataTypes.INTEGER,
|
|
35
|
+
defaultValue: 0,
|
|
36
|
+
comment: "Display order",
|
|
37
|
+
},
|
|
38
|
+
ai_metadata: {
|
|
39
|
+
type: DataTypes.JSON,
|
|
40
|
+
allowNull: true,
|
|
41
|
+
comment: "Brand, model, condition extracted by AI analysis",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
sequelize,
|
|
46
|
+
modelName: "ProductImage",
|
|
47
|
+
tableName: "product_images",
|
|
48
|
+
timestamps: false,
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
ProductImage.removeAttribute("id");
|
|
53
|
+
return ProductImage;
|
|
54
|
+
};
|
package/models/Rating.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Model, DataTypes } = require("sequelize");
|
|
4
|
-
|
|
5
|
-
module.exports = (sequelize) => {
|
|
6
|
-
class Rating extends Model {
|
|
7
|
-
static associate(models) {
|
|
8
|
-
Rating.belongsTo(models.Escrow, {
|
|
9
|
-
foreignKey: "escrow_id",
|
|
10
|
-
as: "escrow",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
Rating.belongsTo(models.User, {
|
|
14
|
-
foreignKey: "buyer_id",
|
|
15
|
-
as: "buyer",
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
Rating.belongsTo(models.User, {
|
|
19
|
-
foreignKey: "seller_id",
|
|
20
|
-
as: "seller",
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Rating.init(
|
|
26
|
-
{
|
|
27
|
-
rating_id: {
|
|
28
|
-
type: DataTypes.INTEGER,
|
|
29
|
-
primaryKey: true,
|
|
30
|
-
autoIncrement: true,
|
|
31
|
-
},
|
|
32
|
-
escrow_id: {
|
|
33
|
-
type: DataTypes.INTEGER,
|
|
34
|
-
allowNull: false,
|
|
35
|
-
unique: true,
|
|
36
|
-
references: { model: "escrows", key: "escrow_id" },
|
|
37
|
-
onDelete: "RESTRICT",
|
|
38
|
-
comment: "One rating per completed escrow",
|
|
39
|
-
},
|
|
40
|
-
buyer_id: {
|
|
41
|
-
type: DataTypes.INTEGER,
|
|
42
|
-
allowNull: false,
|
|
43
|
-
references: { model: "users", key: "user_id" },
|
|
44
|
-
onDelete: "RESTRICT",
|
|
45
|
-
},
|
|
46
|
-
seller_id: {
|
|
47
|
-
type: DataTypes.INTEGER,
|
|
48
|
-
allowNull: false,
|
|
49
|
-
references: { model: "users", key: "user_id" },
|
|
50
|
-
onDelete: "RESTRICT",
|
|
51
|
-
},
|
|
52
|
-
rating: {
|
|
53
|
-
type: DataTypes.TINYINT,
|
|
54
|
-
allowNull: false,
|
|
55
|
-
validate: { min: 1, max: 5 },
|
|
56
|
-
},
|
|
57
|
-
comment: {
|
|
58
|
-
type: DataTypes.TEXT,
|
|
59
|
-
allowNull: true,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
sequelize,
|
|
64
|
-
modelName: "Rating",
|
|
65
|
-
tableName: "ratings",
|
|
66
|
-
timestamps: true,
|
|
67
|
-
createdAt: "created_at",
|
|
68
|
-
updatedAt: false,
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
Rating.removeAttribute("id");
|
|
73
|
-
return Rating;
|
|
74
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
|
|
5
|
+
module.exports = (sequelize) => {
|
|
6
|
+
class Rating extends Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
Rating.belongsTo(models.Escrow, {
|
|
9
|
+
foreignKey: "escrow_id",
|
|
10
|
+
as: "escrow",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
Rating.belongsTo(models.User, {
|
|
14
|
+
foreignKey: "buyer_id",
|
|
15
|
+
as: "buyer",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
Rating.belongsTo(models.User, {
|
|
19
|
+
foreignKey: "seller_id",
|
|
20
|
+
as: "seller",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Rating.init(
|
|
26
|
+
{
|
|
27
|
+
rating_id: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
primaryKey: true,
|
|
30
|
+
autoIncrement: true,
|
|
31
|
+
},
|
|
32
|
+
escrow_id: {
|
|
33
|
+
type: DataTypes.INTEGER,
|
|
34
|
+
allowNull: false,
|
|
35
|
+
unique: true,
|
|
36
|
+
references: { model: "escrows", key: "escrow_id" },
|
|
37
|
+
onDelete: "RESTRICT",
|
|
38
|
+
comment: "One rating per completed escrow",
|
|
39
|
+
},
|
|
40
|
+
buyer_id: {
|
|
41
|
+
type: DataTypes.INTEGER,
|
|
42
|
+
allowNull: false,
|
|
43
|
+
references: { model: "users", key: "user_id" },
|
|
44
|
+
onDelete: "RESTRICT",
|
|
45
|
+
},
|
|
46
|
+
seller_id: {
|
|
47
|
+
type: DataTypes.INTEGER,
|
|
48
|
+
allowNull: false,
|
|
49
|
+
references: { model: "users", key: "user_id" },
|
|
50
|
+
onDelete: "RESTRICT",
|
|
51
|
+
},
|
|
52
|
+
rating: {
|
|
53
|
+
type: DataTypes.TINYINT,
|
|
54
|
+
allowNull: false,
|
|
55
|
+
validate: { min: 1, max: 5 },
|
|
56
|
+
},
|
|
57
|
+
comment: {
|
|
58
|
+
type: DataTypes.TEXT,
|
|
59
|
+
allowNull: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
sequelize,
|
|
64
|
+
modelName: "Rating",
|
|
65
|
+
tableName: "ratings",
|
|
66
|
+
timestamps: true,
|
|
67
|
+
createdAt: "created_at",
|
|
68
|
+
updatedAt: false,
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
Rating.removeAttribute("id");
|
|
73
|
+
return Rating;
|
|
74
|
+
};
|
package/models/Role.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Model, DataTypes } = require("sequelize");
|
|
4
|
-
const { ROLE_NAME } = require("../services/constants");
|
|
5
|
-
|
|
6
|
-
module.exports = (sequelize) => {
|
|
7
|
-
class Role extends Model {
|
|
8
|
-
static associate(models) {
|
|
9
|
-
Role.belongsToMany(models.User, {
|
|
10
|
-
through: models.UserRole,
|
|
11
|
-
foreignKey: "role_id",
|
|
12
|
-
otherKey: "user_id",
|
|
13
|
-
as: "users",
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Role.init(
|
|
19
|
-
{
|
|
20
|
-
role_id: {
|
|
21
|
-
type: DataTypes.INTEGER,
|
|
22
|
-
primaryKey: true,
|
|
23
|
-
autoIncrement: true,
|
|
24
|
-
},
|
|
25
|
-
name: {
|
|
26
|
-
type: DataTypes.ENUM(...Object.values(ROLE_NAME)),
|
|
27
|
-
allowNull: false,
|
|
28
|
-
unique: true,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
sequelize,
|
|
33
|
-
modelName: "Role",
|
|
34
|
-
tableName: "roles",
|
|
35
|
-
timestamps: true,
|
|
36
|
-
createdAt: "created_at",
|
|
37
|
-
updatedAt: "updated_at",
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
Role.removeAttribute("id");
|
|
42
|
-
return Role;
|
|
43
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { ROLE_NAME } = require("../services/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class Role extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
Role.belongsToMany(models.User, {
|
|
10
|
+
through: models.UserRole,
|
|
11
|
+
foreignKey: "role_id",
|
|
12
|
+
otherKey: "user_id",
|
|
13
|
+
as: "users",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Role.init(
|
|
19
|
+
{
|
|
20
|
+
role_id: {
|
|
21
|
+
type: DataTypes.INTEGER,
|
|
22
|
+
primaryKey: true,
|
|
23
|
+
autoIncrement: true,
|
|
24
|
+
},
|
|
25
|
+
name: {
|
|
26
|
+
type: DataTypes.ENUM(...Object.values(ROLE_NAME)),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
unique: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
sequelize,
|
|
33
|
+
modelName: "Role",
|
|
34
|
+
tableName: "roles",
|
|
35
|
+
timestamps: true,
|
|
36
|
+
createdAt: "created_at",
|
|
37
|
+
updatedAt: "updated_at",
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
Role.removeAttribute("id");
|
|
42
|
+
return Role;
|
|
43
|
+
};
|