mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
wip
This commit is contained in:
@@ -61,8 +61,11 @@ export class BillsApplication {
|
||||
* Deletes multiple bills.
|
||||
* @param {number[]} billIds
|
||||
*/
|
||||
public bulkDeleteBills(billIds: number[]) {
|
||||
return this.bulkDeleteBillsService.bulkDeleteBills(billIds);
|
||||
public bulkDeleteBills(
|
||||
billIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeleteBillsService.bulkDeleteBills(billIds, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
ApiExtraModels,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
@@ -15,6 +16,8 @@ import {
|
||||
Delete,
|
||||
Get,
|
||||
Query,
|
||||
DefaultValuePipe,
|
||||
ParseBoolPipe,
|
||||
} from '@nestjs/common';
|
||||
import { BillsApplication } from './Bills.application';
|
||||
import { IBillsFilter } from './Bills.types';
|
||||
@@ -56,12 +59,25 @@ export class BillsController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple bills.' })
|
||||
@ApiQuery({
|
||||
name: 'skip_undeletable',
|
||||
required: false,
|
||||
type: Boolean,
|
||||
description:
|
||||
'When true, undeletable bills will be skipped and only deletable ones will be removed.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Bills deleted successfully',
|
||||
})
|
||||
bulkDeleteBills(@Body() bulkDeleteDto: BulkDeleteDto): Promise<void> {
|
||||
return this.billsApplication.bulkDeleteBills(bulkDeleteDto.ids);
|
||||
bulkDeleteBills(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.billsApplication.bulkDeleteBills(bulkDeleteDto.ids, {
|
||||
skipUndeletable,
|
||||
});
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
||||
@@ -10,17 +10,25 @@ export class BulkDeleteBillsService {
|
||||
|
||||
async bulkDeleteBills(
|
||||
billIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const billsIds = uniq(castArray(billIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(billsIds)
|
||||
.process(async (billId: number) => {
|
||||
await this.deleteBillService.deleteBill(billId);
|
||||
try {
|
||||
await this.deleteBillService.deleteBill(billId);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user