Skip to content

Commit

Permalink
Merge pull request #430 from internxt/fix/update-tier-gateway-does-no…
Browse files Browse the repository at this point in the history
…t-fail

fix: gateway update tier does not fail anymore
  • Loading branch information
sg-gs authored Mar 7, 2024
2 parents 6c5ff34 + 61b7c49 commit c672cc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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,3 +1,4 @@
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 / build (16.x)

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

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

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

0 comments on commit c672cc9

Please sign in to comment.