Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,7 @@ module.exports = {
"NOT_ELIGIBLE_FOR_CERTIFICATE" : "Project is not eligible for certificate",
"ISSUER_KID_NOT_FOUND" : "Failed to fetch certificate issuer kid",
"PROJECT_SUBMITTED_FOR_REISSUE" : "Submitted for project certificate reIssue",
"FAILED_TO_START_RESOURCE": "There was an error in starting/joining. Please try again after some time."
"FAILED_TO_START_RESOURCE": "There was an error in starting/joining. Please try again after some time.",
"REQUIRED_PROGRAM_ID": "Required program id",

};
28 changes: 26 additions & 2 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ module.exports = class UserProjectsHelper {
"entityInformation._id",
"lastDownloadedAt",
"appInformation",
"status"
"status",
"programId",
"isAPrivateProgram"
]);

if (!userProject.length > 0) {
Expand Down Expand Up @@ -158,6 +160,19 @@ module.exports = class UserProjectsHelper {
}
let createNewProgramAndSolution = false;
let solutionExists = false;

if (
(userProject[0].programId && !data.programId) ||
(userProject[0].solutionInformation?._id && !data.solutionId)
) {
throw {
status: HTTP_STATUS_CODE['bad_request'].status,
message:
userProject[0].programId && !data.programId
? CONSTANTS.apiResponses.REQUIRED_PROGRAM_ID
: CONSTANTS.apiResponses.REQUIRED_SOLUTION_ID
};
}

if (data.programId && data.programId !== "") {

Expand Down Expand Up @@ -229,7 +244,7 @@ module.exports = class UserProjectsHelper {
return resolve(programAndSolutionInformation);
}

if (solutionExists) {
if (solutionExists && userProject[0].isAPrivateProgram) {

let updateProgram =
await surveyService.removeSolutionsFromProgram(
Expand Down Expand Up @@ -361,6 +376,15 @@ module.exports = class UserProjectsHelper {
if ( data.status == CONSTANTS.common.COMPLETED_STATUS || data.status == CONSTANTS.common.SUBMITTED_STATUS ) {
updateProject.completedDate = new Date();
}

// remove restricted keys
updateProject = _.omit(updateProject, [
"programInformation",
"solutionInformation",
"programId",
"solutionId"
]);


let projectUpdated =
await projectQueries.findOneAndUpdate(
Expand Down