diff --git a/src/adapters/hasura/altAuth.adapter.ts b/src/adapters/hasura/altAuth.adapter.ts index 4900de17..89a661b8 100644 --- a/src/adapters/hasura/altAuth.adapter.ts +++ b/src/adapters/hasura/altAuth.adapter.ts @@ -11,8 +11,8 @@ export class HasuraAuthService { public async login(request: any, response: any, loginDto: ALTAuthDto) { const qs = require("qs"); const data = qs.stringify({ - username: loginDto.username, - password: loginDto.password, + username: loginDto.username.trim(), + password: loginDto.password.trim(), grant_type: "password", client_id: "hasura-app", client_secret: process.env.KEYCLOAK_HASURA_CLIENT_SECRET, diff --git a/src/adapters/hasura/altUserEligibility.adapter.ts b/src/adapters/hasura/altUserEligibility.adapter.ts index f8345ab0..3a8ae18c 100644 --- a/src/adapters/hasura/altUserEligibility.adapter.ts +++ b/src/adapters/hasura/altUserEligibility.adapter.ts @@ -22,7 +22,7 @@ export class ALTUserEligibilityService { private altModuleTrackingService: ALTModuleTrackingService, private altCourseTrackingService: ALTCourseTrackingService, private altUserService: ALTHasuraUserService - ) {} + ) { } public async checkEligibilityforCourse( request: any, @@ -101,10 +101,24 @@ export class ALTUserEligibilityService { userId ); + const skipBaseline = programRules.prog[0]?.skipBaseline ? true : false; + if ( !baselineAssessmentRecord?.data?.length && courseId === baselineAssessmentId ) { + if (skipBaseline) { + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: { + contentId: courseId, + contentType: programRules.prog[0].contentType, + msg: "Course " + courseId + " skipped.", + status: "unlocked", + }, + }); + } return new SuccessResponse({ statusCode: 200, message: "Ok.", @@ -117,7 +131,7 @@ export class ALTUserEligibilityService { }); } else if ( !baselineAssessmentRecord?.data?.length && - courseId !== baselineAssessmentId + courseId !== baselineAssessmentId && !skipBaseline ) { return new SuccessResponse({ statusCode: 200, @@ -211,6 +225,7 @@ export class ALTUserEligibilityService { } } if (course.criteria["1"]?.contentId && !baselineCriteriaFulfilled) { + // base criteria not fullfilled means user needs to do all courses no course can be skipped just check if previos course is completed or not let recordList: any = {}; recordList = await this.altCourseTrackingService.getExistingCourseTrackingRecords( @@ -317,7 +332,62 @@ export class ALTUserEligibilityService { }); } } - } else { + } else if (skipBaseline) { + // Baseline Assessment skip for course + let courseFound; + for (const course of programRules?.prog) { + const courseDate = new Date(course.startDate); + const currentDate = new Date(); + if ( + course.contentId === courseId && + courseDate.getTime() <= currentDate.getTime() + ) { + courseFound = true; + if ( + JSON.stringify(course.criteria) === JSON.stringify({}) && + course.contentType !== "assessment" + ) { + const currentCourseCompletion = + await this.getCurrentCourseCompletionStatus( + request, + course.contentId, + altUserId + ); + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: { + contentId: courseId, + contentType: course.contentType, + msg: "Course " + courseId + " " + currentCourseCompletion, + status: currentCourseCompletion, + }, + }); + } else { + return new ErrorResponse({ + errorCode: "400", + errorMessage: + "Criteria for previous course completion not found in rules", + }); + } + } + } + if (!courseFound) { + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: { + contentId: courseId, + msg: + "Course " + + courseId + + " is not available at the moment. Please try again later!", + status: "locked", + }, + }); + } + } + else { return new ErrorResponse({ errorCode: "400", errorMessage: diff --git a/src/main.ts b/src/main.ts index 3d0c7df5..16f6e0a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,6 @@ async function bootstrap() { { type: "apiKey", name: "Authorization", in: "header" }, "access-token" ) - .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup("api/swagger-docs", app, document);