1- import { Switcher , checkNumeric , checkValue } from 'switcher-client' ;
1+ import { Switcher , checkValue , checkPayload } from 'switcher-client' ;
22import { EnvType } from '../models/environment' ;
33import { BadRequestError , FeatureUnavailableError } from '../exceptions' ;
44import { getDomainById , getTotalDomainsByOwner } from '../services/domain' ;
@@ -47,8 +47,11 @@ export async function checkDomain(req) {
4747
4848 const total = await getTotalDomainsByOwner ( req . admin . _id ) ;
4949 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
50- checkValue ( `domain#${ req . admin . _id } ` ) ,
51- checkNumeric ( String ( total ) )
50+ checkPayload ( JSON . stringify ( {
51+ feature : 'domain' ,
52+ owner : req . admin . _id ,
53+ total
54+ } ) )
5255 ] ) , 'Domain limit has been reached.' ) ;
5356}
5457
@@ -58,8 +61,11 @@ export async function checkGroup(domain) {
5861
5962 const total = await getTotalGroupsByDomainId ( domain . _id ) ;
6063 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
61- checkValue ( `group#${ domain . owner } ` ) ,
62- checkNumeric ( String ( total ) )
64+ checkPayload ( JSON . stringify ( {
65+ feature : 'group' ,
66+ owner : domain . owner ,
67+ total
68+ } ) )
6369 ] ) , 'Group limit has been reached.' ) ;
6470}
6571
@@ -70,8 +76,11 @@ export async function checkSwitcher(group) {
7076 const total = await getTotalConfigsByDomainId ( group . domain ) ;
7177 const { owner } = await getDomainById ( group . domain ) ;
7278 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
73- checkValue ( `switcher#${ owner } ` ) ,
74- checkNumeric ( String ( total ) )
79+ checkPayload ( JSON . stringify ( {
80+ feature : 'switcher' ,
81+ owner,
82+ total
83+ } ) )
7584 ] ) , 'Switcher limit has been reached.' ) ;
7685}
7786
@@ -82,8 +91,11 @@ export async function checkComponent(domain) {
8291 const total = await getTotalComponentsByDomainId ( domain ) ;
8392 const { owner } = await getDomainById ( domain ) ;
8493 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
85- checkValue ( `component#${ owner } ` ) ,
86- checkNumeric ( String ( total ) )
94+ checkPayload ( JSON . stringify ( {
95+ feature : 'component' ,
96+ owner,
97+ total
98+ } ) )
8799 ] ) , 'Component limit has been reached.' ) ;
88100}
89101
@@ -94,8 +106,11 @@ export async function checkEnvironment(domain) {
94106 const total = await getTotalEnvByDomainId ( domain ) ;
95107 const { owner } = await getDomainById ( domain ) ;
96108 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
97- checkValue ( `environment#${ owner } ` ) ,
98- checkNumeric ( String ( total ) )
109+ checkPayload ( JSON . stringify ( {
110+ feature : 'environment' ,
111+ owner,
112+ total
113+ } ) )
99114 ] ) , 'Environment limit has been reached.' ) ;
100115}
101116
@@ -106,8 +121,11 @@ export async function checkTeam(domain) {
106121 const total = await getTotalTeamsByDomainId ( domain ) ;
107122 const { owner } = await getDomainById ( domain ) ;
108123 switcherFlagResult ( await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
109- checkValue ( `team#${ owner } ` ) ,
110- checkNumeric ( String ( total ) )
124+ checkPayload ( JSON . stringify ( {
125+ feature : 'team' ,
126+ owner,
127+ total
128+ } ) )
111129 ] ) , 'Team limit has been reached.' ) ;
112130}
113131
@@ -117,7 +135,10 @@ export async function checkMetrics(config) {
117135
118136 const { owner } = await getDomainById ( config . domain ) ;
119137 const flag = await checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
120- checkValue ( `metrics#${ owner } ` )
138+ checkPayload ( JSON . stringify ( {
139+ feature : 'metrics' ,
140+ owner
141+ } ) )
121142 ] ) ;
122143
123144 if ( ! flag ) {
@@ -138,7 +159,10 @@ export async function checkHistory(domain) {
138159
139160 const { owner } = await getDomainById ( domain ) ;
140161 return checkFeature ( SwitcherKeys . ELEMENT_CREATION , [
141- checkValue ( `history#${ owner } ` )
162+ checkPayload ( JSON . stringify ( {
163+ feature : 'history' ,
164+ owner
165+ } ) )
142166 ] ) ;
143167}
144168
0 commit comments