2016-11-05 17:02:46 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
const NotFoundError = require('../../lib/error/notfound-error');
|
2016-11-13 15:41:35 +01:00
|
|
|
|
|
|
|
module.exports = () => {
|
2021-01-21 13:47:08 +01:00
|
|
|
const _strategies = [
|
|
|
|
{ name: 'default', editable: false, parameters: {}, deprecated: false },
|
|
|
|
];
|
2016-11-13 15:41:35 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
getStrategies: () => Promise.resolve(_strategies),
|
2019-03-14 17:56:02 +01:00
|
|
|
getEditableStrategies: () =>
|
|
|
|
Promise.resolve(_strategies.filter(s => s.editable)),
|
2017-06-28 10:20:22 +02:00
|
|
|
getStrategy: name => {
|
2016-12-13 13:59:52 +01:00
|
|
|
const strategy = _strategies.find(s => s.name === name);
|
|
|
|
if (strategy) {
|
|
|
|
return Promise.resolve(strategy);
|
|
|
|
}
|
2020-04-14 22:29:11 +02:00
|
|
|
return Promise.reject(new NotFoundError('Not found!'));
|
2016-12-13 13:59:52 +01:00
|
|
|
},
|
2021-01-18 12:32:19 +01:00
|
|
|
createStrategy: strat => _strategies.push(strat),
|
|
|
|
updateStrategy: strat => {
|
|
|
|
_strategies.splice(
|
|
|
|
_strategies.indexOf(({ name }) => name === strat.name),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
_strategies.push(strat);
|
|
|
|
},
|
|
|
|
importStrategy: strat => Promise.resolve(_strategies.push(strat)),
|
|
|
|
dropStrategies: () => _strategies.splice(0, _strategies.length),
|
|
|
|
deleteStrategy: strat =>
|
|
|
|
_strategies.splice(
|
|
|
|
_strategies.indexOf(({ name }) => name === strat.name),
|
|
|
|
1,
|
|
|
|
),
|
2021-01-21 13:47:08 +01:00
|
|
|
deprecateStrategy: ({ name }) => {
|
|
|
|
const deprecatedStrat = _strategies.find(s => s.name === name);
|
|
|
|
deprecatedStrat.deprecated = true;
|
|
|
|
_strategies.splice(
|
|
|
|
_strategies.indexOf(s => name === s.name),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
_strategies.push(deprecatedStrat);
|
|
|
|
},
|
|
|
|
reactivateStrategy: ({ name }) => {
|
|
|
|
const reactivatedStrat = _strategies.find(s => s.name === name);
|
|
|
|
reactivatedStrat.deprecated = false;
|
|
|
|
_strategies.splice(
|
|
|
|
_strategies.indexOf(s => name === s.name),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
_strategies.push(reactivatedStrat);
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
};
|
2016-11-05 17:02:46 +01:00
|
|
|
};
|