maestro/app/services/routines.service.js
2020-04-15 09:11:10 -05:00

31 lines
903 B
JavaScript

const { Service } = require('flitter-di')
const Routine = require('../classes/routine/Routine')
/*
* routines Service
* -------------------------------------------------------------
* This is a service file that will be made available through Flitter's
* dependency injector to the rest of the application based on its given
* canonical name.
*
* e.g. app.di().service("routines")
*/
class RoutinesService extends Service {
static get services() {
return [...super.services, 'app', 'configs', 'hosts']
}
async get(name) {
this.app.make(Routine)
const config = this.configs.get(`routines:${name}`)
const hosts = {}
for ( const host_name of config.hosts ) {
hosts[host_name] = await this.hosts.get(host_name)
}
return new Routine(hosts, config, config.type)
}
}
module.exports = exports = RoutinesService