Skip to content

Commit

Permalink
Merge pull request #75 from shikshalokam/observationFix
Browse files Browse the repository at this point in the history
observation profile information fix
  • Loading branch information
aks30 authored Mar 16, 2022
2 parents ec56745 + 012a468 commit 8837638
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
9 changes: 8 additions & 1 deletion controllers/v1/observationSubmissionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,17 @@ module.exports = class ObservationSubmissions extends Abstract {
if( solutionDocument.hasOwnProperty("criteriaLevelReport") ) {
submissionDocument["criteriaLevelReport"] = solutionDocument["criteriaLevelReport"];
}
if( observationDocument.userRoleInformation ){
if( observationDocument.userRoleInformation && Object.keys(observationDocument.userRoleInformation).length > 0 ){
submissionDocument.userRoleInformation = observationDocument.userRoleInformation;
} else if( req.body && req.body.role && !observationDocument.userRoleInformation ){
submissionDocument.userRoleInformation = req.body;
let updateObservation = await observationsHelper.updateObservationDocument
(
{ _id: req.params._id },
{
$set: { userRoleInformation : req.body }
}
)
}


Expand Down
10 changes: 9 additions & 1 deletion controllers/v1/observationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,11 +1173,19 @@ module.exports = class Observations extends Abstract {


//}
if( observationDocument.userRoleInformation ){
if( observationDocument.userRoleInformation && Object.keys(observationDocument.userRoleInformation).length > 0 ) {
submissionDocument.userRoleInformation = observationDocument.userRoleInformation;
} else if( req.body && req.body.role && !observationDocument.userRoleInformation ){
submissionDocument.userRoleInformation = req.body;
let updateObservation = await observationsHelper.updateObservationDocument
(
{ _id: req.params._id },
{
$set: { userRoleInformation : req.body }
}
)
}

if( solutionDocument.referenceFrom === messageConstants.common.PROJECT ) {
submissionDocument["referenceFrom"] = messageConstants.common.PROJECT;
submissionDocument["project"] = solutionDocument.project;
Expand Down
57 changes: 53 additions & 4 deletions module/observations/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module.exports = class ObservationsHelper {
"updatedBy": userId,
"createdBy": userId,
"isAPrivateProgram" : solution.isAPrivateProgram,
"userRoleInformation" : userRoleInformation ? userRoleInformation : ""
"userRoleInformation" : userRoleInformation ? userRoleInformation : {}
})
);

Expand Down Expand Up @@ -1624,12 +1624,12 @@ module.exports = class ObservationsHelper {
solutionId : solutionId,
createdBy : userId
},["_id"]);

if( observationData.length > 0 ) {
observationId = observationData[0]._id;
} else {

let solutionData =
let solutionData =
await coreService.solutionDetailsBasedOnRoleAndLocation(
token,
bodyData,
Expand Down Expand Up @@ -1670,7 +1670,9 @@ module.exports = class ObservationsHelper {
solutionId,
solutionData.data,
userId,
token
token,
"",
bodyData
);

observationId = observation._id;
Expand Down Expand Up @@ -1923,4 +1925,51 @@ module.exports = class ObservationsHelper {

}

/**
* Update observation document.
* @method
* @name updateObservationDocument
* @param {Object} query - query to find document
* @param {Object} updateObject - fields to update
* @returns {String} - message.
*/

static updateObservationDocument(query= {}, updateObject= {}) {
return new Promise(async (resolve, reject) => {
try {

if (Object.keys(query).length == 0) {
throw new Error(messageConstants.apiResponses.UPDATE_QUERY_REQUIRED)
}

if (Object.keys(updateObject).length == 0) {
throw new Error (messageConstants.apiResponses.UPDATE_OBJECT_REQUIRED)
}

let updateResponse = await database.models.observations.updateOne
(
query,
updateObject
)

if (updateResponse.nModified == 0) {
throw new Error(messageConstants.apiResponses.FAILED_TO_UPDATE)
}

return resolve({
success: true,
message: messageConstants.apiResponses.UPDATED_DOCUMENT_SUCCESSFULLY,
data: true
});

} catch (error) {
return resolve({
success: false,
message: error.message,
data: false
});
}
});
}

};

0 comments on commit 8837638

Please sign in to comment.