1
0
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:
ivaosthu 2016-11-13 22:25:14 +01:00
parent 9b277f29b9
commit ac2072971f
3 changed files with 34 additions and 20 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,16 @@ import { throwIfNotSuccess, headers } from './helper';
const URI = '/api/features';
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 () {
return fetch(URI)
.then(throwIfNotSuccess)
@ -10,11 +20,13 @@ function fetchAll () {
}
function create (featureToggle) {
return fetch(URI, {
method: 'POST',
headers,
body: JSON.stringify(featureToggle),
}).then(throwIfNotSuccess);
return validateToggle(featureToggle)
.then(() => fetch(URI, {
method: 'POST',
headers,
body: JSON.stringify(featureToggle),
}))
.then(throwIfNotSuccess);
}
function validate (featureToggle) {
@ -26,11 +38,13 @@ function validate (featureToggle) {
}
function update (featureToggle) {
return fetch(`${URI}/${featureToggle.name}`, {
method: 'PUT',
headers,
body: JSON.stringify(featureToggle),
}).then(throwIfNotSuccess);
return validateToggle(featureToggle)
.then(() => fetch(`${URI}/${featureToggle.name}`, {
method: 'PUT',
headers,
body: JSON.stringify(featureToggle),
}))
.then(throwIfNotSuccess);
}
function remove (featureToggleName) {