mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
wip
This commit is contained in:
@@ -8,23 +8,31 @@ import { DeletePaymentReceivedService } from './commands/DeletePaymentReceived.s
|
||||
export class BulkDeletePaymentReceivedService {
|
||||
constructor(
|
||||
private readonly deletePaymentReceivedService: DeletePaymentReceivedService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async bulkDeletePaymentReceived(
|
||||
paymentReceiveIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const paymentsIds = uniq(castArray(paymentReceiveIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(paymentsIds)
|
||||
.process(async (paymentReceiveId: number) => {
|
||||
await this.deletePaymentReceivedService.deletePaymentReceive(
|
||||
paymentReceiveId,
|
||||
);
|
||||
try {
|
||||
await this.deletePaymentReceivedService.deletePaymentReceive(
|
||||
paymentReceiveId,
|
||||
);
|
||||
} catch (error) {
|
||||
if (!skipUndeletable) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (results.errors && results.errors.length > 0) {
|
||||
if (!skipUndeletable && results.errors && results.errors.length > 0) {
|
||||
throw results.errors[0].raw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,13 @@ export class PaymentReceivesApplication {
|
||||
* Deletes multiple payment receives.
|
||||
* @param {number[]} paymentReceiveIds
|
||||
*/
|
||||
public bulkDeletePaymentReceives(paymentReceiveIds: number[]) {
|
||||
public bulkDeletePaymentReceives(
|
||||
paymentReceiveIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeletePaymentReceivedService.bulkDeletePaymentReceived(
|
||||
paymentReceiveIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
ApiExtraModels,
|
||||
ApiOperation,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
@@ -13,10 +14,12 @@ import {
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
DefaultValuePipe,
|
||||
} from '@nestjs/common';
|
||||
import { PaymentReceivesApplication } from './PaymentReceived.application';
|
||||
import {
|
||||
@@ -171,13 +174,25 @@ 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) {
|
||||
public bulkDeletePaymentsReceived(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
) {
|
||||
return this.paymentReceivesApplication.bulkDeletePaymentReceives(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user