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,5 +1,7 @@
import { IsArray, IsInt, ArrayNotEmpty } from 'class-validator'; import { IsArray, IsInt, ArrayNotEmpty, IsBoolean, IsOptional } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { parseBoolean } from '@/utils/parse-boolean';
export class BulkDeleteDto { export class BulkDeleteDto {
@IsArray() @IsArray()
@@ -11,6 +13,16 @@ export class BulkDeleteDto {
example: [1, 2, 3], example: [1, 2, 3],
}) })
ids: number[]; ids: number[];
@IsOptional()
@IsBoolean()
@Transform(({ value }) => parseBoolean(value, false))
@ApiPropertyOptional({
description: 'When true, undeletable items will be skipped and only deletable ones will be removed.',
type: Boolean,
default: false,
})
skipUndeletable?: boolean;
} }
export class ValidateBulkDeleteResponseDto { export class ValidateBulkDeleteResponseDto {

View File

@@ -7,8 +7,6 @@ import {
Get, Get,
Query, Query,
ParseIntPipe, ParseIntPipe,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { AccountsApplication } from './AccountsApplication.service'; import { AccountsApplication } from './AccountsApplication.service';
import { CreateAccountDTO } from './CreateAccount.dto'; import { CreateAccountDTO } from './CreateAccount.dto';
@@ -66,24 +64,15 @@ export class AccountsController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple accounts in bulk.' }) @ApiOperation({ summary: 'Deletes multiple accounts in bulk.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable accounts will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'The accounts have been successfully deleted.', description: 'The accounts have been successfully deleted.',
}) })
async bulkDeleteAccounts( async bulkDeleteAccounts(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.accountsApplication.bulkDeleteAccounts(bulkDeleteDto.ids, { return this.accountsApplication.bulkDeleteAccounts(bulkDeleteDto.ids, {
skipUndeletable, skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
}); });
} }

View File

@@ -50,8 +50,12 @@ export class DeleteAccount {
/** /**
* Deletes the account from the storage. * Deletes the account from the storage.
* @param {number} accountId * @param {number} accountId
* @param {Knex.Transaction} trx - Database transaction instance.
*/ */
public deleteAccount = async (accountId: number): Promise<void> => { public deleteAccount = async (
accountId: number,
trx?: Knex.Transaction,
): Promise<void> => {
// Retrieve account or not found service error. // Retrieve account or not found service error.
const oldAccount = await this.accountModel().query().findById(accountId); const oldAccount = await this.accountModel().query().findById(accountId);
@@ -82,6 +86,6 @@ export class DeleteAccount {
oldAccount, oldAccount,
trx, trx,
} as IAccountEventDeletedPayload); } as IAccountEventDeletedPayload);
}); }, trx);
}; };
} }

View File

@@ -35,7 +35,7 @@ export class ValidateBulkDeleteAccountsService {
for (const accountId of accountIds) { for (const accountId of accountIds) {
try { try {
await this.deleteAccountService.deleteAccount(accountId); await this.deleteAccountService.deleteAccount(accountId, trx);
deletableIds.push(accountId); deletableIds.push(accountId);
} catch (error) { } catch (error) {
if (error instanceof ModelHasRelationsError) { if (error instanceof ModelHasRelationsError) {

View File

@@ -2,7 +2,6 @@ import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiParam, ApiParam,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -16,8 +15,6 @@ import {
Delete, Delete,
Get, Get,
Query, Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { BillsApplication } from './Bills.application'; import { BillsApplication } from './Bills.application';
import { IBillsFilter } from './Bills.types'; import { IBillsFilter } from './Bills.types';
@@ -59,24 +56,15 @@ export class BillsController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple bills.' }) @ApiOperation({ summary: 'Deletes multiple bills.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable bills will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Bills deleted successfully', description: 'Bills deleted successfully',
}) })
bulkDeleteBills( bulkDeleteBills(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.billsApplication.bulkDeleteBills(bulkDeleteDto.ids, { return this.billsApplication.bulkDeleteBills(bulkDeleteDto.ids, {
skipUndeletable, skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
}); });
} }

View File

@@ -27,7 +27,7 @@ export class ValidateBulkDeleteBillsService {
for (const billId of billIds) { for (const billId of billIds) {
try { try {
await this.deleteBillService.deleteBill(billId); await this.deleteBillService.deleteBill(billId, trx);
deletableIds.push(billId); deletableIds.push(billId);
} catch (error) { } catch (error) {
nonDeletableIds.push(billId); nonDeletableIds.push(billId);

View File

@@ -29,9 +29,10 @@ export class DeleteBill {
/** /**
* Deletes the bill with associated entries. * Deletes the bill with associated entries.
* @param {number} billId * @param {number} billId
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {void} * @return {void}
*/ */
public async deleteBill(billId: number) { public async deleteBill(billId: number, trx?: Knex.Transaction) {
// Retrieve the given bill or throw not found error. // Retrieve the given bill or throw not found error.
const oldBill = await this.billModel() const oldBill = await this.billModel()
.query() .query()
@@ -75,6 +76,6 @@ export class DeleteBill {
oldBill, oldBill,
trx, trx,
} as IBIllEventDeletedPayload); } as IBIllEventDeletedPayload);
}); }, trx);
} }
} }

View File

@@ -3,7 +3,6 @@ import {
ApiOperation, ApiOperation,
ApiResponse, ApiResponse,
ApiParam, ApiParam,
ApiQuery,
ApiExtraModels, ApiExtraModels,
getSchemaPath, getSchemaPath,
} from '@nestjs/swagger'; } from '@nestjs/swagger';
@@ -12,9 +11,7 @@ import {
Controller, Controller,
Delete, Delete,
Get, Get,
DefaultValuePipe,
Param, Param,
ParseBoolPipe,
Post, Post,
Put, Put,
Query, Query,
@@ -143,25 +140,16 @@ export class CreditNotesController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple credit notes.' }) @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({ @ApiResponse({
status: 200, status: 200,
description: 'Credit notes deleted successfully', description: 'Credit notes deleted successfully',
}) })
bulkDeleteCreditNotes( bulkDeleteCreditNotes(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.creditNoteApplication.bulkDeleteCreditNotes( return this.creditNoteApplication.bulkDeleteCreditNotes(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -9,7 +9,7 @@ export class ValidateBulkDeleteCreditNotesService {
private readonly deleteCreditNoteService: DeleteCreditNoteService, private readonly deleteCreditNoteService: DeleteCreditNoteService,
@Inject(TENANCY_DB_CONNECTION) @Inject(TENANCY_DB_CONNECTION)
private readonly tenantKnex: () => Knex, private readonly tenantKnex: () => Knex,
) {} ) { }
public async validateBulkDeleteCreditNotes(creditNoteIds: number[]): Promise<{ public async validateBulkDeleteCreditNotes(creditNoteIds: number[]): Promise<{
deletableCount: number; deletableCount: number;
@@ -27,7 +27,10 @@ export class ValidateBulkDeleteCreditNotesService {
for (const creditNoteId of creditNoteIds) { for (const creditNoteId of creditNoteIds) {
try { try {
await this.deleteCreditNoteService.deleteCreditNote(creditNoteId); await this.deleteCreditNoteService.deleteCreditNote(
creditNoteId,
trx,
);
deletableIds.push(creditNoteId); deletableIds.push(creditNoteId);
} catch (error) { } catch (error) {
nonDeletableIds.push(creditNoteId); nonDeletableIds.push(creditNoteId);

View File

@@ -49,9 +49,13 @@ export class DeleteCreditNoteService {
/** /**
* Deletes the given credit note transactions. * Deletes the given credit note transactions.
* @param {number} creditNoteId * @param {number} creditNoteId
* @param {Knex.Transaction} trx - Database transaction instance.
* @returns {Promise<void>} * @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. // Retrieve the credit note or throw not found service error.
const oldCreditNote = await this.creditNoteModel() const oldCreditNote = await this.creditNoteModel()
.query() .query()
@@ -88,7 +92,7 @@ export class DeleteCreditNoteService {
creditNoteId, creditNoteId,
trx, trx,
} as ICreditNoteDeletedPayload); } as ICreditNoteDeletedPayload);
}); }, trx);
} }
/** /**

View File

@@ -7,15 +7,12 @@ import {
Post, Post,
Put, Put,
Query, Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { ExpensesApplication } from './ExpensesApplication.service'; import { ExpensesApplication } from './ExpensesApplication.service';
import { IExpensesFilter } from './Expenses.types'; import { IExpensesFilter } from './Expenses.types';
import { import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -62,24 +59,15 @@ export class ExpensesController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple expenses.' }) @ApiOperation({ summary: 'Deletes multiple expenses.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable expenses will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Expenses deleted successfully', description: 'Expenses deleted successfully',
}) })
public bulkDeleteExpenses( public bulkDeleteExpenses(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
) { ) {
return this.expensesApplication.bulkDeleteExpenses(bulkDeleteDto.ids, { return this.expensesApplication.bulkDeleteExpenses(bulkDeleteDto.ids, {
skipUndeletable, skipUndeletable: bulkDeleteDto.skipUndeletable ?? false,
}); });
} }

View File

@@ -27,7 +27,7 @@ export class ValidateBulkDeleteExpensesService {
for (const expenseId of expenseIds) { for (const expenseId of expenseIds) {
try { try {
await this.deleteExpenseService.deleteExpense(expenseId); await this.deleteExpenseService.deleteExpense(expenseId, trx);
deletableIds.push(expenseId); deletableIds.push(expenseId);
} catch (error) { } catch (error) {
nonDeletableIds.push(expenseId); nonDeletableIds.push(expenseId);

View File

@@ -36,9 +36,12 @@ export class DeleteExpense {
/** /**
* Deletes the given expense. * Deletes the given expense.
* @param {number} expenseId * @param {number} expenseId
* @param {ISystemUser} authorizedUser * @param {Knex.Transaction} trx - Database transaction instance.
*/ */
public async deleteExpense(expenseId: number): Promise<void> { public async deleteExpense(
expenseId: number,
trx?: Knex.Transaction,
): Promise<void> {
// Retrieves the expense transaction with associated entries or // Retrieves the expense transaction with associated entries or
// throw not found error. // throw not found error.
const oldExpense = await this.expenseModel() const oldExpense = await this.expenseModel()
@@ -74,6 +77,6 @@ export class DeleteExpense {
oldExpense, oldExpense,
trx, trx,
} as IExpenseEventDeletePayload); } as IExpenseEventDeletePayload);
}); }, trx);
} }
} }

View File

@@ -27,7 +27,10 @@ export class ValidateBulkDeleteItemCategoriesService {
for (const itemCategoryId of itemCategoryIds) { for (const itemCategoryId of itemCategoryIds) {
try { try {
await this.deleteItemCategoryService.deleteItemCategory(itemCategoryId); await this.deleteItemCategoryService.deleteItemCategory(
itemCategoryId,
trx,
);
deletableIds.push(itemCategoryId); deletableIds.push(itemCategoryId);
} catch (error) { } catch (error) {
nonDeletableIds.push(itemCategoryId); nonDeletableIds.push(itemCategoryId);

View File

@@ -32,9 +32,13 @@ export class DeleteItemCategoryService {
/** /**
* Deletes the given item category. * Deletes the given item category.
* @param {number} itemCategoryId - Item category id. * @param {number} itemCategoryId - Item category id.
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {Promise<void>} * @return {Promise<void>}
*/ */
public async deleteItemCategory(itemCategoryId: number) { public async deleteItemCategory(
itemCategoryId: number,
trx?: Knex.Transaction,
) {
// Retrieve item category or throw not found error. // Retrieve item category or throw not found error.
const oldItemCategory = await this.itemCategoryModel() const oldItemCategory = await this.itemCategoryModel()
.query() .query()
@@ -56,7 +60,7 @@ export class DeleteItemCategoryService {
itemCategoryId, itemCategoryId,
oldItemCategory, oldItemCategory,
} as IItemCategoryDeletedPayload); } as IItemCategoryDeletedPayload);
}); }, trx);
} }
/** /**

View File

@@ -8,15 +8,12 @@ import {
Post, Post,
Put, Put,
Query, Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { ManualJournalsApplication } from './ManualJournalsApplication.service'; import { ManualJournalsApplication } from './ManualJournalsApplication.service';
import { import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiParam, ApiParam,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -64,25 +61,16 @@ export class ManualJournalsController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple manual journals.' }) @ApiOperation({ summary: 'Deletes multiple manual journals.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable journals will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Manual journals deleted successfully', description: 'Manual journals deleted successfully',
}) })
public bulkDeleteManualJournals( public bulkDeleteManualJournals(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.manualJournalsApplication.bulkDeleteManualJournals( return this.manualJournalsApplication.bulkDeleteManualJournals(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -31,6 +31,7 @@ export class ValidateBulkDeleteManualJournalsService {
try { try {
await this.deleteManualJournalService.deleteManualJournal( await this.deleteManualJournalService.deleteManualJournal(
manualJournalId, manualJournalId,
trx,
); );
deletableIds.push(manualJournalId); deletableIds.push(manualJournalId);
} catch (error) { } catch (error) {

View File

@@ -29,10 +29,12 @@ export class DeleteManualJournalService {
/** /**
* Deletes the given manual journal * Deletes the given manual journal
* @param {number} manualJournalId * @param {number} manualJournalId
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {Promise<void>} * @return {Promise<void>}
*/ */
public deleteManualJournal = async ( public deleteManualJournal = async (
manualJournalId: number, manualJournalId: number,
trx?: Knex.Transaction,
): Promise<{ ): Promise<{
oldManualJournal: ManualJournal; oldManualJournal: ManualJournal;
}> => { }> => {
@@ -70,6 +72,6 @@ export class DeleteManualJournalService {
} as IManualJournalEventDeletedPayload); } as IManualJournalEventDeletedPayload);
return { oldManualJournal }; return { oldManualJournal };
}); }, trx);
}; };
} }

View File

@@ -1,7 +1,6 @@
import { import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -14,12 +13,10 @@ import {
Headers, Headers,
HttpCode, HttpCode,
Param, Param,
ParseBoolPipe,
ParseIntPipe, ParseIntPipe,
Post, Post,
Put, Put,
Query, Query,
DefaultValuePipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { PaymentReceivesApplication } from './PaymentReceived.application'; import { PaymentReceivesApplication } from './PaymentReceived.application';
import { import {
@@ -174,25 +171,16 @@ export class PaymentReceivesController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple payments received.' }) @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({ @ApiResponse({
status: 200, status: 200,
description: 'Payments received deleted successfully.', description: 'Payments received deleted successfully.',
}) })
public bulkDeletePaymentsReceived( public bulkDeletePaymentsReceived(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
) { ) {
return this.paymentReceivesApplication.bulkDeletePaymentReceives( return this.paymentReceivesApplication.bulkDeletePaymentReceives(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

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

View File

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

View File

@@ -2,7 +2,6 @@ import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiParam, ApiParam,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -12,11 +11,9 @@ import {
Controller, Controller,
Delete, Delete,
Get, Get,
DefaultValuePipe,
Headers, Headers,
HttpCode, HttpCode,
Param, Param,
ParseBoolPipe,
ParseIntPipe, ParseIntPipe,
Post, Post,
Put, Put,
@@ -75,25 +72,16 @@ export class SaleEstimatesController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple sale estimates.' }) @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({ @ApiResponse({
status: 200, status: 200,
description: 'Sale estimates deleted successfully', description: 'Sale estimates deleted successfully',
}) })
public bulkDeleteSaleEstimates( public bulkDeleteSaleEstimates(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.saleEstimatesApplication.bulkDeleteSaleEstimates( return this.saleEstimatesApplication.bulkDeleteSaleEstimates(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -11,7 +11,9 @@ export class ValidateBulkDeleteSaleEstimatesService {
private readonly tenantKnex: () => Knex, private readonly tenantKnex: () => Knex,
) { } ) { }
public async validateBulkDeleteSaleEstimates(saleEstimateIds: number[]): Promise<{ public async validateBulkDeleteSaleEstimates(
saleEstimateIds: number[],
): Promise<{
deletableCount: number; deletableCount: number;
nonDeletableCount: number; nonDeletableCount: number;
deletableIds: number[]; deletableIds: number[];
@@ -27,7 +29,10 @@ export class ValidateBulkDeleteSaleEstimatesService {
for (const saleEstimateId of saleEstimateIds) { for (const saleEstimateId of saleEstimateIds) {
try { try {
await this.deleteSaleEstimateService.deleteEstimate(saleEstimateId); await this.deleteSaleEstimateService.deleteEstimate(
saleEstimateId,
trx,
);
deletableIds.push(saleEstimateId); deletableIds.push(saleEstimateId);
} catch (error) { } catch (error) {
nonDeletableIds.push(saleEstimateId); nonDeletableIds.push(saleEstimateId);
@@ -48,4 +53,3 @@ export class ValidateBulkDeleteSaleEstimatesService {
} }
} }
} }

View File

@@ -24,18 +24,22 @@ export class DeleteSaleEstimate {
private readonly eventPublisher: EventEmitter2, private readonly eventPublisher: EventEmitter2,
private readonly uow: UnitOfWork, private readonly uow: UnitOfWork,
) {} ) { }
/** /**
* Deletes the given estimate id with associated entries. * Deletes the given estimate id with associated entries.
* @async * @async
* @param {number} estimateId * @param {number} estimateId - Sale estimate id.
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {Promise<void>} * @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. // Retrieve sale estimate or throw not found service error.
const oldSaleEstimate = await this.saleEstimateModel() const oldSaleEstimate = await this.saleEstimateModel()
.query() .query(trx)
.findById(estimateId) .findById(estimateId)
.throwIfNotFound(); .throwIfNotFound();
@@ -70,6 +74,6 @@ export class DeleteSaleEstimate {
oldSaleEstimate, oldSaleEstimate,
trx, trx,
} as ISaleEstimateDeletedPayload); } as ISaleEstimateDeletedPayload);
}); }, trx);
} }
} }

View File

@@ -2,13 +2,11 @@ import { Response } from 'express';
import { import {
Body, Body,
Controller, Controller,
DefaultValuePipe,
Delete, Delete,
Get, Get,
Headers, Headers,
HttpCode, HttpCode,
Param, Param,
ParseBoolPipe,
ParseIntPipe, ParseIntPipe,
Post, Post,
Put, Put,
@@ -80,25 +78,16 @@ export class SaleInvoicesController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple sale invoices.' }) @ApiOperation({ summary: 'Deletes multiple sale invoices.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable invoices will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Sale invoices deleted successfully', description: 'Sale invoices deleted successfully',
}) })
bulkDeleteSaleInvoices( bulkDeleteSaleInvoices(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.saleInvoiceApplication.bulkDeleteSaleInvoices( return this.saleInvoiceApplication.bulkDeleteSaleInvoices(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -27,7 +27,10 @@ export class ValidateBulkDeleteSaleInvoicesService {
for (const saleInvoiceId of saleInvoiceIds) { for (const saleInvoiceId of saleInvoiceIds) {
try { try {
await this.deleteSaleInvoiceService.deleteSaleInvoice(saleInvoiceId); await this.deleteSaleInvoiceService.deleteSaleInvoice(
saleInvoiceId,
trx,
);
deletableIds.push(saleInvoiceId); deletableIds.push(saleInvoiceId);
} catch (error) { } catch (error) {
nonDeletableIds.push(saleInvoiceId); nonDeletableIds.push(saleInvoiceId);

View File

@@ -47,7 +47,7 @@ export class DeleteSaleInvoice {
@Inject(ItemEntry.name) @Inject(ItemEntry.name)
private itemEntryModel: TenantModelProxy<typeof ItemEntry>, private itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {} ) { }
/** /**
* Validate the sale invoice has no payment entries. * Validate the sale invoice has no payment entries.
@@ -86,9 +86,12 @@ export class DeleteSaleInvoice {
* Deletes the given sale invoice with associated entries * Deletes the given sale invoice with associated entries
* and journal transactions. * and journal transactions.
* @param {Number} saleInvoiceId - The given sale invoice id. * @param {Number} saleInvoiceId - The given sale invoice id.
* @param {ISystemUser} authorizedUser - * @param {Knex.Transaction} trx - Database transaction instance.
*/ */
public async deleteSaleInvoice(saleInvoiceId: number): Promise<void> { public async deleteSaleInvoice(
saleInvoiceId: number,
trx?: Knex.Transaction,
): Promise<void> {
// Retrieve the given sale invoice with associated entries // Retrieve the given sale invoice with associated entries
// or throw not found error. // or throw not found error.
const oldSaleInvoice = await this.saleInvoiceModel() const oldSaleInvoice = await this.saleInvoiceModel()
@@ -138,6 +141,6 @@ export class DeleteSaleInvoice {
saleInvoiceId, saleInvoiceId,
trx, trx,
} as ISaleInvoiceDeletedPayload); } as ISaleInvoiceDeletedPayload);
}); }, trx);
} }
} }

View File

@@ -6,8 +6,6 @@ import {
Headers, Headers,
HttpCode, HttpCode,
Param, Param,
ParseBoolPipe,
DefaultValuePipe,
ParseIntPipe, ParseIntPipe,
Post, Post,
Put, Put,
@@ -19,7 +17,6 @@ import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiParam, ApiParam,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -73,25 +70,16 @@ export class SaleReceiptsController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple sale receipts.' }) @ApiOperation({ summary: 'Deletes multiple sale receipts.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable receipts will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Sale receipts deleted successfully', description: 'Sale receipts deleted successfully',
}) })
bulkDeleteSaleReceipts( bulkDeleteSaleReceipts(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.saleReceiptApplication.bulkDeleteSaleReceipts( return this.saleReceiptApplication.bulkDeleteSaleReceipts(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -29,7 +29,10 @@ export class ValidateBulkDeleteSaleReceiptsService {
for (const saleReceiptId of saleReceiptIds) { for (const saleReceiptId of saleReceiptIds) {
try { try {
await this.deleteSaleReceiptService.deleteSaleReceipt(saleReceiptId); await this.deleteSaleReceiptService.deleteSaleReceipt(
saleReceiptId,
trx,
);
deletableIds.push(saleReceiptId); deletableIds.push(saleReceiptId);
} catch (error) { } catch (error) {
nonDeletableIds.push(saleReceiptId); nonDeletableIds.push(saleReceiptId);

View File

@@ -29,9 +29,13 @@ export class DeleteSaleReceipt {
/** /**
* Deletes the sale receipt with associated entries. * Deletes the sale receipt with associated entries.
* @param {Integer} saleReceiptId - Sale receipt identifier. * @param {Integer} saleReceiptId - Sale receipt identifier.
* @param {Knex.Transaction} trx - Database transaction instance.
* @return {void} * @return {void}
*/ */
public async deleteSaleReceipt(saleReceiptId: number) { public async deleteSaleReceipt(
saleReceiptId: number,
trx?: Knex.Transaction,
) {
const oldSaleReceipt = await this.saleReceiptModel() const oldSaleReceipt = await this.saleReceiptModel()
.query() .query()
.findById(saleReceiptId) .findById(saleReceiptId)
@@ -65,6 +69,6 @@ export class DeleteSaleReceipt {
oldSaleReceipt, oldSaleReceipt,
trx, trx,
} as ISaleReceiptEventDeletedPayload); } as ISaleReceiptEventDeletedPayload);
}); }, trx);
} }
} }

View File

@@ -31,6 +31,7 @@ export class ValidateBulkDeleteVendorCreditsService {
try { try {
await this.deleteVendorCreditService.deleteVendorCredit( await this.deleteVendorCreditService.deleteVendorCredit(
vendorCreditId, vendorCreditId,
trx,
); );
deletableIds.push(vendorCreditId); deletableIds.push(vendorCreditId);
} catch (error) { } catch (error) {

View File

@@ -7,15 +7,12 @@ import {
Post, Post,
Put, Put,
Query, Query,
DefaultValuePipe,
ParseBoolPipe,
} from '@nestjs/common'; } from '@nestjs/common';
import { VendorCreditsApplicationService } from './VendorCreditsApplication.service'; import { VendorCreditsApplicationService } from './VendorCreditsApplication.service';
import { IVendorCreditsQueryDTO } from './types/VendorCredit.types'; import { IVendorCreditsQueryDTO } from './types/VendorCredit.types';
import { import {
ApiExtraModels, ApiExtraModels,
ApiOperation, ApiOperation,
ApiQuery,
ApiResponse, ApiResponse,
ApiTags, ApiTags,
getSchemaPath, getSchemaPath,
@@ -62,25 +59,16 @@ export class VendorCreditsController {
@Post('bulk-delete') @Post('bulk-delete')
@ApiOperation({ summary: 'Deletes multiple vendor credits.' }) @ApiOperation({ summary: 'Deletes multiple vendor credits.' })
@ApiQuery({
name: 'skip_undeletable',
required: false,
type: Boolean,
description:
'When true, undeletable vendor credits will be skipped and only deletable ones will be removed.',
})
@ApiResponse({ @ApiResponse({
status: 200, status: 200,
description: 'Vendor credits deleted successfully', description: 'Vendor credits deleted successfully',
}) })
async bulkDeleteVendorCredits( async bulkDeleteVendorCredits(
@Body() bulkDeleteDto: BulkDeleteDto, @Body() bulkDeleteDto: BulkDeleteDto,
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
skipUndeletable: boolean,
): Promise<void> { ): Promise<void> {
return this.vendorCreditsApplication.bulkDeleteVendorCredits( return this.vendorCreditsApplication.bulkDeleteVendorCredits(
bulkDeleteDto.ids, bulkDeleteDto.ids,
{ skipUndeletable }, { skipUndeletable: bulkDeleteDto.skipUndeletable ?? false },
); );
} }

View File

@@ -93,7 +93,7 @@ export class DeleteVendorCreditService {
oldVendorCredit, oldVendorCredit,
trx, trx,
} as IVendorCreditDeletedPayload); } as IVendorCreditDeletedPayload);
}); }, trx);
}; };
/** /**

View File

@@ -46,8 +46,8 @@ function AccountBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('accounts-table'); queryCache.invalidateQueries('accounts-table');
closeDialog(dialogName);
setAccountsSelectedRows([]); setAccountsSelectedRows([]);
closeDialog(dialogName);
}) })
.catch((errors) => { .catch((errors) => {
handleDeleteErrors(errors); handleDeleteErrors(errors);

View File

@@ -45,8 +45,8 @@ function BillBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('bills-table'); queryCache.invalidateQueries('bills-table');
closeDialog(dialogName);
setBillsSelectedRows([]); setBillsSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -46,8 +46,8 @@ function CreditNoteBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('credit-notes-table'); queryCache.invalidateQueries('credit-notes-table');
closeDialog(dialogName);
setCreditNotesSelectedRows([]); setCreditNotesSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -46,8 +46,8 @@ function EstimateBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('estimates-table'); queryCache.invalidateQueries('estimates-table');
closeDialog(dialogName);
setEstimatesSelectedRows([]); setEstimatesSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -46,8 +46,8 @@ function ExpenseBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('expenses-table'); queryCache.invalidateQueries('expenses-table');
closeDialog(dialogName);
setExpensesSelectedRows([]); setExpensesSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -51,8 +51,8 @@ function InvoiceBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('invoices-table'); queryCache.invalidateQueries('invoices-table');
closeDialog(dialogName);
resetInvoicesSelectedRows(); resetInvoicesSelectedRows();
closeDialog(dialogName);
}) })
.catch((errors) => { .catch((errors) => {
AppToaster.show({ AppToaster.show({

View File

@@ -46,8 +46,8 @@ function ManualJournalBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('manual-journals-table'); queryCache.invalidateQueries('manual-journals-table');
closeDialog(dialogName);
setManualJournalsSelectedRows([]); setManualJournalsSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -48,8 +48,8 @@ function PaymentReceivedBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('payments-received-table'); queryCache.invalidateQueries('payments-received-table');
closeDialog(dialogName);
setPaymentReceivesSelectedRows([]); setPaymentReceivesSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -46,8 +46,8 @@ function ReceiptBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('sale-receipts-table'); queryCache.invalidateQueries('sale-receipts-table');
closeDialog(dialogName);
setReceiptsSelectedRows([]); setReceiptsSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -48,8 +48,8 @@ function VendorCreditBulkDeleteDialog({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
queryCache.invalidateQueries('vendor-credits-table'); queryCache.invalidateQueries('vendor-credits-table');
closeDialog(dialogName);
setVendorsCreditNoteSelectedRows([]); setVendorsCreditNoteSelectedRows([]);
closeDialog(dialogName);
}) })
.catch(() => { .catch(() => {
AppToaster.show({ AppToaster.show({

View File

@@ -165,15 +165,10 @@ export function useBulkDeleteAccounts(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('accounts/bulk-delete', {
'accounts/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -126,15 +126,10 @@ export function useBulkDeleteCreditNotes(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('credit-notes/bulk-delete', {
'credit-notes/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -139,15 +139,10 @@ export function useBulkDeleteEstimates(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('sale-estimates/bulk-delete', {
'sale-estimates/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -117,15 +117,10 @@ export function useBulkDeleteExpenses(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('expenses/bulk-delete', {
'expenses/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -140,15 +140,10 @@ export function useBulkDeleteInvoices(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('sale-invoices/bulk-delete', {
'sale-invoices/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -103,15 +103,10 @@ export function useBulkDeleteManualJournals(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('manual-journals/bulk-delete', {
'manual-journals/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -165,15 +165,10 @@ export function useBulkDeletePaymentReceives(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('payments-received/bulk-delete', {
'payments-received/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -119,15 +119,10 @@ export function useBulkDeleteReceipts(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('sale-receipts/bulk-delete', {
'sale-receipts/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.

View File

@@ -128,15 +128,10 @@ export function useBulkDeleteVendorCredits(props) {
ids: number[]; ids: number[];
skipUndeletable?: boolean; skipUndeletable?: boolean;
}) => }) =>
apiRequest.post( apiRequest.post('vendor-credits/bulk-delete', {
'vendor-credits/bulk-delete', ids,
{ ids }, skipUndeletable,
{ }),
params: skipUndeletable
? { skip_undeletable: true }
: undefined,
},
),
{ {
onSuccess: () => { onSuccess: () => {
// Common invalidate queries. // Common invalidate queries.