cr
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NotFoundException, Logger } from '@nestjs/common';
|
||||
import { PrismaService } from '../../database/prisma.service';
|
||||
import { PaginationDto } from '../dto/pagination.dto';
|
||||
import { PaginationMeta } from '../types/api-response.type';
|
||||
import { NotFoundException, Logger } from "@nestjs/common";
|
||||
import { PrismaService } from "../../database/prisma.service";
|
||||
import { PaginationDto } from "../dto/pagination.dto";
|
||||
import { PaginationMeta } from "../types/api-response.type";
|
||||
|
||||
/**
|
||||
* Generic base service with common CRUD operations
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './base.service';
|
||||
export * from './base.controller';
|
||||
export * from "./base.service";
|
||||
export * from "./base.controller";
|
||||
|
||||
Reference in New Issue
Block a user