@b2y/ecommerce-common 1.3.2 → 1.3.4
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.
|
@@ -5,12 +5,21 @@ const AppUtil = require('../utility/AppUtil');
|
|
|
5
5
|
const getAllSubscriptionPlans = (
|
|
6
6
|
SubscriptionPlan,
|
|
7
7
|
SubscriptionFeature,
|
|
8
|
+
TenantSubscription,
|
|
8
9
|
logger,
|
|
9
10
|
) => {
|
|
10
11
|
return async (req, res) => {
|
|
11
12
|
const { pageNumber, pageSize } = req.query;
|
|
12
13
|
const { limit, offset } = AppUtil.getPagination(pageNumber, pageSize);
|
|
14
|
+
const tenantId = req.user?.TenantID;
|
|
13
15
|
try {
|
|
16
|
+
let tenantPlan = null;
|
|
17
|
+
if (tenantId !== null || tenantId !== undefined) {
|
|
18
|
+
tenantPlan = await TenantSubscription.findOne({
|
|
19
|
+
where: tenantId ? { TenantID: tenantId } : undefined,
|
|
20
|
+
attributes: ["SubscriptionPlanID", "Status"],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
14
23
|
const { rows, count } = await SubscriptionPlan.findAndCountAll({
|
|
15
24
|
attributes: [
|
|
16
25
|
"SubscriptionPlanID",
|
|
@@ -35,12 +44,35 @@ const getAllSubscriptionPlans = (
|
|
|
35
44
|
offset,
|
|
36
45
|
distinct: true,
|
|
37
46
|
});
|
|
47
|
+
const formattedPlanFeatures = rows.map((plan) => {
|
|
48
|
+
let isCurrentPlan = null;
|
|
49
|
+
let currentPlanStatus = null;
|
|
50
|
+
if (tenantId) {
|
|
51
|
+
isCurrentPlan =
|
|
52
|
+
tenantPlan.SubscriptionPlanID === plan.SubscriptionPlanID;
|
|
53
|
+
currentPlanStatus = isCurrentPlan ? tenantPlan.Status : null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
SubscriptionPlanID: plan.SubscriptionPlanID,
|
|
57
|
+
PlanName: plan.PlanName,
|
|
58
|
+
PlanCode: plan.PlanCode,
|
|
59
|
+
Price: AppUtil.trimDecimal(plan.Price),
|
|
60
|
+
BillingCycle: plan.BillingCycle,
|
|
61
|
+
Currency: plan.Currency,
|
|
62
|
+
TrialPeriodDays: plan.TrialPeriodDays,
|
|
63
|
+
IsActive: plan.IsActive,
|
|
64
|
+
SortOrder: plan.SortOrder,
|
|
65
|
+
isCurrentPlan,
|
|
66
|
+
currentPlanStatus,
|
|
67
|
+
Features: plan.Features,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
38
70
|
logger.debug("subscription plans fetched successfully");
|
|
39
71
|
return AppUtil.generateResponse(
|
|
40
72
|
200,
|
|
41
73
|
StatusMessage.SUCCESS,
|
|
42
74
|
null,
|
|
43
|
-
{ rows, count, pageNumber, limit },
|
|
75
|
+
{ rows: formattedPlanFeatures, count, pageNumber, limit },
|
|
44
76
|
res,
|
|
45
77
|
);
|
|
46
78
|
} catch (error) {
|
package/dbconnection/Connect.js
CHANGED
|
@@ -177,10 +177,10 @@ const initializeModels = (sequelize) => {
|
|
|
177
177
|
as: "AttributeValue",
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
ProductVariant.
|
|
180
|
+
ProductVariant.belongsTo(PackagingBox, {
|
|
181
181
|
foreignKey: "PackagingBoxID",
|
|
182
182
|
as: "PackagingBox"
|
|
183
|
-
})
|
|
183
|
+
});
|
|
184
184
|
|
|
185
185
|
// Product and ProductGroup Association
|
|
186
186
|
// Many-to-One
|