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 = '/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) {