Skip to content

Commit

Permalink
feat: add start endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowgate15 committed Aug 20, 2021
1 parent caf5c0e commit 620b614
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/controllers/api/v1/control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Boom = require('@hapi/boom');

async function checkJobName(ctx, next) {
const { jobName } = ctx.params;

if (jobName && !ctx.bree.config.jobs.some((j) => j.name === jobName))
return Boom.badData('Job name does not exist');

return next();
}

async function start(ctx) {
const { jobName } = ctx.params;

ctx.bree.start(jobName);

ctx.body = {};
}

module.exports = { checkJobName, start };
3 changes: 2 additions & 1 deletion app/controllers/api/v1/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const config = require('./config');
const jobs = require('./jobs');
const control = require('./control');

const test = (ctx) => {
ctx.body = { breeExists: Boolean(ctx.bree) };
};

module.exports = { config, test, jobs };
module.exports = { config, test, jobs, control };
5 changes: 5 additions & 0 deletions routes/api/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ router.get('/config', api.v1.config.get);
router.get('/jobs', api.v1.jobs.get);
router.post('/jobs', api.v1.jobs.add);

router.use(api.v1.control.checkJobName);

router.post('/start', api.v1.control.start);
router.post('/start/:jobName', api.v1.control.start);

module.exports = router;

0 comments on commit 620b614

Please sign in to comment.