feat: add pagination, sorting and filtering

This commit is contained in:
2026-06-07 12:58:38 +03:30
parent 28c1a4831e
commit d1fecf62ad
19 changed files with 389 additions and 176 deletions
@@ -1,4 +1,4 @@
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common';
import { AdminAuthService } from './providers/admin-auth.service';
import { AdminLoginDTO } from './dtos/admin-login.dto';
import { Public } from '@/modules/auth/decorators/public.decorator';
@@ -14,7 +14,7 @@ export class AdminAuthController {
@Public()
@Post('login')
@HttpCode(200)
@HttpCode(HttpStatus.OK)
public async login(@Body() adminLoginDto: AdminLoginDTO) {
return await this.adminAuthService.login(adminLoginDto);
}
@@ -1,16 +1,21 @@
import { Role } from '@/common/enums/roles.enum';
import { Roles } from '@/modules/auth/decorators/roles.decorator';
import { CreateTestDTO } from '@/modules/tests/dtos/create-test.dto';
import { FindTestsDTO } from '@/modules/tests/dtos/find-tests.dto';
import { UpdateTestDTO } from '@/modules/tests/dtos/update-test.dto';
import { TestsService } from '@/modules/tests/providers/tests.service';
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
ParseIntPipe,
Patch,
Post,
Query,
} from '@nestjs/common';
@Controller('admin/tests')
@@ -29,8 +34,8 @@ export class AdminTestsController {
}
@Get()
public async getAllTests() {
return await this.testsService.adminGetAll();
public async getAllTests(@Query() query: FindTestsDTO) {
return await this.testsService.adminGetAll(query);
}
@Get(':id')
@@ -45,4 +50,10 @@ export class AdminTestsController {
) {
return await this.testsService.updateOne(id, updateTestDto);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
public async deleteTestById(@Param('id', ParseIntPipe) id: number) {
return await this.testsService.deleteOne(id);
}
}
@@ -0,0 +1,2 @@
DELETE http://localhost:3000/admin/tests/1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgwNzQ5MTcwLCJleHAiOjE3ODA3NTI3NzAsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.apRhtVZgFMFcyutZGO7uzckscch9Jw42s0RCSZZv4K0
@@ -1,5 +1,5 @@
GET http://localhost:3000/admin/tests
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgwMzk4MzI0LCJleHAiOjE3ODA0MDE5MjQsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.s3NAErSAjMTz2s27obas3TEi5Og2HPeLgWCoIyzmzII
GET http://localhost:3000/admin/tests?title=test&isActive=true&accessType=paid&sortBy=title&order=DSC&page=2&limit=1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgwNzQ5MTcwLCJleHAiOjE3ODA3NTI3NzAsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.apRhtVZgFMFcyutZGO7uzckscch9Jw42s0RCSZZv4K0
GET http://localhost:3000/admin/tests/4
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgwMzk4MzI0LCJleHAiOjE3ODA0MDE5MjQsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.s3NAErSAjMTz2s27obas3TEi5Og2HPeLgWCoIyzmzII
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgwNzQ5MTcwLCJleHAiOjE3ODA3NTI3NzAsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.apRhtVZgFMFcyutZGO7uzckscch9Jw42s0RCSZZv4K0