Commit 6579bbf6 authored by Severine Duvaud's avatar Severine Duvaud
Browse files

Implementing latest changes in the API spec

parent 7047dc4f
......@@ -176,12 +176,22 @@ function checkResultAndGetResponse(params, samples, countTotal) {
if (samples && samples.length > 0) { // a value was found by mongodb
responseResource.observed = samples.length;
// SD, May 2016: according to the specs, observed parameter was removed from BeaconDatasetAlleleResponse.
// We could divide the sample.length by the total number of samples in order to fill the frequency parameters
// for instance (and if of interest for arrayMap).
// responseResource.observed = samples.length;
responseResource.NOT_BEACON_numberMatchedSamples = samples.length;
var matchedSegments = samples.map(function (s) { return checkResult(params, s)});
if (!matchedSegments || !matchedSegments[0] || !matchedSegments[0].matchedSegment) {
responseResource.exists = null;
responseResource.error = "Internal error, DB returned a value but post check is not valid."
// BeaconError instead of simple string
// (error is not null if and only of exists is null)
responseResource.error = {
errorCode: 500,
message: "Internal error, DB returned a value but post check is not valid."
};
} else {
responseResource.exists = true;
responseResource.NOT_BEACON_ARRAYMAP_DEBUG_INFO = {"matchedSegments" : matchedSegments};
......
......@@ -54,8 +54,7 @@ router.get('/v0.2/query/', function (req, res) {
console.log("Building MongoDB query params: " + JSON.stringify(mongoQuery));
req.db.samples.count({'ICDMORPHOLOGYCODE': req.query.dataset}, function(err, count){
req.db.samples.find(mongoQuery, {}, function (err, docs){
req.db.samples.find(mongoQuery, {}, function (err, docs){
var response = beacon.checkResultAndGetResponse(req.query, docs, count);
response.NOT_BEACON_totalInDataSet = count;
res.json(response);
......@@ -77,8 +76,14 @@ router.get('/v0.3/query/', function (req, res) {
var mongoQuery = beacon.buildMongoQuery(req.query);
console.log("Building MongoDB query params: " + JSON.stringify(mongoQuery));
req.db.samples.count({'ICDMORPHOLOGYCODE': req.query.dataset}, function(err, count){
// Count: list of datasets (and not 1 dataset)
var orConditions = [];
var identifiers = req.query.datasetIds.split(','); // comma separated list of datasets
identifiers.forEach(function (id) {
orConditions.push({ICDMORPHOLOGYCODE: id});
});
req.db.samples.count({$or: orConditions}, function(err, count){
req.db.samples.find(mongoQuery, {}, function (err, docs){
var response = beacon.checkResultAndGetResponse(req.query, docs, count);
response.NOT_BEACON_totalInDataSet = count;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment