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

@@ -7,15 +7,12 @@ import {
Post,
Put,
Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common';
import { ExpensesApplication } from './ExpensesApplication.service';
import { IExpensesFilter } from './Expenses.types';
import {
ApiExtraModels,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
getSchemaPath,
@@ -62,24 +59,15 @@ export class ExpensesController {
@Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple expenses.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable expenses will be skipped and only deletable ones will be removed.',
})
@ApiResponse({
status: 200,
description: 'Expenses deleted successfully',
})
public bulkDeleteExpenses(
@Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
) {
return this.expensesApplication.bulkDeleteExpenses(bulkDeleteDto.ids, {
skipUndeletable,
skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
});
}

View File

@@ -27,7 +27,7 @@ export class ValidateBulkDeleteExpensesService {
for (const expenseId of expenseIds) {
try {
await this.deleteExpenseService.deleteExpense(expenseId);
await this.deleteExpenseService.deleteExpense(expenseId, trx);
deletableIds.push(expenseId);
} catch (error) {
nonDeletableIds.push(expenseId);

View File

@@ -36,9 +36,12 @@ export class DeleteExpense {
/**
* Deletes the given expense.
* @param {number} expenseId
* @param {ISystemUser} authorizedUser
* @param {Knex.Transaction} trx - Database transaction instance.
*/
public async deleteExpense(expenseId: number): Promise<void> {
public async deleteExpense(
expenseId: number,
trx?: Knex.Transaction,
): Promise<void> {
// Retrieves the expense transaction with associated entries or
// throw not found error.
const oldExpense = await this.expenseModel()
@@ -74,6 +77,6 @@ export class DeleteExpense {
oldExpense,
trx,
} as IExpenseEventDeletePayload);
});
}, trx);
}
}