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
parent a96ff2c614
commit c16f4a1867
5 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,6 @@
module.exports = {
featureCreated : 'feature-created',
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'}); });
});
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) {
req.checkBody('name', 'Name is required').notEmpty();
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() {
return knex
.select(STRATEGY_COLUMNS)

View File

@ -44,5 +44,9 @@ describe('The strategy api', function () {
.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: {
emails: "String"
}
},
{
name: "deletable",
description: "deletable"
}
];