Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gateway update tier does not fail anymore #430

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/app/routes/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@ module.exports = (Router, Service) => {

let user = await Service.User.FindUserByUuid(uuid);
if (!user) {
Logger.error('[Gateway]: Failed to get user :%s', uuid);
Logger.error('[GATEWAY/TIER]: Failed to get user :%s', uuid);
return res.status(500).send();
}

const paidPlanTier = await Service.FeatureLimits.getTierByPlanId(
let paidPlanTier = await Service.FeatureLimits.getTierByPlanId(
planId === 'free_individual_tier' ? INDIVIDUAL_FREE_TIER_PLAN_ID : planId,
);

if (!paidPlanTier) {
Logger.error(`[GATEWAY]: Plan id not found id: ${planId} email: ${user.email}`);
return res.status(500).send({ error: 'Plan was not found' });
Logger.error(
`[GATEWAY/TIER]: Plan id not found, assigning free tier by default. id: ${planId}, email: ${user.email}`,
);
paidPlanTier = await Service.FeatureLimits.getIndividualFreeTier();
}

await Service.User.updateTier(user, paidPlanTier.tierId);
return res.status(200).send({ error: null, user: { ...user.dataValues, tierId: paidPlanTier.tierId } });
});
Expand Down
6 changes: 6 additions & 0 deletions src/app/services/featureLimit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { INDIVIDUAL_FREE_TIER_PLAN_ID } = require('../constants');

module.exports = (Model, App) => {

Check warning on line 3 in src/app/services/featureLimit.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

'App' is defined but never used

Check warning on line 3 in src/app/services/featureLimit.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'App' is defined but never used
const getTierByPlanId = async (planId) => {
return Model.paidPlans.findOne({
where: { planId },
Expand All @@ -7,8 +8,13 @@
});
};

const getIndividualFreeTier = async () => {
return getTierByPlanId(INDIVIDUAL_FREE_TIER_PLAN_ID);
};

return {
Name: 'FeatureLimits',
getTierByPlanId,
getIndividualFreeTier,
};
};
Loading