converted file, script, search and sender routes

This commit is contained in:
azivner
2018-03-30 17:29:13 -04:00
parent aa57a64c61
commit cfe0ae1eda
6 changed files with 114 additions and 106 deletions

View File

@@ -1,55 +1,56 @@
"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
const wrap = require('express-promise-wrap').wrap;
const labels = require('../../services/labels');
const script = require('../../services/script');
const Repository = require('../../services/repository');
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
async function exec(req) {
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
res.send({
return {
executionResult: ret
});
}));
};
}
router.post('/run/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
async function run(req) {
const repository = new Repository(req);
const note = await repository.getNote(req.params.noteId);
const ret = await script.executeNote(req, note);
res.send({
return {
executionResult: ret
});
}));
};
}
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
async function getStartupBundles(req) {
const repository = new Repository(req);
const notes = await labels.getNotesWithLabel(repository, "run", "frontend_startup");
const scripts = [];
const bundles = [];
for (const note of notes) {
const bundle = await script.getScriptBundle(note);
if (bundle) {
scripts.push(bundle);
bundles.push(bundle);
}
}
res.send(scripts);
}));
return bundles;
}
router.get('/bundle/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
async function getBundle(req) {
const repository = new Repository(req);
const note = await repository.getNote(req.params.noteId);
const bundle = await script.getScriptBundle(note);
res.send(bundle);
}));
return bundle;
}
module.exports = router;
module.exports = {
exec,
run,
getStartupBundles,
getBundle
};