This commit is contained in:
2026-04-16 17:21:48 +03:00
parent c8fa4c442d
commit c8e7e4e927
116 changed files with 3720 additions and 4197 deletions
+29 -29
View File
@@ -8,20 +8,20 @@ import {
Body,
HttpCode,
ParseUUIDPipe,
} from '@nestjs/common';
} from "@nestjs/common";
import {
ApiOperation,
ApiOkResponse,
ApiNotFoundResponse,
ApiBadRequestResponse,
} from '@nestjs/swagger';
import { BaseService } from './base.service';
import { PaginationDto } from '../dto/pagination.dto';
} from "@nestjs/swagger";
import { BaseService } from "./base.service";
import { PaginationDto } from "../dto/pagination.dto";
import {
ApiResponse,
createSuccessResponse,
createPaginatedResponse,
} from '../types/api-response.type';
} from "../types/api-response.type";
/**
* Generic base controller with common CRUD endpoints
@@ -37,8 +37,8 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
@Get()
@HttpCode(200)
@ApiOperation({ summary: 'Get all records with pagination' })
@ApiOkResponse({ description: 'Records retrieved successfully' })
@ApiOperation({ summary: "Get all records with pagination" })
@ApiOkResponse({ description: "Records retrieved successfully" })
async findAll(
@Query() pagination: PaginationDto,
): Promise<ApiResponse<{ items: T[]; meta: any }>> {
@@ -52,13 +52,13 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
);
}
@Get(':id')
@Get(":id")
@HttpCode(200)
@ApiOperation({ summary: 'Get a record by ID' })
@ApiOkResponse({ description: 'Record retrieved successfully' })
@ApiNotFoundResponse({ description: 'Record not found' })
@ApiOperation({ summary: "Get a record by ID" })
@ApiOkResponse({ description: "Record retrieved successfully" })
@ApiNotFoundResponse({ description: "Record not found" })
async findOne(
@Param('id', ParseUUIDPipe) id: string,
@Param("id", ParseUUIDPipe) id: string,
): Promise<ApiResponse<T>> {
const result = await this.service.findOne(id);
return createSuccessResponse(
@@ -69,9 +69,9 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
@Post()
@HttpCode(200)
@ApiOperation({ summary: 'Create a new record' })
@ApiOkResponse({ description: 'Record created successfully' })
@ApiBadRequestResponse({ description: 'Validation failed' })
@ApiOperation({ summary: "Create a new record" })
@ApiOkResponse({ description: "Record created successfully" })
@ApiBadRequestResponse({ description: "Validation failed" })
async create(@Body() createDto: CreateDto): Promise<ApiResponse<T>> {
const result = await this.service.create(createDto);
return createSuccessResponse(
@@ -81,13 +81,13 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
);
}
@Put(':id')
@Put(":id")
@HttpCode(200)
@ApiOperation({ summary: 'Update an existing record' })
@ApiOkResponse({ description: 'Record updated successfully' })
@ApiNotFoundResponse({ description: 'Record not found' })
@ApiOperation({ summary: "Update an existing record" })
@ApiOkResponse({ description: "Record updated successfully" })
@ApiNotFoundResponse({ description: "Record not found" })
async update(
@Param('id', ParseUUIDPipe) id: string,
@Param("id", ParseUUIDPipe) id: string,
@Body() updateDto: UpdateDto,
): Promise<ApiResponse<T>> {
const result = await this.service.update(id, updateDto);
@@ -97,13 +97,13 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
);
}
@Delete(':id')
@Delete(":id")
@HttpCode(200)
@ApiOperation({ summary: 'Delete a record (soft delete)' })
@ApiOkResponse({ description: 'Record deleted successfully' })
@ApiNotFoundResponse({ description: 'Record not found' })
@ApiOperation({ summary: "Delete a record (soft delete)" })
@ApiOkResponse({ description: "Record deleted successfully" })
@ApiNotFoundResponse({ description: "Record not found" })
async delete(
@Param('id', ParseUUIDPipe) id: string,
@Param("id", ParseUUIDPipe) id: string,
): Promise<ApiResponse<T>> {
const result = await this.service.delete(id);
return createSuccessResponse(
@@ -112,12 +112,12 @@ export abstract class BaseController<T, CreateDto, UpdateDto> {
);
}
@Post(':id/restore')
@Post(":id/restore")
@HttpCode(200)
@ApiOperation({ summary: 'Restore a soft-deleted record' })
@ApiOkResponse({ description: 'Record restored successfully' })
@ApiOperation({ summary: "Restore a soft-deleted record" })
@ApiOkResponse({ description: "Record restored successfully" })
async restore(
@Param('id', ParseUUIDPipe) id: string,
@Param("id", ParseUUIDPipe) id: string,
): Promise<ApiResponse<T>> {
const result = await this.service.restore(id);
return createSuccessResponse(