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

@@ -1,7 +1,6 @@
import {
ApiExtraModels,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
getSchemaPath,
@@ -14,12 +13,10 @@ import {
Headers,
HttpCode,
Param,
ParseBoolPipe,
ParseIntPipe,
Post,
Put,
Query,
DefaultValuePipe,
} from '@nestjs/common';
import { PaymentReceivesApplication } from './PaymentReceived.application';
import {
@@ -174,25 +171,16 @@ export class PaymentReceivesController {
@Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple payments received.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable payments will be skipped and only deletable ones will be removed.',
})
@ApiResponse({
status: 200,
description: 'Payments received deleted successfully.',
})
public bulkDeletePaymentsReceived(
@Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
) {
return this.paymentReceivesApplication.bulkDeletePaymentReceives(
bulkDeleteDto.ids,
{ skipUndeletable },
{ skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
);
}

View File

@@ -9,7 +9,7 @@ export class ValidateBulkDeletePaymentReceivedService {
private readonly deletePaymentReceivedService: DeletePaymentReceivedService,
@Inject(TENANCY_DB_CONNECTION)
private readonly tenantKnex: () => Knex,
) {}
) { }
public async validateBulkDeletePaymentReceived(
paymentReceiveIds: number[],
@@ -31,6 +31,7 @@ export class ValidateBulkDeletePaymentReceivedService {
try {
await this.deletePaymentReceivedService.deletePaymentReceive(
paymentReceiveId,
trx,
);
deletableIds.push(paymentReceiveId);
} catch (error) {

View File

@@ -30,7 +30,7 @@ export class DeletePaymentReceivedService {
private paymentReceiveEntryModel: TenantModelProxy<
typeof PaymentReceivedEntry
>,
) {}
) { }
/**
* Deletes the given payment receive with associated entries
@@ -43,9 +43,12 @@ export class DeletePaymentReceivedService {
* - Revert the payment amount of the associated invoices.
* @async
* @param {Integer} paymentReceiveId - Payment receive id.
* @param {IPaymentReceived} paymentReceive - Payment receive object.
* @param {Knex.Transaction} trx - Database transaction instance.
*/
public async deletePaymentReceive(paymentReceiveId: number) {
public async deletePaymentReceive(
paymentReceiveId: number,
trx?: Knex.Transaction,
) {
// Retreive payment receive or throw not found service error.
const oldPaymentReceive = await this.paymentReceiveModel()
.query()
@@ -79,6 +82,6 @@ export class DeletePaymentReceivedService {
oldPaymentReceive,
trx,
} as IPaymentReceivedDeletedPayload);
});
}, trx);
}
}