Skip to content

Commit df7d1c7

Browse files
committed
✨ feat: Add filtering and pagination to get all games
The `findAll` method in `GameController` and `GameService` was modified to accept and process `GetGameDto`, allowing for filtering and pagination of game questions. This change enables fetching game data with pagination support by using query parameters like page and limit.
1 parent 9ae2a53 commit df7d1c7

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/main/game/dto/getGame.dto.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ApiProperty } from "@nestjs/swagger";
2+
import { IsNumber, IsOptional } from "class-validator";
3+
import { Type } from "class-transformer";
4+
5+
export class GetGameDto {
6+
@ApiProperty({
7+
description: 'Page number for pagination',
8+
example: 1,
9+
required: false,
10+
})
11+
@IsOptional()
12+
@Type(() => Number)
13+
@IsNumber()
14+
page?: number;
15+
16+
@ApiProperty({
17+
description: 'Number of items per page',
18+
example: 10,
19+
required: false,
20+
})
21+
@IsOptional()
22+
@Type(() => Number)
23+
@IsNumber()
24+
limit?: number;
25+
}

src/main/game/game.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { UpdateGameDto } from './dto/update-game.dto';
77
import { JwtAuthGuard } from 'src/utils/jwt-auth.guard';
88
import { QuestType } from 'generated/prisma';
99
import { DuaDto } from './dto/createDua.dto';
10+
import { GetGameDto } from './dto/getGame.dto';
1011

1112

1213
@ApiTags('Game')
@@ -50,8 +51,8 @@ export class GameController {
5051
@Get()
5152
@ApiOperation({ summary: 'Get all game questions' })
5253
@ApiResponse({ status: 200, description: 'List of game questions' })
53-
findAll() {
54-
return this.gameService.findAll();
54+
findAll(@Query() filter:GetGameDto) {
55+
return this.gameService.findAll(filter);
5556
}
5657

5758
@Get(':id')

src/main/game/game.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { QuestStatus, QuestType } from 'generated/prisma';
77
import * as fs from 'fs';
88
import * as path from 'path';
99
import { DuaDto } from './dto/createDua.dto';
10+
import { GetGameDto } from './dto/getGame.dto';
1011

1112

1213
@Injectable()
@@ -50,8 +51,12 @@ export class GameService {
5051
});
5152
}
5253

53-
async findAll() {
54+
async findAll(filer:GetGameDto) {
55+
const {page=1,limit=10}=filer
56+
const skip=(page-1)*limit
5457
return this.prisma.gameData.findMany({
58+
skip:skip,
59+
take:limit,
5560
orderBy: { createdAt: 'desc' },
5661
});
5762
}

0 commit comments

Comments
 (0)