This commit is contained in:
Ahmed Bouhuolia
2025-11-19 23:42:06 +02:00
parent 5eafd23bf8
commit d90b6ffbe7
52 changed files with 161 additions and 261 deletions

View File

@@ -2,7 +2,6 @@ import {
ApiExtraModels,
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
getSchemaPath,
@@ -16,8 +15,6 @@ import {
Delete,
Get,
Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common';
import { BillsApplication } from './Bills.application';
import { IBillsFilter } from './Bills.types';
@@ -59,24 +56,15 @@ 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,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> {
return this.billsApplication.bulkDeleteBills(bulkDeleteDto.ids, {
skipUndeletable,
skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
});
}

View File

@@ -27,7 +27,7 @@ export class ValidateBulkDeleteBillsService {
for (const billId of billIds) {
try {
await this.deleteBillService.deleteBill(billId);
await this.deleteBillService.deleteBill(billId, trx);
deletableIds.push(billId);
} catch (error) {
nonDeletableIds.push(billId);

View File

@@ -29,9 +29,10 @@ export class DeleteBill {
/**
* Deletes the bill with associated entries.
* @param {number} billId
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {void}
*/
public async deleteBill(billId: number) {
public async deleteBill(billId: number, trx?: Knex.Transaction) {
// Retrieve the given bill or throw not found error.
const oldBill = await this.billModel()
.query()
@@ -75,6 +76,6 @@ export class DeleteBill {
oldBill,
trx,
} as IBIllEventDeletedPayload);
});
}, trx);
}
}