Skip to content

Commit

Permalink
feat: gateway change user tier
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Feb 23, 2024
1 parent 708ddc6 commit c074689
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
SYNC_KEEPALIVE_INTERVAL_MS: 60 * 1000, // 60 seconds
SHARE_TOKEN_LENGTH: 64,
RECENTS_LIMIT: 15,
PLAN_FREE_TIER_ID: 'free_000000',
INDIVIDUAL_FREE_TIER_PLAN_ID: 'free_000000',
};
10 changes: 6 additions & 4 deletions src/app/routes/gateway.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { PLAN_FREE_TIER_ID } = require('../constants');
const { INDIVIDUAL_FREE_TIER_PLAN_ID } = require('../constants');
const basicAuthBuilder = require('../middleware/basic-auth');
const logger = require('../../lib/logger').default;

Expand Down Expand Up @@ -66,14 +66,14 @@ module.exports = (Router, Service) => {
});

Router.put('/gateway/user/update/tier', basicAuth, async (req, res) => {
const { planId, assignFreeTier } = req.body;
const { planId } = req.body;
const uuid = req.body.uuid;

if (!uuid) {
return res.status(400).send({ error: 'Users uuid is required' });
}

if (!planId && !assignFreeTier) {
if (!planId) {
return res.status(400).send({ error: 'You need to asign a tier to the user' });
}

Expand All @@ -83,7 +83,9 @@ module.exports = (Router, Service) => {
return res.status(500).send();
}

const paidPlanTier = await Service.FeatureLimits.getTierByPlanId(assignFreeTier ? PLAN_FREE_TIER_ID : planId);
const 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' });
Expand Down

0 comments on commit c074689

Please sign in to comment.