Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/SAIG-KMITL/edusaig-api into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganthepro committed Nov 29, 2024
2 parents 2791f99 + 19a0028 commit 93230a0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/enrollment/enrollment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ export class EnrollmentController {
return this.enrollmentService.findAll(query);
}

@Get('/user')
@ApiResponse({
status: HttpStatus.OK,
type: EnrollmentResponseDto,
description: 'Get all enrollments by user',
isArray: true,
})
@Roles(Role.STUDENT)
async findAllByUser(
@Req() request: AuthenticatedRequest,
@Query() query: PaginateQueryDto,
): Promise<PaginatedEnrollmentResponseDto> {
return await this.enrollmentService.findAllByUser(request.user.id, query);
}

@Get(':id')
@ApiParam({
name: 'id',
Expand Down
28 changes: 28 additions & 0 deletions src/enrollment/enrollment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ export class EnrollmentService {
return enrollment;
}

async findAllByUser(
userId: string,
{
page = 1,
limit = 20,
}: {
page?: number;
limit?: number;
},
): Promise<PaginatedEnrollmentResponseDto> {
const { find } = await createPagination(this.enrollmentRepository, {
page,
limit,
});

const enrollments = await find({
where: {
user: { id: userId },
},
relations: {
user: true,
course: true,
},
}).run();

return enrollments;
}

async create(createEnrollmentDto: CreateEnrollmentDto): Promise<Enrollment> {
const enrollment = await this.enrollmentRepository.findOne({
where: {
Expand Down
2 changes: 0 additions & 2 deletions src/pretest/pretest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export class PretestService {
);
return { data: response.data };
} catch (error) {
console.log(error);
throw new Error('Failed to fetch data or process request');
}
}
Expand All @@ -279,7 +278,6 @@ export class PretestService {
search: '',
},
);

const requestBody: CreateEvaluate = {
question: preTestExam.data.map((data) => data.question.question),
correct_answer: preTestExam.data.map(
Expand Down
15 changes: 15 additions & 0 deletions src/progress/progress.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ export class ProgressController {
return this.progressService.findAll(query);
}

@Get('/user')
@ApiResponse({
status: HttpStatus.OK,
type: ProgressResponseDto,
description: 'Get all progress by user',
isArray: true,
})
@Roles(Role.STUDENT)
async findAllByUser(
@Req() request: AuthenticatedRequest,
@Query() query: PaginateQueryDto,
): Promise<PaginatedProgressResponseDto> {
return this.progressService.findAllByUser(request.user.id, query);
}

@Get(':id')
@ApiParam({
name: 'id',
Expand Down
24 changes: 24 additions & 0 deletions src/progress/progress.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { createPagination } from 'src/shared/pagination';
import { PaginateQueryDto } from 'src/shared/pagination/dtos/paginate-query.dto';
import { FindOneOptions, FindOptionsWhere, Repository } from 'typeorm';
import { CreateProgressDto } from './dtos/create-progress.dto';
import { PaginatedProgressResponseDto } from './dtos/progress-response.dto';
Expand Down Expand Up @@ -36,6 +37,29 @@ export class ProgressService {
return progress;
}

async findAllByUser(
userId: string,
query: PaginateQueryDto,
): Promise<PaginatedProgressResponseDto> {
const { find } = await createPagination(this.progressRepository, query);

const progress = await find({
where: {
enrollment: {
user: {
id: userId,
},
},
},
relations: {
enrollment: true,
chapter: true,
},
}).run();

return progress;
}

async findOne(
id: string,
options: FindOneOptions<Progress>,
Expand Down
5 changes: 3 additions & 2 deletions src/roadmap/roadmap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class RoadmapService {
userID: userId,
},
};
console.log('Request body', requestBody);
const response = await this.httpService.axiosRef.post(
`https://ai.edusaig.com/ai/generate-roadmap`,
requestBody,
Expand Down Expand Up @@ -129,7 +128,9 @@ export class RoadmapService {
const queryBuilder = this.roadmapRepository
.createQueryBuilder('roadmap')
.leftJoinAndSelect('roadmap.user', 'user')
.leftJoinAndSelect('roadmap.courses', 'courses');
.leftJoinAndSelect('roadmap.courses', 'courses')
.leftJoinAndSelect('courses.teacher', 'teacher')
.leftJoinAndSelect('courses.category', 'category');

if (userId) {
queryBuilder.andWhere('user.id = :userId', { userId });
Expand Down

0 comments on commit 93230a0

Please sign in to comment.