Skip to content

Commit

Permalink
Merge pull request #328 from switcherapi/patch_297
Browse files Browse the repository at this point in the history
Closes #297 - Bumped switcher-client to 3.1.1
  • Loading branch information
petruki authored Jul 2, 2022
2 parents 03d8106 + 4861514 commit 46ccf09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"mongodb": "^4.7.0",
"mongoose": "^6.4.0",
"swagger-ui-express": "^4.4.0",
"switcher-client": "^3.1.0",
"switcher-client": "^3.1.1",
"validator": "^13.7.0"
},
"devDependencies": {
Expand Down
54 changes: 39 additions & 15 deletions src/external/switcher-api-facade.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Switcher, checkNumeric, checkValue } from 'switcher-client';
import { Switcher, checkValue, checkPayload } from 'switcher-client';
import { EnvType } from '../models/environment';
import { BadRequestError, FeatureUnavailableError } from '../exceptions';
import { getDomainById, getTotalDomainsByOwner } from '../services/domain';
Expand Down Expand Up @@ -47,8 +47,11 @@ export async function checkDomain(req) {

const total = await getTotalDomainsByOwner(req.admin._id);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`domain#${req.admin._id}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'domain',
owner: req.admin._id,
total
}))
]), 'Domain limit has been reached.');
}

Expand All @@ -58,8 +61,11 @@ export async function checkGroup(domain) {

const total = await getTotalGroupsByDomainId(domain._id);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`group#${domain.owner}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'group',
owner: domain.owner,
total
}))
]), 'Group limit has been reached.');
}

Expand All @@ -70,8 +76,11 @@ export async function checkSwitcher(group) {
const total = await getTotalConfigsByDomainId(group.domain);
const { owner } = await getDomainById(group.domain);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`switcher#${owner}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'switcher',
owner,
total
}))
]), 'Switcher limit has been reached.');
}

Expand All @@ -82,8 +91,11 @@ export async function checkComponent(domain) {
const total = await getTotalComponentsByDomainId(domain);
const { owner } = await getDomainById(domain);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`component#${owner}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'component',
owner,
total
}))
]), 'Component limit has been reached.');
}

Expand All @@ -94,8 +106,11 @@ export async function checkEnvironment(domain) {
const total = await getTotalEnvByDomainId(domain);
const { owner } = await getDomainById(domain);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`environment#${owner}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'environment',
owner,
total
}))
]), 'Environment limit has been reached.');
}

Expand All @@ -106,8 +121,11 @@ export async function checkTeam(domain) {
const total = await getTotalTeamsByDomainId(domain);
const { owner } = await getDomainById(domain);
switcherFlagResult(await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`team#${owner}`),
checkNumeric(String(total))
checkPayload(JSON.stringify({
feature: 'team',
owner,
total
}))
]), 'Team limit has been reached.');
}

Expand All @@ -117,7 +135,10 @@ export async function checkMetrics(config) {

const { owner } = await getDomainById(config.domain);
const flag = await checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`metrics#${owner}`)
checkPayload(JSON.stringify({
feature: 'metrics',
owner
}))
]);

if (!flag) {
Expand All @@ -138,7 +159,10 @@ export async function checkHistory(domain) {

const { owner } = await getDomainById(domain);
return checkFeature(SwitcherKeys.ELEMENT_CREATION, [
checkValue(`history#${owner}`)
checkPayload(JSON.stringify({
feature: 'history',
owner
}))
]);
}

Expand Down

0 comments on commit 46ccf09

Please sign in to comment.