Skip to content

Commit c9ecf67

Browse files
authored
Merge pull request #201 from borkarsaish65/bugfix/program_listing
Bugfix/program listing
2 parents 10206f0 + dc4a144 commit c9ecf67

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

module/programs/helper.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,9 @@ module.exports = class ProgramsHelper {
433433
return new Promise( async (resolve, reject) => {
434434

435435
try {
436-
437436
let programDocument = [];
438437

439-
let matchQuery = { status : constants.common.ACTIVE };
438+
let matchQuery = { status: constants.common.ACTIVE };
440439

441440
if( Object.keys(filter).length > 0 ) {
442441
matchQuery = _.merge(matchQuery,filter);
@@ -498,6 +497,8 @@ module.exports = class ProgramsHelper {
498497

499498
programDocument.push({ $match : matchQuery }, sortQuery,{ $project : projection1 }, facetQuery, projection2);
500499

500+
501+
501502
let programDocuments =
502503
await database.models.programs.aggregate(programDocument);
503504

@@ -529,7 +530,7 @@ module.exports = class ProgramsHelper {
529530
* @returns {JSON} - List of programs based on role and location.
530531
*/
531532

532-
static forUserRoleAndLocation( bodyData, pageSize, pageNo,searchText = "" ) {
533+
static forUserRoleAndLocation( bodyData, pageSize, pageNo,searchText = "",programId = "" ) {
533534

534535
return new Promise(async (resolve, reject) => {
535536

@@ -542,6 +543,12 @@ module.exports = class ProgramsHelper {
542543
if( !queryData.success ) {
543544
return resolve(queryData);
544545
}
546+
547+
if (programId !== "") {
548+
queryData.data._id = gen.utils.convertStringToObjectId(programId);
549+
}
550+
queryData.data.startDate = { $lte: new Date() };
551+
queryData.data.endDate = { $gte: new Date() };
545552

546553
let targetedPrograms = await this.list(
547554
pageNo,

module/solutions/helper.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,20 @@ module.exports = class SolutionsHelper {
711711
matchQuery["$or"] = [];
712712

713713
targetedTypes.forEach( type => {
714-
715-
let singleType = {
716-
type : type
717-
};
714+
let singleType = {};
715+
if (type === constants.common.SURVEY) {
716+
singleType = {
717+
type: type,
718+
};
719+
const currentDate = new Date();
720+
currentDate.setDate(currentDate.getDate() - 15);
721+
singleType["endDate"] = { $gte: currentDate };
722+
} else {
723+
singleType = {
724+
type: type,
725+
};
726+
singleType["endDate"] = { $gte: new Date() };
727+
}
718728

719729
if( type === constants.common.IMPROVEMENT_PROJECT ) {
720730
singleType["projectTemplateId"] = { $exists : true };
@@ -727,7 +737,15 @@ module.exports = class SolutionsHelper {
727737
if( type !== "" ) {
728738
matchQuery["type"] = type;
729739
}
730-
740+
741+
if (type === constants.common.SURVEY) {
742+
const currentDate = new Date();
743+
currentDate.setDate(currentDate.getDate() - 15);
744+
matchQuery["endDate"] = { $gte: currentDate };
745+
} else {
746+
matchQuery["endDate"] = { $gte: new Date() };
747+
}
748+
731749
if( subType !== "" ) {
732750
matchQuery["subType"] = subType;
733751
}
@@ -737,6 +755,8 @@ module.exports = class SolutionsHelper {
737755
matchQuery["programId"] = ObjectId(programId);
738756
}
739757

758+
matchQuery["startDate"] = { $lte: new Date() };
759+
740760
let targetedSolutions = await this.list(
741761
type,
742762
subType,
@@ -901,7 +921,8 @@ module.exports = class SolutionsHelper {
901921
"language",
902922
"creator",
903923
"link",
904-
"certificateTemplateId"
924+
"certificateTemplateId",
925+
"endDate"
905926
]
906927
);
907928

0 commit comments

Comments
 (0)