mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
wip
This commit is contained in:
@@ -10,19 +10,25 @@ export class BulkDeleteSaleInvoicesService {
|
||||
|
||||
async bulkDeleteSaleInvoices(
|
||||
saleInvoiceIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const invoicesIds = uniq(castArray(saleInvoiceIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(invoicesIds)
|
||||
.process(async (saleInvoiceId: number) => {
|
||||
await this.deleteSaleInvoiceService.deleteSaleInvoice(saleInvoiceId);
|
||||
try {
|
||||
await this.deleteSaleInvoiceService.deleteSaleInvoice(saleInvoiceId);
|
||||
} catch (error) {
|
||||
if (!skipUndeletable) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (results.errors && results.errors.length > 0) {
|
||||
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||
throw results.errors[0].raw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export class SaleInvoiceApplication {
|
||||
private generateShareLinkService: GenerateShareLink,
|
||||
private bulkDeleteSaleInvoicesService: BulkDeleteSaleInvoicesService,
|
||||
private validateBulkDeleteSaleInvoicesService: ValidateBulkDeleteSaleInvoicesService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Creates a new sale invoice with associated GL entries.
|
||||
@@ -87,9 +87,13 @@ export class SaleInvoiceApplication {
|
||||
* @param {number[]} saleInvoiceIds
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public bulkDeleteSaleInvoices(saleInvoiceIds: number[]) {
|
||||
public bulkDeleteSaleInvoices(
|
||||
saleInvoiceIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeleteSaleInvoicesService.bulkDeleteSaleInvoices(
|
||||
saleInvoiceIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ import { Response } from 'express';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
Delete,
|
||||
Get,
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
@@ -78,13 +80,25 @@ 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): Promise<void> {
|
||||
bulkDeleteSaleInvoices(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.saleInvoiceApplication.bulkDeleteSaleInvoices(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user