mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
wip
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user