From 630ac3d01721137833c52e9816bb0fa0ea939c7a Mon Sep 17 00:00:00 2001 From: chin Date: Fri, 28 Jan 2022 00:58:28 +0800 Subject: [PATCH] fix(api,update): `isDocExist` return empty object - Change async function - using await on mongodb find --- api/FHIRApiService/update.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/api/FHIRApiService/update.js b/api/FHIRApiService/update.js index 0ac833f0..df5e6d56 100644 --- a/api/FHIRApiService/update.js +++ b/api/FHIRApiService/update.js @@ -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, @@ -119,7 +112,12 @@ function isDocExist(id,resourceType) { error: "" }; //no doc } - }); + } catch(e) { + return { + status: 0, + error: e + }; //error + } } function doUpdateData(req,resourceType) {