diff --git a/src/controller/progress/tracking.service.ts b/src/controller/progress/tracking.service.ts index cd35c0f..1020489 100644 --- a/src/controller/progress/tracking.service.ts +++ b/src/controller/progress/tracking.service.ts @@ -35,6 +35,7 @@ import { UpdateProjectDto } from './dto/project.dto'; import { quizBatchDto } from '../content/dto/content.dto'; import { BootcampController } from '../bootcamp/bootcamp.controller'; import { SubmitFormBodyDto } from './dto/form.dto'; +import { helperVariable } from 'src/constants/helper'; const { ZUVY_CONTENT_URL, ZUVY_CONTENTS_API_URL } = process.env; // INPORTING env VALUSE ZUVY_CONTENT @@ -1477,8 +1478,17 @@ export class TrackingService { async getLatestUpdatedCourseForStudents(userId: number) { try { const latestTracking = await db.select().from(zuvyRecentBootcamp) - .where(eq(zuvyRecentBootcamp.userId, BigInt(userId))); + .where(eq(zuvyRecentBootcamp.userId, BigInt(userId))); if (latestTracking.length > 0) { + const ifEnrolled = await db.select().from(zuvyBatchEnrollments).where(sql`${zuvyBatchEnrollments.bootcampId} = ${latestTracking[0].bootcampId} AND ${zuvyBatchEnrollments.userId} = ${BigInt(userId)}`); + if(ifEnrolled.length == 0) + { + return { + status: helperVariable.success, + code: 200, + message: 'You have been removed from the recent course that you are studying.Please ask your instructor about this!!' + } + } if (latestTracking[0].progress < 100) { const data = await db.query.zuvyCourseModules.findFirst({ where: (courseModules, { sql }) => @@ -1496,13 +1506,18 @@ export class TrackingService { }); const index = data['moduleChapterData'].findIndex(obj => obj.id === latestTracking[0].chapterId) const newChapter = data['moduleChapterData'][index + 1]; + return { + status: helperVariable.success, + code:200, + latestCourse: { moduleId: data.id, moduleName: data.name, typeId: data.typeId, bootcampId: data.bootcampId, bootcampName: data['moduleData'].name, newChapter + } } } else { @@ -1534,20 +1549,23 @@ export class TrackingService { projectData: true, }, }); - if (data) { return { + status: helperVariable.success, + code:200, + latestCourse : { moduleId: data.id, moduleName: data.name, typeId: data.typeId, bootcampId: data['moduleData'].id, - bootcampName: data['moduleData'], - newChapter: data.typeId == 1 ? data['moduleChapterData'][0] : data['projectData'][0] + bootcampName: data['moduleData'].name, + newChapter: data.typeId == 1 ? (data['moduleChapterData'].length > 0 ? data['moduleChapterData'][0] : 'There is no chapter in the module') : data['projectData'][0] + } }; } else { return { - status: 'error', + status: helperVariable.error, code: 404, message: 'Start a course' } @@ -1557,7 +1575,7 @@ export class TrackingService { } else { return { - status: 'error', + status: helperVariable.error, code: 404, message: 'You have not yet started any course module' } diff --git a/src/controller/student/student.service.ts b/src/controller/student/student.service.ts index f4ae950..9ca725f 100644 --- a/src/controller/student/student.service.ts +++ b/src/controller/student/student.service.ts @@ -9,9 +9,10 @@ import { users } from '../../../drizzle/schema'; import { db } from '../../db/index'; -import { eq, sql, desc, count } from 'drizzle-orm'; +import { eq, sql, desc, count,asc } from 'drizzle-orm'; import { ClassesService } from '../classes/classes.service' import { query } from 'express'; +import { helperVariable } from 'src/constants/helper'; @Injectable() export class StudentService { @@ -172,7 +173,7 @@ export class StudentService { let enrolled = await db.select().from(zuvyBatchEnrollments).where(queryString); if (enrolled.length == 0) { - return { status: 'error', message: 'not enrolled in any course.', code: 404 }; + return { status: helperVariable.error, message: 'not enrolled in any course.', code: 404 }; } let bootcampIds = await Promise.all(enrolled.map(async (e) => { @@ -186,7 +187,7 @@ export class StudentService { .where( sql`${zuvySessions.bootcampId} IN ${bootcampIds} AND ${zuvySessions.status} != 'completed'`, ) - .orderBy(desc(zuvySessions.startTime)) + .orderBy(asc(zuvySessions.startTime)) let filterClasses = upcomingClasses.reduce((acc, e) => { if (e.status == 'upcoming') {