mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
refactor(nestjs): wip
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
||||
|
||||
@Controller('credit-notes')
|
||||
@ApiTags('credit-notes-apply-invoice')
|
||||
export class CreditNotesApplyInvoiceController {
|
||||
constructor(
|
||||
private readonly getCreditNoteAssociatedAppliedInvoicesService: GetCreditNoteAssociatedAppliedInvoices,
|
||||
) {}
|
||||
|
||||
@Get(':creditNoteId/applied-invoices')
|
||||
@ApiOperation({ summary: 'Applied credit note to invoices' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Credit note successfully applied to invoices',
|
||||
})
|
||||
@ApiResponse({ status: 404, description: 'Credit note not found' })
|
||||
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
||||
appliedCreditNoteToInvoices(@Param('creditNoteId') creditNoteId: number) {
|
||||
return this.getCreditNoteAssociatedAppliedInvoicesService.getCreditAssociatedAppliedInvoices(
|
||||
creditNoteId,
|
||||
);
|
||||
}
|
||||
|
||||
@Post(':creditNoteId/apply-invoices')
|
||||
@ApiOperation({ summary: 'Apply credit note to invoices' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Credit note successfully applied to invoices',
|
||||
})
|
||||
@ApiResponse({ status: 404, description: 'Credit note not found' })
|
||||
@ApiResponse({ status: 400, description: 'Invalid input data' })
|
||||
applyCreditNoteToInvoices(@Param('creditNoteId') creditNoteId: number) {
|
||||
return this.getCreditNoteAssociatedAppliedInvoicesService.getCreditAssociatedAppliedInvoices(
|
||||
creditNoteId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { PaymentsReceivedModule } from '../PaymentReceived/PaymentsReceived.modu
|
||||
import { CreditNotesModule } from '../CreditNotes/CreditNotes.module';
|
||||
import { GetCreditNoteAssociatedAppliedInvoices } from './queries/GetCreditNoteAssociatedAppliedInvoices.service';
|
||||
import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteAssociatedInvoicesToApply.service';
|
||||
import { CreditNotesApplyInvoiceController } from './CreditNotesApplyInvoice.controller';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
@@ -16,12 +17,11 @@ import { GetCreditNoteAssociatedInvoicesToApply } from './queries/GetCreditNoteA
|
||||
CreditNoteApplyToInvoices,
|
||||
CreditNoteApplySyncInvoicesCreditedAmount,
|
||||
CreditNoteApplySyncCredit,
|
||||
// GetCreditNoteAssociatedAppliedInvoices,
|
||||
// GetCreditNoteAssociatedInvoicesToApply
|
||||
],
|
||||
exports: [
|
||||
DeleteCustomerLinkedCreditNoteService,
|
||||
GetCreditNoteAssociatedAppliedInvoices,
|
||||
GetCreditNoteAssociatedInvoicesToApply,
|
||||
],
|
||||
exports: [DeleteCustomerLinkedCreditNoteService],
|
||||
imports: [PaymentsReceivedModule, forwardRef(() => CreditNotesModule)],
|
||||
controllers: [CreditNotesApplyInvoiceController],
|
||||
})
|
||||
export class CreditNotesApplyInvoiceModule {}
|
||||
|
||||
@@ -7,9 +7,16 @@ import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetCreditNoteAssociatedAppliedInvoices {
|
||||
/**
|
||||
* @param {TransformerInjectable} transformer - The transformer service.
|
||||
* @param {TenantModelProxy<typeof CreditNoteAppliedInvoice>} creditNoteAppliedInvoiceModel - The credit note applied invoice model.
|
||||
* @param {TenantModelProxy<typeof CreditNote>} creditNoteModel - The credit note model.
|
||||
*/
|
||||
constructor(
|
||||
private readonly transformer: TransformerInjectable,
|
||||
private readonly creditNoteAppliedInvoiceModel: typeof CreditNoteAppliedInvoice,
|
||||
|
||||
@Inject(CreditNoteAppliedInvoice.name)
|
||||
private readonly creditNoteAppliedInvoiceModel: TenantModelProxy<typeof CreditNoteAppliedInvoice>,
|
||||
|
||||
@Inject(CreditNote.name)
|
||||
private readonly creditNoteModel: TenantModelProxy<typeof CreditNote>,
|
||||
@@ -29,7 +36,7 @@ export class GetCreditNoteAssociatedAppliedInvoices {
|
||||
.findById(creditNoteId)
|
||||
.throwIfNotFound();
|
||||
|
||||
const appliedToInvoices = await this.creditNoteAppliedInvoiceModel
|
||||
const appliedToInvoices = await this.creditNoteAppliedInvoiceModel()
|
||||
.query()
|
||||
.where('credit_note_id', creditNoteId)
|
||||
.withGraphFetched('saleInvoice')
|
||||
|
||||
@@ -10,7 +10,7 @@ export class GetCreditNoteAssociatedInvoicesToApply {
|
||||
/**
|
||||
* @param {TransformerInjectable} transformer - Transformer service.
|
||||
* @param {GetCreditNote} getCreditNote - Get credit note service.
|
||||
* @param {typeof SaleInvoice} saleInvoiceModel - Sale invoice model.
|
||||
* @param {TenantModelProxy<typeof SaleInvoice>} saleInvoiceModel - Sale invoice model.
|
||||
*/
|
||||
constructor(
|
||||
private transformer: TransformerInjectable,
|
||||
|
||||
Reference in New Issue
Block a user