2017-05-18 21:21:33 +03:00
|
|
|
const {
|
|
|
|
datacenter,
|
|
|
|
portal,
|
|
|
|
deploymentGroups,
|
|
|
|
services,
|
|
|
|
instances
|
|
|
|
} = require('./data.json');
|
|
|
|
|
|
|
|
const find = (query = {}) => item =>
|
|
|
|
Object.keys(query).every(key => item[key] === query[key]);
|
|
|
|
|
|
|
|
const cleanQuery = (q = {}) => JSON.parse(JSON.stringify(q));
|
|
|
|
|
|
|
|
const getServiceInstances = s =>
|
|
|
|
Object.assign({}, s, {
|
2017-05-31 19:09:06 +03:00
|
|
|
instances: instances.filter(find({ service: s.id })).map(s =>
|
2017-05-18 21:21:33 +03:00
|
|
|
Object.assign({}, s, {
|
|
|
|
slug: s.name
|
|
|
|
})
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
const getDeploymentGroupServices = dg =>
|
|
|
|
Object.assign({}, dg, {
|
|
|
|
services: services
|
2017-05-31 19:09:06 +03:00
|
|
|
.filter(find({ deploymentGroup: dg.id }))
|
2017-05-18 21:21:33 +03:00
|
|
|
.map(getServiceInstances)
|
|
|
|
});
|
|
|
|
|
|
|
|
const getDeploymentGroups = query =>
|
|
|
|
deploymentGroups
|
|
|
|
.filter(find(cleanQuery(query)))
|
|
|
|
.map(getDeploymentGroupServices);
|
|
|
|
|
2017-05-31 19:09:06 +03:00
|
|
|
const getPortal = () => Object.assign({}, portal, {
|
|
|
|
datacenter,
|
|
|
|
deploymentGroups: getDeploymentGroups()
|
|
|
|
});
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
const getServices = query =>
|
|
|
|
services.filter(find(query)).map(getDeploymentGroupServices);
|
|
|
|
|
|
|
|
module.exports = {
|
2017-05-31 19:09:06 +03:00
|
|
|
portal: (options, request, fn) => fn(null, getPortal()),
|
|
|
|
deploymentGroups: (options, request, fn) => fn(null, getDeploymentGroups(options)),
|
|
|
|
deploymentGroup: (options, request, fn) => fn(null, getDeploymentGroups(options).shift()),
|
|
|
|
services: (options, request, fn) => fn(null, getServices()),
|
|
|
|
service: (options, request, fn) => fn(null, getServices(options).shift())
|
2017-05-18 21:21:33 +03:00
|
|
|
};
|