feat(api): add OpenAPI/Swagger documentation for all API endpoints

Install @nestjs/swagger, configure Swagger UI at /api/docs with JWT bearer
auth, and add ApiTags/ApiOperation/ApiResponse/ApiProperty decorators to
all 8 controllers (50+ endpoints) and 31 DTOs across auth, listings,
search, payments, subscriptions, admin, notifications, and analytics modules.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 04:08:11 +07:00
parent 325cd4c421
commit 8e7672694b
42 changed files with 531 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ import {
Inject,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { ApiProperty } from '@nestjs/swagger';
import { CurrentUser } from '@modules/auth/presentation/decorators';
import { type JwtPayload } from '@modules/auth';
import {
@@ -21,16 +23,21 @@ import { IsBoolean, IsEnum, IsString } from 'class-validator';
import { NotificationChannel as PrismaChannel } from '@prisma/client';
class UpdatePreferenceDto {
@ApiProperty({ enum: PrismaChannel, description: 'Notification channel' })
@IsEnum(PrismaChannel)
channel!: PrismaChannel;
@ApiProperty({ description: 'Event type identifier' })
@IsString()
eventType!: string;
@ApiProperty({ description: 'Whether the preference is enabled' })
@IsBoolean()
enabled!: boolean;
}
@ApiTags('notifications')
@ApiBearerAuth('JWT')
@Controller('notifications')
@UseGuards(AuthGuard('jwt'))
export class NotificationsController {
@@ -43,6 +50,10 @@ export class NotificationsController {
) {}
@Get('history')
@ApiOperation({ summary: 'Get notification history' })
@ApiResponse({ status: 200, description: 'Notification history retrieved' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
@ApiQuery({ name: 'limit', required: false, type: Number })
async getHistory(
@CurrentUser() user: JwtPayload,
@Query('limit') limit?: number,
@@ -51,11 +62,17 @@ export class NotificationsController {
}
@Get('preferences')
@ApiOperation({ summary: 'Get notification preferences' })
@ApiResponse({ status: 200, description: 'Preferences retrieved' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async getPreferences(@CurrentUser() user: JwtPayload) {
return this.preferenceRepo.findByUserId(user.sub);
}
@Put('preferences')
@ApiOperation({ summary: 'Update a notification preference' })
@ApiResponse({ status: 200, description: 'Preference updated' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async updatePreference(
@CurrentUser() user: JwtPayload,
@Body() dto: UpdatePreferenceDto,
@@ -64,6 +81,9 @@ export class NotificationsController {
}
@Get('templates')
@ApiOperation({ summary: 'Get available notification templates' })
@ApiResponse({ status: 200, description: 'Templates retrieved' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async getTemplates() {
return { templates: this.templateService.getTemplateKeys() };
}