mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
wip
This commit is contained in:
@@ -10,17 +10,25 @@ export class BulkDeleteSaleEstimatesService {
|
||||
|
||||
async bulkDeleteSaleEstimates(
|
||||
saleEstimateIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const estimatesIds = uniq(castArray(saleEstimateIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(estimatesIds)
|
||||
.process(async (saleEstimateId: number) => {
|
||||
await this.deleteSaleEstimateService.deleteEstimate(saleEstimateId);
|
||||
try {
|
||||
await this.deleteSaleEstimateService.deleteEstimate(saleEstimateId);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export class SaleEstimatesApplication {
|
||||
private readonly getSaleEstimateMailStateService: GetSaleEstimateMailStateService,
|
||||
private readonly bulkDeleteSaleEstimatesService: BulkDeleteSaleEstimatesService,
|
||||
private readonly validateBulkDeleteSaleEstimatesService: ValidateBulkDeleteSaleEstimatesService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Create a sale estimate.
|
||||
@@ -77,9 +77,13 @@ export class SaleEstimatesApplication {
|
||||
* @param {number[]} saleEstimateIds
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public bulkDeleteSaleEstimates(saleEstimateIds: number[]) {
|
||||
public bulkDeleteSaleEstimates(
|
||||
saleEstimateIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
) {
|
||||
return this.bulkDeleteSaleEstimatesService.bulkDeleteSaleEstimates(
|
||||
saleEstimateIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
ApiExtraModels,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
@@ -11,9 +12,11 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
DefaultValuePipe,
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
@@ -72,15 +75,25 @@ export class SaleEstimatesController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@ApiOperation({ summary: 'Deletes multiple sale estimates.' })
|
||||
@ApiQuery({
|
||||
name: 'skip_undeletable',
|
||||
required: false,
|
||||
type: Boolean,
|
||||
description:
|
||||
'When true, undeletable estimates will be skipped and only deletable ones will be removed.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Sale estimates deleted successfully',
|
||||
})
|
||||
public bulkDeleteSaleEstimates(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.saleEstimatesApplication.bulkDeleteSaleEstimates(
|
||||
bulkDeleteDto.ids,
|
||||
{ skipUndeletable },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user