feat(server): endpoints swagger docs

This commit is contained in:
Ahmed Bouhuolia
2025-06-30 16:30:55 +02:00
parent 83e698acf3
commit 9f6e9e85a5
23 changed files with 1248 additions and 23 deletions

View File

@@ -10,10 +10,18 @@ import {
} from '@nestjs/common';
import { ExcludeBankTransactionsApplication } from './ExcludeBankTransactionsApplication';
import { ExcludedBankTransactionsQuery } from './types/BankTransactionsExclude.types';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import {
ApiExtraModels,
ApiOperation,
ApiResponse,
ApiTags,
getSchemaPath,
} from '@nestjs/swagger';
import { GetExcludedBankTransactionResponseDto } from './dtos/GetExcludedBankTransactionResponse.dto';
@Controller('banking/exclude')
@ApiTags('Banking Transactions')
@ApiExtraModels(GetExcludedBankTransactionResponseDto)
export class BankingTransactionsExcludeController {
constructor(
private readonly excludeBankTransactionsApplication: ExcludeBankTransactionsApplication,
@@ -35,6 +43,17 @@ export class BankingTransactionsExcludeController {
@Get()
@ApiOperation({ summary: 'Retrieves the excluded bank transactions.' })
@ApiResponse({
status: 200,
description:
'The excluded bank transactions has been retrieved successfully.',
schema: {
type: 'array',
items: {
$ref: getSchemaPath(GetExcludedBankTransactionResponseDto),
},
},
})
public getExcludedBankTransactions(
@Query() query: ExcludedBankTransactionsQuery,
) {

View File

@@ -0,0 +1,205 @@
import { ApiProperty, ApiExtraModels } from '@nestjs/swagger';
import {
IsNumber,
IsString,
IsBoolean,
IsDateString,
IsOptional,
} from 'class-validator';
@ApiExtraModels()
export class GetExcludedBankTransactionResponseDto {
@ApiProperty({
description:
'Transaction amount (positive for deposit, negative for withdrawal)',
})
@IsNumber()
amount: number;
@ApiProperty({ description: 'Transaction date (ISO string or Date)' })
@IsDateString()
date: string | Date;
@ApiProperty({ description: 'ID of the associated bank account' })
@IsNumber()
accountId: number;
@ApiProperty({
description: 'Reference number for the transaction',
required: false,
})
@IsString()
@IsOptional()
referenceNo?: string;
@ApiProperty({ description: 'Payee name', required: false })
@IsString()
@IsOptional()
payee?: string;
@ApiProperty({ description: 'Transaction description', required: false })
@IsString()
@IsOptional()
description?: string;
@ApiProperty({ description: 'Plaid transaction ID', required: false })
@IsString()
@IsOptional()
plaidTransactionId?: string;
@ApiProperty({
description: 'Whether the transaction is pending',
required: false,
})
@IsBoolean()
@IsOptional()
pending?: boolean;
@ApiProperty({
description: 'ID of the recognized transaction, if any',
required: false,
})
@IsNumber()
@IsOptional()
recognizedTransactionId?: number;
@ApiProperty({
description: 'Categorization reference type',
required: false,
})
@IsString()
@IsOptional()
categorizeRefType?: string;
@ApiProperty({ description: 'Categorization reference ID', required: false })
@IsNumber()
@IsOptional()
categorizeRefId?: number;
@ApiProperty({
description: 'Formatted amount (localized string)',
required: false,
})
@IsString()
@IsOptional()
formattedAmount?: string;
@ApiProperty({ description: 'Formatted transaction date', required: false })
@IsString()
@IsOptional()
formattedDate?: string;
@ApiProperty({ description: 'Formatted deposit amount', required: false })
@IsString()
@IsOptional()
formattedDepositAmount?: string;
@ApiProperty({ description: 'Formatted withdrawal amount', required: false })
@IsString()
@IsOptional()
formattedWithdrawalAmount?: string;
@ApiProperty({ description: 'Withdrawal amount', required: false })
@IsNumber()
@IsOptional()
withdrawal?: number;
@ApiProperty({ description: 'Deposit amount', required: false })
@IsNumber()
@IsOptional()
deposit?: number;
@ApiProperty({ description: 'True if deposit transaction', required: false })
@IsBoolean()
@IsOptional()
isDepositTransaction?: boolean;
@ApiProperty({
description: 'True if withdrawal transaction',
required: false,
})
@IsBoolean()
@IsOptional()
isWithdrawalTransaction?: boolean;
@ApiProperty({
description: 'True if transaction is recognized',
required: false,
})
@IsBoolean()
@IsOptional()
isRecognized?: boolean;
@ApiProperty({
description: 'True if transaction is excluded',
required: false,
})
@IsBoolean()
@IsOptional()
isExcluded?: boolean;
@ApiProperty({
description: 'True if transaction is pending',
required: false,
})
@IsBoolean()
@IsOptional()
isPending?: boolean;
// Recognized transaction fields (from transformer)
@ApiProperty({
description: 'Assigned account ID from recognized transaction',
required: false,
})
@IsNumber()
@IsOptional()
assignedAccountId?: number;
@ApiProperty({
description: 'Assigned account name from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedAccountName?: string;
@ApiProperty({
description: 'Assigned account code from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedAccountCode?: string;
@ApiProperty({
description: 'Assigned payee from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedPayee?: string;
@ApiProperty({
description: 'Assigned memo from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedMemo?: string;
@ApiProperty({
description: 'Assigned category from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedCategory?: string;
@ApiProperty({
description: 'Assigned formatted category from recognized transaction',
required: false,
})
@IsString()
@IsOptional()
assignedCategoryFormatted?: string;
}

View File

@@ -0,0 +1,3 @@
import { UncategorizedTransactionTransformer } from '@/modules/BankingCategorize/commands/UncategorizedTransaction.transformer';
export class ExcludedBankTransactionTransformer extends UncategorizedTransactionTransformer {}

View File

@@ -1,9 +1,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { ExcludedBankTransactionsQuery } from '../types/BankTransactionsExclude.types';
import { UncategorizedTransactionTransformer } from '@/modules/BankingCategorize/commands/UncategorizedTransaction.transformer';
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ExcludedBankTransactionTransformer } from './ExcludedBankTransaction.transformer';
@Injectable()
export class GetExcludedBankTransactionsService {
@@ -60,7 +60,7 @@ export class GetExcludedBankTransactionsService {
const data = await this.transformer.transform(
results,
new UncategorizedTransactionTransformer(),
new ExcludedBankTransactionTransformer(),
);
return { data, pagination };
}