feat: swagger document endpoints

This commit is contained in:
Ahmed Bouhuolia
2025-06-19 21:04:54 +02:00
parent 26c1f118c1
commit 4d52059dba
9 changed files with 218 additions and 14 deletions

View File

@@ -1,16 +1,25 @@
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import {
ApiTags,
ApiOperation,
ApiResponse,
getSchemaPath,
ApiExtraModels,
} from '@nestjs/swagger';
import { Controller, Get } from '@nestjs/common';
import { DashboardService } from './Dashboard.service';
import { GetDashboardBootMetaResponseDto } from './dtos/GetDashboardBootMetaResponse.dto';
@ApiTags('Dashboard')
@Controller('dashboard')
@ApiExtraModels(GetDashboardBootMetaResponseDto)
export class DashboardController {
constructor(private readonly dashboardService: DashboardService) {}
@ApiOperation({ summary: 'Get dashboard boot metadata' })
@ApiResponse({
status: 200,
description: 'Returns dashboard boot metadata including abilities, features, and cloud status',
description: 'The dashboard details have been successfully retrieved.',
schema: { $ref: getSchemaPath(GetDashboardBootMetaResponseDto) },
})
@Get('boot')
getBootMeta() {

View File

@@ -0,0 +1,64 @@
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger';
class RoleAbilityResponseDto {
@ApiProperty({
description: 'The subject of the ability',
example: 'all',
})
subject: string;
@ApiProperty({
description: 'The action permitted for the subject',
example: 'manage',
})
action: string;
}
class DashboardFeatureResponseDto {
@ApiProperty({
description: 'The name of the feature',
example: 'warehouses',
})
name: string;
@ApiProperty({
description: 'Whether the feature is accessible for the tenant',
example: true,
})
isAccessible: boolean;
@ApiProperty({
description: 'The default accessibility of the feature',
example: false,
})
defaultAccessible: boolean;
}
@ApiExtraModels(RoleAbilityResponseDto, DashboardFeatureResponseDto)
export class GetDashboardBootMetaResponseDto {
@ApiProperty({
description: 'List of abilities for the current user',
type: [RoleAbilityResponseDto],
example: [
{ subject: 'all', action: 'manage' },
{ subject: 'invoices', action: 'read' },
],
})
abilities: RoleAbilityResponseDto[];
@ApiProperty({
description: 'List of features and their accessibility',
type: [DashboardFeatureResponseDto],
example: [
{ name: 'warehouses', isAccessible: true, defaultAccessible: false },
{ name: 'branches', isAccessible: false, defaultAccessible: false },
],
})
features: DashboardFeatureResponseDto[];
@ApiProperty({
description: 'Whether the app is running on Bigcapital Cloud',
example: true,
})
isBigcapitalCloud: boolean;
}