Skip to content

Commit

Permalink
fixesthe bug that API to retrieve annotations returning status 404 #98
Browse files Browse the repository at this point in the history
  • Loading branch information
nanli-emory committed Mar 10, 2022
1 parent 6e7c751 commit f998cb2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ var HANDLERS = {
"advancedFindLabelingAnnotation": function() {
return dataHandlers.LabelingAnnotation.advancedFind;
},
"findByTypeOrCreator": function() {
return dataHandlers.LabelingAnnotation.findByTypeOrCreator;
},
};

if (!DISABLE_TF) {
Expand Down
13 changes: 12 additions & 1 deletion handlers/dataHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ User.wcido = function(req, res, next) {
}
};
var LabelingAnnotation = {};
LabelingAnnotation.findByTypeOrCreator = function(req, res, next) {
const {slideId, slideName, computation, creator} = req.query;
const query = {};
if (slideId) query["provenance.image.slide"] = slideId;
if (slideName) query["provenance.image.name"] = slideName;
if (computation) query["provenance.analysis.computation"] = computation;
if (creator) query["creator"] = creator;
mongoDB.find('camic', 'labelingAnnotation', query, true, {"geometries": 0}).then((x) => {
req.data = x;
next();
}).catch((e) => next(e));
};
LabelingAnnotation.advancedFind = async function(req, res, next) {
// get params -
// id - annotation id (_id)
Expand Down Expand Up @@ -379,7 +391,6 @@ LabelingAnnotation.advancedFind = async function(req, res, next) {
if (endDate) query.create_date['$lte'] = new Date(endDate);
}
mongoDB.find('camic', 'labelingAnnotation', query ).then((x) => {
console.log(x.length);
req.data = x;
next();
}).catch((e) => next(e));
Expand Down
7 changes: 3 additions & 4 deletions service/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Mongo {
*
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.find/ Read MongoDB Reference}
*/
static async find(database, collectionName, query, transform = true) {
static async find(database, collectionName, query, transform = true, projection) {
try {
query = transformIdToObjectId(query);

const collection = getConnection(database).collection(collectionName);
console.log('find', database, collectionName, query);
const data = await collection.find(query).toArray();

const data = projection ? await collection.find(query, projection).toArray():await collection.find(query).toArray();

/** allow caller method to toggle response transformation */
if (transform) {
Expand All @@ -42,7 +42,6 @@ class Mongo {
throw e;
}
}

/**
* Runs a distinct find operation based on given query
*
Expand Down

0 comments on commit f998cb2

Please sign in to comment.