mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
refactor(nestjs): wip dtos validation schema
This commit is contained in:
@@ -15,11 +15,15 @@ import {
|
||||
EditBillPaymentDto,
|
||||
} from './dtos/BillPayment.dto';
|
||||
import { GetBillPaymentsFilterDto } from './dtos/GetBillPaymentsFilter.dto';
|
||||
import { BillPaymentsPages } from './commands/BillPaymentsPages.service';
|
||||
|
||||
@Controller('bill-payments')
|
||||
@ApiTags('bill-payments')
|
||||
export class BillPaymentsController {
|
||||
constructor(private billPaymentsApplication: BillPaymentsApplication) {}
|
||||
constructor(
|
||||
private billPaymentsApplication: BillPaymentsApplication,
|
||||
private billPaymentsPagesService: BillPaymentsPages,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new bill payment.' })
|
||||
@@ -59,6 +63,24 @@ export class BillPaymentsController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get('/new-page/entries')
|
||||
@ApiOperation({
|
||||
summary:
|
||||
'Retrieves the payable entries of the new page once vendor be selected.',
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'vendorId',
|
||||
required: true,
|
||||
type: Number,
|
||||
description: 'The vendor id',
|
||||
})
|
||||
async getBillPaymentNewPageEntries(@Query('vendorId') vendorId: number) {
|
||||
const entries =
|
||||
await this.billPaymentsPagesService.getNewPageEntries(vendorId);
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Get(':billPaymentId/bills')
|
||||
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
|
||||
@ApiParam({
|
||||
@@ -71,6 +93,25 @@ export class BillPaymentsController {
|
||||
return this.billPaymentsApplication.getPaymentBills(Number(billPaymentId));
|
||||
}
|
||||
|
||||
@Get('/:billPaymentId/edit-page')
|
||||
@ApiOperation({
|
||||
summary: 'Retrieves the edit page of the given bill payment.',
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'billPaymentId',
|
||||
required: true,
|
||||
type: Number,
|
||||
description: 'The bill payment id',
|
||||
})
|
||||
public async getBillPaymentEditPage(
|
||||
@Param('billPaymentId') billPaymentId: number,
|
||||
) {
|
||||
const billPaymentsWithEditEntries =
|
||||
await this.billPaymentsPagesService.getBillPaymentEditPage(billPaymentId);
|
||||
|
||||
return billPaymentsWithEditEntries;
|
||||
}
|
||||
|
||||
@Get(':billPaymentId')
|
||||
@ApiOperation({ summary: 'Retrieves the bill payment details.' })
|
||||
@ApiParam({
|
||||
@@ -83,8 +124,14 @@ export class BillPaymentsController {
|
||||
return this.billPaymentsApplication.getBillPayment(Number(billPaymentId));
|
||||
}
|
||||
|
||||
@Get('')
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Retrieves the bill payments list.' })
|
||||
@ApiParam({
|
||||
name: 'filterDTO',
|
||||
required: true,
|
||||
type: GetBillPaymentsFilterDto,
|
||||
description: 'The bill payments filter dto',
|
||||
})
|
||||
public getBillPayments(@Query() filterDTO: GetBillPaymentsFilterDto) {
|
||||
return this.billPaymentsApplication.getBillPayments(filterDTO);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { BillPaymentsExportable } from './queries/BillPaymentsExportable';
|
||||
import { BillPaymentsImportable } from './commands/BillPaymentsImportable';
|
||||
import { GetBillPaymentsService } from './queries/GetBillPayments.service';
|
||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
import { BillPaymentsPages } from './commands/BillPaymentsPages.service';
|
||||
|
||||
@Module({
|
||||
imports: [LedgerModule, AccountsModule, DynamicListModule],
|
||||
@@ -41,6 +42,7 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
BillPaymentsExportable,
|
||||
BillPaymentsImportable,
|
||||
GetBillPaymentsService,
|
||||
BillPaymentsPages,
|
||||
],
|
||||
exports: [
|
||||
BillPaymentValidators,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ServiceError } from '../../Items/ServiceError';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export default class BillPaymentsPages {
|
||||
export class BillPaymentsPages {
|
||||
/**
|
||||
* @param {TenantModelProxy<typeof Bill>} billModel - Bill model.
|
||||
* @param {TenantModelProxy<typeof BillPayment>} billPaymentModel - Bill payment model.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
IsDate,
|
||||
IsDateString,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
@@ -9,25 +10,33 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ToNumber } from '@/common/decorators/Validators';
|
||||
|
||||
export class BillPaymentEntryDto {
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({ description: 'The id of the bill', example: 1 })
|
||||
billId: number;
|
||||
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({
|
||||
description: 'The payment amount of the bill payment',
|
||||
example: 100,
|
||||
})
|
||||
paymentAmount: number;
|
||||
}
|
||||
|
||||
export class CommandBillPaymentDTO {
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({
|
||||
description: 'The id of the vendor',
|
||||
example: 1,
|
||||
})
|
||||
@ApiProperty({ description: 'The id of the vendor', example: 1 })
|
||||
vendorId: number;
|
||||
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
@@ -36,12 +45,10 @@ export class CommandBillPaymentDTO {
|
||||
})
|
||||
amount?: number;
|
||||
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({
|
||||
description: 'The id of the payment account',
|
||||
example: 1,
|
||||
})
|
||||
@ApiProperty({ description: 'The id of the payment account', example: 1 })
|
||||
paymentAccountId: number;
|
||||
|
||||
@IsString()
|
||||
@@ -52,8 +59,8 @@ export class CommandBillPaymentDTO {
|
||||
})
|
||||
paymentNumber?: string;
|
||||
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
@IsDateString()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({
|
||||
description: 'The payment date of the bill payment',
|
||||
example: '2021-01-01',
|
||||
@@ -76,7 +83,6 @@ export class CommandBillPaymentDTO {
|
||||
})
|
||||
statement?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@@ -92,12 +98,10 @@ export class CommandBillPaymentDTO {
|
||||
})
|
||||
entries: BillPaymentEntryDto[];
|
||||
|
||||
@ToNumber()
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
description: 'The id of the branch',
|
||||
example: 1,
|
||||
})
|
||||
@ApiProperty({ description: 'The id of the branch', example: 1 })
|
||||
branchId?: number;
|
||||
|
||||
@IsArray()
|
||||
|
||||
Reference in New Issue
Block a user