mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Added validation: require at-least one strategy
This commit is contained in:
parent
9b277f29b9
commit
ac2072971f
18
frontend/dist/bundle.js
vendored
18
frontend/dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
2
frontend/dist/bundle.js.map
vendored
2
frontend/dist/bundle.js.map
vendored
File diff suppressed because one or more lines are too long
@ -3,6 +3,16 @@ import { throwIfNotSuccess, headers } from './helper';
|
|||||||
const URI = '/api/features';
|
const URI = '/api/features';
|
||||||
const URI_VALIDATE = '/api/features-validate';
|
const URI_VALIDATE = '/api/features-validate';
|
||||||
|
|
||||||
|
function validateToggle (featureToggle) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!featureToggle.strategies || featureToggle.strategies.length === 0) {
|
||||||
|
reject(new Error('You must add at least one activation strategy'));
|
||||||
|
} else {
|
||||||
|
resolve(featureToggle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function fetchAll () {
|
function fetchAll () {
|
||||||
return fetch(URI)
|
return fetch(URI)
|
||||||
.then(throwIfNotSuccess)
|
.then(throwIfNotSuccess)
|
||||||
@ -10,11 +20,13 @@ function fetchAll () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function create (featureToggle) {
|
function create (featureToggle) {
|
||||||
return fetch(URI, {
|
return validateToggle(featureToggle)
|
||||||
method: 'POST',
|
.then(() => fetch(URI, {
|
||||||
headers,
|
method: 'POST',
|
||||||
body: JSON.stringify(featureToggle),
|
headers,
|
||||||
}).then(throwIfNotSuccess);
|
body: JSON.stringify(featureToggle),
|
||||||
|
}))
|
||||||
|
.then(throwIfNotSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate (featureToggle) {
|
function validate (featureToggle) {
|
||||||
@ -26,11 +38,13 @@ function validate (featureToggle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function update (featureToggle) {
|
function update (featureToggle) {
|
||||||
return fetch(`${URI}/${featureToggle.name}`, {
|
return validateToggle(featureToggle)
|
||||||
method: 'PUT',
|
.then(() => fetch(`${URI}/${featureToggle.name}`, {
|
||||||
headers,
|
method: 'PUT',
|
||||||
body: JSON.stringify(featureToggle),
|
headers,
|
||||||
}).then(throwIfNotSuccess);
|
body: JSON.stringify(featureToggle),
|
||||||
|
}))
|
||||||
|
.then(throwIfNotSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove (featureToggleName) {
|
function remove (featureToggleName) {
|
||||||
|
Loading…
Reference in New Issue
Block a user