Skip to content

Commit

Permalink
fix(api,update): isDocExist return empty object
Browse files Browse the repository at this point in the history
- Change async function
- using await on mongodb find
  • Loading branch information
Chinlinlee committed Jan 27, 2022
1 parent 1624240 commit 630ac3d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions api/FHIRApiService/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,9 @@ module.exports = async function (req, res, resourceType) {
return resFunc[status](result);
};

function isDocExist(id,resourceType) {
mongodb[resourceType].findOne({
id: id
}, async function (err, doc) {
if (err) {
return {
status: 0,
error: err
}; //error
}
async function isDocExist(id,resourceType) {
try {
let doc = await mongodb[resourceType].findOne({ id: id });
if (doc) {
return {
status: 1,
Expand All @@ -119,7 +112,12 @@ function isDocExist(id,resourceType) {
error: ""
}; //no doc
}
});
} catch(e) {
return {
status: 0,
error: e
}; //error
}
}

function doUpdateData(req,resourceType) {
Expand Down

0 comments on commit 630ac3d

Please sign in to comment.