Skip to content

Commit

Permalink
Merge pull request #56 from priyanka-TL/projectSubmissionFix
Browse files Browse the repository at this point in the history
project submission fix
  • Loading branch information
aks30 authored Jan 12, 2022
2 parents 7fdc0cd + b781083 commit ead7506
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
3 changes: 2 additions & 1 deletion generics/kafka/consumers/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var messageReceived = function (message) {
try {

let parsedMessage = JSON.parse(message.value);

console.log(parsedMessage ,"messageReceived from kafka")
let submissionDocument = {
"_id" : parsedMessage._id.toString(),
"status" : parsedMessage.status,
Expand Down Expand Up @@ -59,6 +59,7 @@ var errorTriggered = function (error) {
return new Promise(function (resolve, reject) {

try {
console.log(error ,"errorTriggered from kafka")
return resolve(error);
} catch (error) {
return reject(error);
Expand Down
69 changes: 27 additions & 42 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,64 +803,49 @@ module.exports = class UserProjectsHelper {
return new Promise(async (resolve, reject) => {
try {

let update = {};
let tasksUpdated;
let updateSubmission = [];

let projectDocument = await projectQueries.projectDocument(
{
_id: projectId,
"tasks._id": taskId
}, [
"tasks.$.submissions"
"tasks"
]);

let tasks = projectDocument[0].tasks;
if ( tasks && tasks.length > 0 ) {
tasks = projectDocument[0].tasks[0];
}

let submissions = tasks.submissions;
let pushToSubmissionArray = false;

if ( !submissions && !submissions.length > 0 ){
pushToSubmissionArray = true;
}

let checkSubmissionExist = submissions.filter(submission => submission._id == updatedData._id);

if ( !checkSubmissionExist.length > 0 ) {
pushToSubmissionArray = true;
let currentTask = projectDocument[0].tasks.find(task => task._id == taskId);
let submissions = currentTask.submissions && currentTask.submissions.length > 0 ? currentTask.submissions : [] ;

// if submission array is empty
if ( !submissions && !submissions.length > 0 ) {
updateSubmission.push(updatedData);
}

// submission not exist
let checkSubmissionExist = submissions.findIndex(submission => submission._id == updatedData._id);

if ( pushToSubmissionArray === true ) {

update["tasks.$." + "submissions"] = updatedData;
if ( checkSubmissionExist == -1 ) {

tasksUpdated =
await projectQueries.findOneAndUpdate({
_id: projectId,
"tasks._id": taskId
}, { $push: update });
updateSubmission = submissions;
updateSubmission.push(updatedData);

} else {
//submission exist
submissions[checkSubmissionExist] = updatedData;
updateSubmission = submissions;
}

const index = submissions.indexOf(checkSubmissionExist[0]);

if ( submissions[index].status !== CONSTANTS.common.COMPLETED_STATUS ) {
submissions[index] = updatedData;
}

update["tasks.$." + "submissions"] = submissions;
tasksUpdated =
await projectQueries.findOneAndUpdate({
_id: projectId,
"tasks._id": taskId
}, { $set: update });
let tasksUpdated = await projectQueries.findOneAndUpdate({
"_id": projectId,
"tasks._id": taskId
}, {
$set: {
"tasks.$.submissions": updateSubmission
}
});

}

return resolve(tasksUpdated);

} catch (error) {
return reject(error);
}
Expand Down

0 comments on commit ead7506

Please sign in to comment.