mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
wip
This commit is contained in:
@@ -2,7 +2,6 @@ import {
|
||||
ApiExtraModels,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
getSchemaPath,
|
||||
@@ -12,11 +11,9 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
DefaultValuePipe,
|
||||
Headers,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseBoolPipe,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Put,
|
||||
@@ -75,25 +72,16 @@ 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 },
|
||||
{ skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ export class ValidateBulkDeleteSaleEstimatesService {
|
||||
private readonly tenantKnex: () => Knex,
|
||||
) { }
|
||||
|
||||
public async validateBulkDeleteSaleEstimates(saleEstimateIds: number[]): Promise<{
|
||||
public async validateBulkDeleteSaleEstimates(
|
||||
saleEstimateIds: number[],
|
||||
): Promise<{
|
||||
deletableCount: number;
|
||||
nonDeletableCount: number;
|
||||
deletableIds: number[];
|
||||
@@ -27,7 +29,10 @@ export class ValidateBulkDeleteSaleEstimatesService {
|
||||
|
||||
for (const saleEstimateId of saleEstimateIds) {
|
||||
try {
|
||||
await this.deleteSaleEstimateService.deleteEstimate(saleEstimateId);
|
||||
await this.deleteSaleEstimateService.deleteEstimate(
|
||||
saleEstimateId,
|
||||
trx,
|
||||
);
|
||||
deletableIds.push(saleEstimateId);
|
||||
} catch (error) {
|
||||
nonDeletableIds.push(saleEstimateId);
|
||||
@@ -48,4 +53,3 @@ export class ValidateBulkDeleteSaleEstimatesService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,18 +24,22 @@ export class DeleteSaleEstimate {
|
||||
|
||||
private readonly eventPublisher: EventEmitter2,
|
||||
private readonly uow: UnitOfWork,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Deletes the given estimate id with associated entries.
|
||||
* @async
|
||||
* @param {number} estimateId
|
||||
* @param {number} estimateId - Sale estimate id.
|
||||
* @param {Knex.Transaction} trx - Database transaction instance.
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public async deleteEstimate(estimateId: number): Promise<void> {
|
||||
public async deleteEstimate(
|
||||
estimateId: number,
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
// Retrieve sale estimate or throw not found service error.
|
||||
const oldSaleEstimate = await this.saleEstimateModel()
|
||||
.query()
|
||||
.query(trx)
|
||||
.findById(estimateId)
|
||||
.throwIfNotFound();
|
||||
|
||||
@@ -70,6 +74,6 @@ export class DeleteSaleEstimate {
|
||||
oldSaleEstimate,
|
||||
trx,
|
||||
} as ISaleEstimateDeletedPayload);
|
||||
});
|
||||
}, trx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user