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 27, 2024
2 parents fda1bfb + aa26d30 commit 4862099
Show file tree
Hide file tree
Showing 40 changed files with 2,201 additions and 215 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { UserOccupationModule } from './user-occupation/user-occupation.module';
import { UserStreakModule } from './user-streak/user-streak.module';
import { UserModule } from './user/user.module';
import { UserRewardModule } from './user-reward/user-reward.module';
import { PretestModule } from './pretest/pretest.module';

@Module({
imports: [
Expand Down Expand Up @@ -79,6 +80,7 @@ import { UserRewardModule } from './user-reward/user-reward.module';
RewardModule,
UserRewardModule,
RoadmapModule,
PretestModule,
],
controllers: [AppController],
providers: [
Expand Down
11 changes: 4 additions & 7 deletions src/chapter/chapter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ export class ChapterController {
type: String,
description: 'Course id',
})
@ApiBearerAuth()
@Public()
@ApiResponse({
status: HttpStatus.OK,
description: 'Get chapter video',
type: StreamableFile,
})
async getVideo(
@Req() request: AuthenticatedRequest,
@Param(
'id',
new ParseUUIDPipe({
Expand All @@ -83,11 +82,9 @@ export class ChapterController {
)
id: string,
): Promise<StreamableFile> {
const chapter = await this.chapterService.findOneWithOwnership(
request.user.id,
request.user.role,
{ where: { id } },
);
const chapter = await this.chapterService.findOne({
where: { id },
});

const file = await this.fileService.get(Folder.CHAPTER_VIDEOS, chapter.videoKey);
return new StreamableFile(file, {
Expand Down
7 changes: 0 additions & 7 deletions src/enrollment/enrollment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ export class EnrollmentService {
return enrollments;
}

async findEnrollmentByUserId(userId: string): Promise<Enrollment[]> {
const enrollment = this.enrollmentRepository.find({
where: { user: { id: userId } },
});
return enrollment;
}

async findOne(where: FindOptionsWhere<Enrollment>): Promise<Enrollment> {
const options: FindOneOptions<Enrollment> = {
where,
Expand Down
30 changes: 30 additions & 0 deletions src/exam-attempt/dtos/create-exam-attempt.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,33 @@ export class CreateExamAttemptDto {
})
status: ExamAttemptStatus;
}

export class CreateExamAttemptPretestDto {
@IsNotEmpty()
@ApiProperty({
description: 'Pretest ID',
type: String,
example: '8d4887aa-28e7-4d0e-844c-28a8ccead003',
})
pretestId: string;

@IsOptional()
@Min(0)
@IsInt()
@ApiProperty({
description: 'Score',
type: Number,
example: 0,
})
score?: number;

@IsNotEmpty()
@IsEnum(ExamAttemptStatus)
@ApiProperty({
description: 'Exam attempt status',
type: String,
example: ExamAttemptStatus.IN_PROGRESS,
enum: ExamAttemptStatus,
})
status: ExamAttemptStatus;
}
100 changes: 100 additions & 0 deletions src/exam-attempt/dtos/exam-attempt-pretest.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { ExamAttemptStatus } from 'src/shared/enums';
import { ApiProperty } from '@nestjs/swagger';
import { PaginatedResponse } from 'src/shared/pagination/dtos/paginate-response.dto';
import { UserResponseDto } from 'src/user/dtos/user-response.dto';
import { ExamAttempt } from '../exam-attempt.entity';
import { PretestResponseDto } from 'src/pretest/dtos/pretest-response.dto';

export class ExamAttemptPretestResponseDto {
@ApiProperty({
description: 'Exam Attempy ID',
type: String,
example: '123e4567-e89b-12d3-a456-426614174000',
})
id: string;

@ApiProperty({
description: 'Pretest Data',
type: PretestResponseDto,
example: {
id: '123e4567-e89b-12d3-a456-426614174000',
title: 'Exam title',
description: 'Exam description',
timeLimit: 20,
passingScore: 3,
maxAttempts: 1,
createdAt: '2024-11-26T11:10:00.257Z',
updatedAt: '2024-11-26T11:10:00.257Z',
},
})
pretest: PretestResponseDto;

@ApiProperty({
description: 'User Data',
type: String,
example: {
id: '389d1065-b898-4249-9d3d-e17e100336a7',
username: 'johndoe',
fullname: 'John Doe',
role: 'student',
email: 'johndoe@gmail.com',
profileKey: null,
},
})
user: UserResponseDto;

@ApiProperty({
description: 'Score',
type: String,
example: 0,
})
score: number;

@ApiProperty({
description: 'Exam attempt status',
type: String,
example: ExamAttemptStatus.IN_PROGRESS,
enum: ExamAttemptStatus,
})
status: ExamAttemptStatus;

@ApiProperty({
description: 'Exam attempt start at',
type: Date,
example: new Date(),
})
startedAt: Date;

@ApiProperty({
description: 'Exam attempt submit at',
type: Date,
example: new Date(),
})
submittedAt: Date;

constructor(examAttempt: ExamAttempt) {
this.id = examAttempt.id;
this.pretest = examAttempt.pretest;
this.user = examAttempt.user;
this.score = examAttempt.score;
this.status = examAttempt.status;
this.startedAt = examAttempt.startedAt;
this.submittedAt = examAttempt.submittedAt;
}
}

export class PaginatedExamAttemptPretestResponseDto extends PaginatedResponse(
ExamAttemptPretestResponseDto,
) {
constructor(
examAttempt: ExamAttempt[],
total: number,
pageSize: number,
currentPage: number,
) {
const examAttemptDtos = examAttempt.map(
(examAttempt) => new ExamAttemptPretestResponseDto(examAttempt),
);
super(examAttemptDtos, total, pageSize, currentPage);
}
}
9 changes: 8 additions & 1 deletion src/exam-attempt/dtos/update-exam-attempt.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { OmitType, PartialType } from '@nestjs/swagger';
import { CreateExamAttemptDto } from './create-exam-attempt.dto';
import {
CreateExamAttemptDto,
CreateExamAttemptPretestDto,
} from './create-exam-attempt.dto';

export class UpdateExamAttemptDto extends PartialType(
OmitType(CreateExamAttemptDto, ['examId'] as const),
) {}

export class UpdateExamAttemptPretestDto extends PartialType(
OmitType(CreateExamAttemptPretestDto, ['pretestId'] as const),
) {}
Loading

0 comments on commit 4862099

Please sign in to comment.