nci/resources/builds.js

52 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-04-10 19:23:52 +00:00
'use strict';
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
db = require('../db');
module.exports = function(app) {
var resource = app.dataio.resource('builds');
2015-04-10 19:23:52 +00:00
2015-07-05 17:18:51 +00:00
resource.use('readAll', function(req, res, next) {
Steppy(
function() {
2015-07-09 20:12:24 +00:00
var data = req.data || {};
var start = {};
if (data.projectName) {
start.projectName = data.projectName;
}
if (data.descCreateDate) {
start.descCreateDate = data.descCreateDate;
}
var findParams = _(data).pick('offset', 'limit');
findParams.start = start;
findParams.limit = findParams.limit || 20;
db.builds.find(findParams, this.slot());
},
function(err, builds) {
res.send(builds);
},
2015-07-05 17:18:51 +00:00
next
);
});
2015-07-05 17:18:51 +00:00
resource.use('read', function(req, res, next) {
2015-05-17 13:48:16 +00:00
Steppy(
function() {
var findParams = {};
findParams.start = _(req.data).pick('id');
db.builds.find(findParams, this.slot());
},
function(err, build) {
res.send(build[0]);
},
2015-07-05 17:18:51 +00:00
next
2015-05-17 13:48:16 +00:00
);
});
return resource;
2015-04-10 19:23:52 +00:00
};