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
2 changes: 2 additions & 0 deletions generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,6 @@ module.exports = {
"BASE_CERTIFICATE_TEMPLATE_NOT_FOUND" : "Base certificate template not found",
"CERTIFICATE_BASE_TEMPLATE_UPDATED" : "Base template updated successfully",
"CERTIFICATE_BASE_TEMPLATE_NOT_UPDATED" : "Base template updation failed",
"LINK_IS_NOT_ACTIVE_YET":'The link has not started yet. Please try again from: ' ,
"NO_SOLUTION_FOUND_FOR_THE_LINK": 'This link appears to be invalid. Please use a valid link to continue.',
};
3 changes: 2 additions & 1 deletion module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,10 @@ module.exports = class ProgramsHelper {
}
}

let caseInsensitiveRoles = [constants.common.ALL_ROLES,...data.role.split(",")].map(role => new RegExp(`^${role}$`, "i"));

let filterQuery = {
"scope.roles.code" : { $in : [constants.common.ALL_ROLES,...data.role.split(",")] },
"scope.roles.code" : { $in : caseInsensitiveRoles },
"scope.entities" : { $in : locationIds },
"isDeleted" : false,
status : constants.common.ACTIVE
Expand Down
72 changes: 57 additions & 15 deletions module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const improvementProjectService = require(ROOT_PATH + '/generics/services/improv
const appsPortalBaseUrl = process.env.APP_PORTAL_BASE_URL + "/" ;
const userExtensionsHelperV2 = require(MODULES_BASE_PATH + "/user-extension/helperv2");
const userService = require(ROOT_PATH + "/generics/services/users");
const timeZoneDifference =
process.env.TIMEZONE_DIFFRENECE_BETWEEN_LOCAL_TIME_AND_UTC;
const moment = require('moment-timezone');
const timeZoneDifference = process.env.TIMEZONE_DIFFRENECE_BETWEEN_LOCAL_TIME_AND_UTC;
/**
* SolutionsHelper
* @class
Expand Down Expand Up @@ -825,9 +825,11 @@ module.exports = class SolutionsHelper {
message : constants.apiResponses.NO_LOCATION_ID_FOUND_IN_DATA
}
}


let caseInsensitiveRoles = [constants.common.ALL_ROLES,...data.role.split(",")].map(role => new RegExp(`^${role}$`, "i"));

let filterQuery = {
"scope.roles.code" : { $in : [constants.common.ALL_ROLES,...data.role.split(",")] },
"scope.roles.code" : { $in : caseInsensitiveRoles },
"scope.entities" : { $in : registryIds },
"scope.entityType" : { $in : entityTypes },
"isReusable" : false,
Expand Down Expand Up @@ -1660,7 +1662,14 @@ module.exports = class SolutionsHelper {
userId,
userToken
);


if(verifySolution.returnError){
throw {
status : httpStatusCode["bad_request"].status,
message : verifySolution.message ? verifySolution.message : constants.apiResponses.INVALID_LINK
}
}

let checkForTargetedSolution = await this.checkForTargetedSolution(
link,
bodyData,
Expand All @@ -1672,7 +1681,7 @@ module.exports = class SolutionsHelper {
}

let solutionData = checkForTargetedSolution.result;

let isSolutionActive = solutionData.status === constants.common.INACTIVE ? false : true;
if( solutionData.type == constants.common.OBSERVATION ) {
// Targeted solution
if(checkForTargetedSolution.result.isATargetedSolution) {
Expand All @@ -1685,6 +1694,13 @@ module.exports = class SolutionsHelper {
checkForTargetedSolution.result["observationId"] = (observationDetailFromLink.result && observationDetailFromLink.result._id != "")
? observationDetailFromLink.result._id
: "";

if (
checkForTargetedSolution.result["observationId"] == "" &&
!isSolutionActive
) {
throw new Error(constants.apiResponses.LINK_IS_EXPIRED);
}

}

Expand Down Expand Up @@ -1735,7 +1751,19 @@ module.exports = class SolutionsHelper {
checkTargetedProjectExist.data[0]._id;
}

if (
!checkForTargetedSolution.result['projectId'] &&
!isSolutionActive
) {
throw new Error(constants.apiResponses.LINK_IS_EXPIRED);
}

} else {

if(!isSolutionActive) {
throw new Error(constants.apiResponses.LINK_IS_EXPIRED);
}

//non targeted project exist
let checkIfUserProjectExistsQuery = {
createdBy: userId,
Expand Down Expand Up @@ -1804,28 +1832,35 @@ module.exports = class SolutionsHelper {
let solutionData = await this.solutionDocuments(
{
link: link,
isReusable: false,
status: {
$ne: constants.common.INACTIVE,
},
isReusable: false
},
["type", "status", "endDate"]
["type", "status", "endDate", "startDate"]
);

if ( !Array.isArray(solutionData) || solutionData.length < 1 ) {
return resolve({
message: constants.apiResponses.INVALID_LINK,
message: constants.apiResponses.NO_SOLUTION_FOUND_FOR_THE_LINK,
result: [],
returnError: true
});
}

if ( solutionData[0].status !== constants.common.ACTIVE ) {
return resolve({
message: constants.apiResponses.LINK_IS_EXPIRED,
message: constants.apiResponses.INVALID_LINK,
result: [],
});
}

// check start date is greater than current date
if(solutionData[0].startDate && new Date() < new Date(solutionData[0].startDate)){
return resolve({
message: constants.apiResponses.LINK_IS_NOT_ACTIVE_YET+moment(solutionData[0].startDate).utc().utcOffset(timeZoneDifference).add(1, "minute").format("ddd, D MMM YYYY, hh:mm A"),
result: [],
returnError:true
});
}

if (
solutionData[0].endDate &&
new Date() > new Date(solutionData[0].endDate)
Expand All @@ -1851,6 +1886,7 @@ module.exports = class SolutionsHelper {
return resolve({
message: constants.apiResponses.LINK_VERIFIED,
result: response,
success:true
});
}
catch (error) {
Expand Down Expand Up @@ -1892,7 +1928,8 @@ module.exports = class SolutionsHelper {
"_id",
"programId",
"name",
"projectTemplateId"
"projectTemplateId",
"status"
]);

let queryData = await this.queryBasedOnRoleAndLocation(bodyData);
Expand All @@ -1903,6 +1940,10 @@ module.exports = class SolutionsHelper {
queryData.data["link"] = link;
let matchQuery = queryData.data;

if (matchQuery.status) {
delete matchQuery.status
}

let solutionData = await this.solutionDocuments(matchQuery, [
"_id",
"link",
Expand All @@ -1918,7 +1959,7 @@ module.exports = class SolutionsHelper {
response.type = solutionDetails[0].type;
response.name = solutionDetails[0].name;
response.programId = solutionDetails[0].programId;

response.status = solutionDetails[0].status;
return resolve({
success: true,
message:
Expand All @@ -1931,6 +1972,7 @@ module.exports = class SolutionsHelper {
Object.assign(response, solutionData[0]);
response.solutionId = solutionData[0]._id;
response.projectTemplateId = solutionDetails[0].projectTemplateId ? solutionDetails[0].projectTemplateId : "";
response.status = solutionDetails[0].status;
delete response._id;

return resolve({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"cache-manager": "^2.9.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cheerio": "^1.0.0-rc.12",
"cheerio": "1.0.0-rc.12",
"cli-table": "^0.3.1",
"commander": "^2.20.0",
"cors": "^2.8.4",
Expand Down