mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
wip
This commit is contained in:
@@ -2,13 +2,11 @@ import { Response } from 'express';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
Delete,
|
||||
Get,
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
@@ -80,25 +78,16 @@ export class SaleInvoicesController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple sale invoices.' })
|
||||
@ApiQuery({
|
||||
name: 'skip_undeletable',
|
||||
required: false,
|
||||
type: Boolean,
|
||||
description:
|
||||
'When true, undeletable invoices will be skipped and only deletable ones will be removed.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Sale invoices deleted successfully',
|
||||
})
|
||||
bulkDeleteSaleInvoices(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.saleInvoiceApplication.bulkDeleteSaleInvoices(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
{ skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ export class ValidateBulkDeleteSaleInvoicesService {
|
||||
|
||||
for (const saleInvoiceId of saleInvoiceIds) {
|
||||
try {
|
||||
await this.deleteSaleInvoiceService.deleteSaleInvoice(saleInvoiceId);
|
||||
await this.deleteSaleInvoiceService.deleteSaleInvoice(
|
||||
saleInvoiceId,
|
||||
trx,
|
||||
);
|
||||
deletableIds.push(saleInvoiceId);
|
||||
} catch (error) {
|
||||
nonDeletableIds.push(saleInvoiceId);
|
||||
|
||||
@@ -47,7 +47,7 @@ export class DeleteSaleInvoice {
|
||||
|
||||
@Inject(ItemEntry.name)
|
||||
private itemEntryModel: TenantModelProxy<typeof ItemEntry>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Validate the sale invoice has no payment entries.
|
||||
@@ -86,9 +86,12 @@ export class DeleteSaleInvoice {
|
||||
* Deletes the given sale invoice with associated entries
|
||||
* and journal transactions.
|
||||
* @param {Number} saleInvoiceId - The given sale invoice id.
|
||||
* @param {ISystemUser} authorizedUser -
|
||||
* @param {Knex.Transaction} trx - Database transaction instance.
|
||||
*/
|
||||
public async deleteSaleInvoice(saleInvoiceId: number): Promise<void> {
|
||||
public async deleteSaleInvoice(
|
||||
saleInvoiceId: number,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
// Retrieve the given sale invoice with associated entries
|
||||
// or throw not found error.
|
||||
const oldSaleInvoice = await this.saleInvoiceModel()
|
||||
@@ -138,6 +141,6 @@ export class DeleteSaleInvoice {
|
||||
saleInvoiceId,
|
||||
trx,
|
||||
} as ISaleInvoiceDeletedPayload);
|
||||
});
|
||||
}, trx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user