1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Implemented server side API for deleting strategies.

relates to #60
This commit is contained in:
ivaosthu 2014-12-08 20:56:22 +01:00 committed by Ivar Conradi Østhus
parent fc42827641
commit c20252d9d7
5 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
featureCreated : 'feature-created', featureCreated : 'feature-created',
featureUpdated : 'feature-updated', featureUpdated : 'feature-updated',
strategyCreated: 'strategy-created' strategyCreated: 'strategy-created',
strategyDeleted: 'strategy-deleted'
}; };

View File

@ -16,6 +16,18 @@ module.exports = function (app) {
.catch(function () { res.json(404, {error: 'Could not find strategy'}); }); .catch(function () { res.json(404, {error: 'Could not find strategy'}); });
}); });
app.delete('/strategies/:name', function (req, res) {
eventStore.create({
type: eventType.strategyDeleted,
createdBy: req.connection.remoteAddress,
data: {
name: req.params.name
}
})
.then(function () { res.status(200).end(); })
.catch(function () { res.status(500).end(); });
});
app.post('/strategies', function (req, res) { app.post('/strategies', function (req, res) {
req.checkBody('name', 'Name is required').notEmpty(); req.checkBody('name', 'Name is required').notEmpty();
req.checkBody('name', 'Name must match format ^[a-zA-Z\\.\\-]+$').matches(/^[a-zA-Z\\.\\-]+$/i); req.checkBody('name', 'Name must match format ^[a-zA-Z\\.\\-]+$').matches(/^[a-zA-Z\\.\\-]+$/i);

View File

@ -12,6 +12,15 @@ eventStore.on(eventType.strategyCreated, function (event) {
}); });
}); });
eventStore.on(eventType.strategyDeleted, function (event) {
knex('strategies')
.where('name', event.data.name)
.del()
.catch(function (err) {
logger.error('Could not delete strategy, error was: ', err);
});
});
function getStrategies() { function getStrategies() {
return knex return knex
.select(STRATEGY_COLUMNS) .select(STRATEGY_COLUMNS)

View File

@ -44,5 +44,9 @@ describe('The strategy api', function () {
.expect(403, done); .expect(403, done);
}); });
it('deletes a new strategy', function (done) {
request
.delete('/strategies/deletable')
.expect(200, done);
});
}); });

View File

@ -11,6 +11,10 @@ var strategies = [
parametersTemplate: { parametersTemplate: {
emails: "String" emails: "String"
} }
},
{
name: "deletable",
description: "deletable"
} }
]; ];