Skip to content

Commit

Permalink
Merge pull request #232 from navgurukul/chore/instructor
Browse files Browse the repository at this point in the history
Optimized and handled some edge cases in some api
  • Loading branch information
giribabu22 authored Aug 13, 2024
2 parents 4b39580 + 87c560d commit 85c2547
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 15 deletions.
9 changes: 7 additions & 2 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,7 @@ export const postsRelations = relations(zuvyModuleChapter, ({ one, many }) => ({
formTrackingDetails: many(zuvyFormTracking),
OutsourseAssessments: many(zuvyOutsourseAssessments),
ModuleAssessment: many(zuvyModuleAssessment),
assignmentTrackingDetails: many(zuvyAssignmentSubmission),
moduleTracked: one(zuvyModuleTracking, {
fields: [zuvyModuleChapter.moduleId],
references: [zuvyModuleTracking.moduleId],
Expand Down Expand Up @@ -3111,8 +3112,12 @@ export const userCodeRelations = relations(users, ({ one }) => ({
}),
}));

export const userAssignmentSubmissionRelations = relations(zuvyAssignmentSubmission, ({ many }) => ({
assignmentSubmission : many(users)
export const userAssignmentSubmissionRelations = relations(zuvyAssignmentSubmission, ({one, many }) => ({
assignmentSubmission : many(users),
chapterDetails:one(zuvyModuleChapter, {
fields: [zuvyAssignmentSubmission.chapterId],
references: [zuvyModuleChapter.id],
}),
}));
export const zuvyChapterRelations = relations(
zuvyChapterTracking,
Expand Down
42 changes: 36 additions & 6 deletions src/controller/progress/tracking.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,28 @@ export class TrackingController {
);
return res;
}

@Get('getQuizAndAssignmentWithStatus')
@ApiOperation({ summary: 'get Quiz And Assignment With Status' })
@ApiBearerAuth()
async getQuizAndAssignmentWithStatus(
@Req() req,
@Query('chapterId') chapterId: number,
@Res() res
) {
try {
let [err, success] = await this.TrackingService.getQuizAndAssignmentWithStatus(
req.user[0].id,
chapterId,
);
if (err) {
return ErrorResponse.BadRequestException(err.message, err.statusCode).send(res)
}
return new SuccessResponse(success.message, success.statusCode, success.data).send(res);
} catch (error) {
return ErrorResponse.BadRequestException(error.message).send(res);
}
}

@Post('updateProject/:projectId')
@ApiOperation({ summary: 'Update project for a user' })
Expand Down Expand Up @@ -490,13 +512,21 @@ export class TrackingController {
@Param('projectId') projectId: number,
@Param('moduleId') moduleId: number,
@Req() req,
@Res() res
) {
const res = await this.TrackingService.getProjectDetailsWithStatus(
projectId,
moduleId,
req.user[0].id
);
return res;
try {
let [err, success] = await this.TrackingService.getProjectDetailsWithStatus(
projectId,
moduleId,
req.user[0].id
);
if (err) {
return ErrorResponse.BadRequestException(err.message, err.statusCode).send(res)
}
return new SuccessResponse(success.message, success.statusCode, success.data).send(res);
} catch (error) {
return ErrorResponse.BadRequestException(error.message).send(res);
}
}

@Get('/allBootcampProgress')
Expand Down
84 changes: 77 additions & 7 deletions src/controller/progress/tracking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,69 @@ export class TrackingService {
}
}

async getQuizAndAssignmentWithStatus(
userId: number,
chapterId: number,
):Promise<any>
{
try {
const chapter = await db.select().from(zuvyModuleChapter).where(eq(zuvyModuleChapter.id,chapterId));
if(chapter.length > 0)
{
if(chapter[0].topicId == 4)
{
if(chapter[0].quizQuestions !== null)
{
const trackedData = await db.query.zuvyModuleQuiz.findMany({
where: (moduleQuiz, { sql }) => sql`${inArray(moduleQuiz.id, Object.values(chapter[0].quizQuestions))}`,
orderBy: (moduleQuiz, { asc }) => asc(moduleQuiz.id),
with: {

quizTrackingData: {
columns: {
chosenOption: true,
status: true
},
where: (quizTracking, { sql }) => sql`${quizTracking.userId} = ${userId} and ${quizTracking.chapterId} = ${chapterId}`,
}
}
});
const quizQuestionsLength = Object.values(chapter[0].quizQuestions).length;
const quizQuestionsWithTrackingData = trackedData.filter(quiz => quiz['quizTrackingData'].length > 0).length;

const allQuestionsHaveTrackingData = quizQuestionsLength === quizQuestionsWithTrackingData;
const status = allQuestionsHaveTrackingData ? 'Completed' : 'Pending';
return [null,{message:'Chapter details fetched successfully',statusCode: STATUS_CODES.OK,data:{chapterTitle:chapter[0].title,chapterId:chapter[0].id,chapterOrder:chapter[0].order,quizDetails:trackedData,status}}]
}
else {
return [null,{message:'No quiz questions found in this quiz chapter',statusCode: STATUS_CODES.OK,data:{chapterTitle:chapter[0].title,chapterId:chapter[0].id,chapterOrder:chapter[0].order,quizDetails: [],status:'Pending'}}]
}
}
else if(chapter[0].topicId == 5)
{
const assignmentTracking = await db
.select()
.from(zuvyAssignmentSubmission)
.where(sql`${zuvyAssignmentSubmission.userId} = ${userId}
AND ${zuvyAssignmentSubmission.chapterId} = ${chapterId}`);

const status = assignmentTracking.length > 0 ? 'Completed' : 'Pending';

return [null,{message:'Assignment chapter fetched succesfully',statusCode: STATUS_CODES.OK,data:{chapterDetails:chapter[0],assignmentTracking,status}}]
}
else {
return [null,{message:'It is not a quiz or assignment chapter',statusCode: STATUS_CODES.OK,data:null}]
}
}
else {
return [null,{message:'No chapter found',statusCode: STATUS_CODES.OK,data:null}]
}
}catch(error)
{

}
}

async submitProjectForAUser(
userId: number,
bootcampId: number,
Expand Down Expand Up @@ -1413,7 +1476,7 @@ export class TrackingService {
} catch (err) { }
}

async getProjectDetailsWithStatus(projectId: number, moduleId: number, userId: number) {
async getProjectDetailsWithStatus(projectId: number, moduleId: number, userId: number):Promise<any> {
try {
const data = await db.query.zuvyCourseModules.findFirst({
where: (courseModules, { eq }) =>
Expand All @@ -1422,6 +1485,17 @@ export class TrackingService {
projectData: {
where: (projectDetails, { eq }) =>
eq(projectDetails.id, projectId),
with: {
projectTrackingData: {
columns: {
projectLink:true,
isChecked:true,
grades:true,
createdAt:true
},
where: (projectTrack, { eq }) => eq(projectTrack.userId, userId)
}
}
},
moduleTracking: {
columns: {
Expand All @@ -1438,13 +1512,9 @@ export class TrackingService {
projectData: data['projectData'],
status: data['moduleTracking'].length > 0 ? 'Completed' : 'Pending'
}
return {
status: 'success',
code: 200,
projectDetails
}
return [null,{message:'Project details successfully fetched',statusCode: STATUS_CODES.OK,data:projectDetails}]
} catch (err) {
throw err;
return [{message:err.message,statusCode: STATUS_CODES.BAD_REQUEST}]
}
}

Expand Down

0 comments on commit 85c2547

Please sign in to comment.