Skip to content

Commit

Permalink
expanded Record
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Jun 20, 2024
1 parent 5f0b6ba commit 4a363d4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/record/dto/res/expandedRes.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ApiProperty } from '@nestjs/swagger';
import { RecordResDto } from './recordRes.dto';
import { Lecture, Professor } from '@prisma/client';

class LectureResDto implements Lecture {
@ApiProperty()
id: number;

@ApiProperty()
lectureName: string;
}

class ProfessorResDto implements Professor {
@ApiProperty()
id: number;

@ApiProperty()
name: string;
}

class LectureProfessorResDto {
@ApiProperty()
lecture: LectureResDto;

@ApiProperty()
professor: ProfessorResDto;
}

export class ExpandedRecordResDto extends RecordResDto {
@ApiProperty()
lectureProfessor: LectureProfessorResDto;
}
3 changes: 2 additions & 1 deletion src/record/record.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto';
import { GetUser } from 'src/user/decorator/get-user.decorator';
import { User } from '@prisma/client';
import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto';
import { ExpandedRecordResDto } from './dto/res/expandedRes.dto';

@ApiTags('record')
@Controller('record')
Expand All @@ -36,7 +37,7 @@ export class RecordController {
@Get()
async getRecordList(
@Query() query: GetAllRecordQueryDto,
): Promise<RecordResDto[]> {
): Promise<ExpandedRecordResDto[]> {
return this.recordService.getRecordList(query);
}

Expand Down
21 changes: 19 additions & 2 deletions src/record/record.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PagenationQueryDto } from './dto/req/pagenationQuery.dto';
import { GetAllRecordQueryDto } from './dto/req/getAllRecordQuery.dto';
import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto';
import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto';
import { ExpandedRecordType } from './types/ExpandedRecord.type';

@Injectable()
export class RecordRepository {
Expand All @@ -13,13 +14,21 @@ export class RecordRepository {
async getRecentRecord({
take,
offset,
}: PagenationQueryDto): Promise<Record[]> {
}: PagenationQueryDto): Promise<ExpandedRecordType[]> {
return this.prismaService.record.findMany({
skip: offset,
take,
orderBy: {
createdAt: 'desc',
},
include: {
lectureProfessor: {
include: {
lecture: true,
professor: true,
},
},
},
});
}

Expand All @@ -28,7 +37,7 @@ export class RecordRepository {
professorId,
take,
offset,
}: Omit<GetAllRecordQueryDto, 'type'>): Promise<Record[]> {
}: Omit<GetAllRecordQueryDto, 'type'>): Promise<ExpandedRecordType[]> {
return this.prismaService.record.findMany({
where: {
lectureId,
Expand All @@ -39,6 +48,14 @@ export class RecordRepository {
orderBy: {
createdAt: 'desc',
},
include: {
lectureProfessor: {
include: {
lecture: true,
professor: true,
},
},
},
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/record/record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { Record, User } from '@prisma/client';
import { GetAllRecordQueryDto } from './dto/req/getAllRecordQuery.dto';
import { CreateRecordBodyDto } from './dto/req/createRecordBody.dto';
import { UpdateRecordBodyDto } from './dto/req/updateRecordBoty.dto';
import { ExpandedRecordType } from './types/ExpandedRecord.type';

@Injectable()
export class RecordService {
constructor(private readonly recordRepository: RecordRepository) {}

async getRecordList(query: GetAllRecordQueryDto): Promise<Record[]> {
async getRecordList(
query: GetAllRecordQueryDto,
): Promise<ExpandedRecordType[]> {
if (query.type === 'recent') {
return this.recordRepository.getRecentRecord(query);
}
Expand Down
12 changes: 12 additions & 0 deletions src/record/types/ExpandedRecord.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Prisma } from '@prisma/client';

export type ExpandedRecordType = Prisma.RecordGetPayload<{
include: {
lectureProfessor: {
include: {
lecture: true;
professor: true;
};
};
};
}>;

0 comments on commit 4a363d4

Please sign in to comment.