Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored latestCourse api and upcoming classes api #223

Merged
merged 2 commits into from
Aug 2, 2024
Merged
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
30 changes: 24 additions & 6 deletions src/controller/progress/tracking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }) =>
Expand All @@ -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 {
Expand Down Expand Up @@ -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'
}
Expand All @@ -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'
}
Expand Down
7 changes: 4 additions & 3 deletions src/controller/student/student.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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') {
Expand Down