Semaphore/lib/routes/playbook/playbooks.js

47 lines
915 B
JavaScript
Raw Normal View History

2014-08-24 23:00:05 +02:00
var models = require('../../models')
2014-08-25 01:02:34 +02:00
var mongoose = require('mongoose')
var playbook = require('./playbook')
2014-08-24 23:00:05 +02:00
exports.unauthorized = function (app, template) {
template([
'add'
], {
prefix: 'playbook'
});
2014-08-25 01:02:34 +02:00
playbook.unauthorized(app, template);
2014-08-24 23:00:05 +02:00
}
2014-08-25 01:02:34 +02:00
exports.httpRouter = function (app) {
playbook.httpRouter(app);
2014-08-24 23:00:05 +02:00
}
exports.router = function (app) {
app.get('/playbooks', getPlaybooks)
2014-08-25 01:02:34 +02:00
.post('/playbooks', addPlaybook)
playbook.router(app);
2014-08-24 23:00:05 +02:00
}
function getPlaybooks (req, res) {
models.Playbook.find({
2014-08-25 01:02:34 +02:00
}).sort('-created').exec(function (err, playbooks) {
2014-08-24 23:00:05 +02:00
res.send(playbooks)
})
2014-08-25 01:02:34 +02:00
}
function addPlaybook (req, res) {
var playbook = new models.Playbook({
name: req.body.name,
location: req.body.location,
vault_password: req.body.vault_password
})
try {
playbook.credential = mongoose.Types.ObjectId(req.body.credential)
} catch (e) {}
playbook.save(function () {
res.send(201);
})
2014-08-24 23:00:05 +02:00
}