mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
wip
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiExtraModels,
|
||||
getSchemaPath,
|
||||
} from '@nestjs/swagger';
|
||||
@@ -12,9 +11,7 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
DefaultValuePipe,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
@@ -143,25 +140,16 @@ export class CreditNotesController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple credit notes.' })
|
||||
@ApiQuery({
|
||||
name: 'skip_undeletable',
|
||||
required: false,
|
||||
type: Boolean,
|
||||
description:
|
||||
'When true, undeletable credit notes will be skipped and only deletable ones will be removed.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Credit notes deleted successfully',
|
||||
})
|
||||
bulkDeleteCreditNotes(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.creditNoteApplication.bulkDeleteCreditNotes(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
{ skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export class ValidateBulkDeleteCreditNotesService {
|
||||
private readonly deleteCreditNoteService: DeleteCreditNoteService,
|
||||
@Inject(TENANCY_DB_CONNECTION)
|
||||
private readonly tenantKnex: () => Knex,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
public async validateBulkDeleteCreditNotes(creditNoteIds: number[]): Promise<{
|
||||
deletableCount: number;
|
||||
@@ -27,7 +27,10 @@ export class ValidateBulkDeleteCreditNotesService {
|
||||
|
||||
for (const creditNoteId of creditNoteIds) {
|
||||
try {
|
||||
await this.deleteCreditNoteService.deleteCreditNote(creditNoteId);
|
||||
await this.deleteCreditNoteService.deleteCreditNote(
|
||||
creditNoteId,
|
||||
trx,
|
||||
);
|
||||
deletableIds.push(creditNoteId);
|
||||
} catch (error) {
|
||||
nonDeletableIds.push(creditNoteId);
|
||||
|
||||
@@ -49,9 +49,13 @@ export class DeleteCreditNoteService {
|
||||
/**
|
||||
* Deletes the given credit note transactions.
|
||||
* @param {number} creditNoteId
|
||||
* @param {Knex.Transaction} trx - Database transaction instance.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async deleteCreditNote(creditNoteId: number): Promise<void> {
|
||||
public async deleteCreditNote(
|
||||
creditNoteId: number,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
// Retrieve the credit note or throw not found service error.
|
||||
const oldCreditNote = await this.creditNoteModel()
|
||||
.query()
|
||||
@@ -88,7 +92,7 @@ export class DeleteCreditNoteService {
|
||||
creditNoteId,
|
||||
trx,
|
||||
} as ICreditNoteDeletedPayload);
|
||||
});
|
||||
}, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user