mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
wip
This commit is contained in:
@@ -12,17 +12,25 @@ export class BulkDeleteSaleReceiptsService {
|
||||
|
||||
async bulkDeleteSaleReceipts(
|
||||
saleReceiptIds: number | number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const receiptIds = uniq(castArray(saleReceiptIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(receiptIds)
|
||||
.process(async (saleReceiptId: number) => {
|
||||
await this.deleteSaleReceiptService.deleteSaleReceipt(saleReceiptId);
|
||||
try {
|
||||
await this.deleteSaleReceiptService.deleteSaleReceipt(saleReceiptId);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +93,13 @@ export class SaleReceiptApplication {
|
||||
* Deletes multiple sale receipts.
|
||||
* @param {number[]} saleReceiptIds
|
||||
*/
|
||||
public async bulkDeleteSaleReceipts(saleReceiptIds: number[]) {
|
||||
public async bulkDeleteSaleReceipts(
|
||||
saleReceiptIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeleteSaleReceiptsService.bulkDeleteSaleReceipts(
|
||||
saleReceiptIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
DefaultValuePipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
@@ -17,6 +19,7 @@ import {
|
||||
ApiExtraModels,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
@@ -70,13 +73,25 @@ export class SaleReceiptsController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple sale receipts.' })
|
||||
@ApiQuery({
|
||||
name: 'skip_undeletable',
|
||||
required: false,
|
||||
type: Boolean,
|
||||
description:
|
||||
'When true, undeletable receipts will be skipped and only deletable ones will be removed.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Sale receipts deleted successfully',
|
||||
})
|
||||
bulkDeleteSaleReceipts(@Body() bulkDeleteDto: BulkDeleteDto): Promise<void> {
|
||||
bulkDeleteSaleReceipts(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.saleReceiptApplication.bulkDeleteSaleReceipts(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user