mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
wip
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
Get,
|
||||
Query,
|
||||
ParseIntPipe,
|
||||
DefaultValuePipe,
|
||||
ParseBoolPipe,
|
||||
} from '@nestjs/common';
|
||||
import { AccountsApplication } from './AccountsApplication.service';
|
||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||
@@ -64,14 +66,25 @@ export class AccountsController {
|
||||
|
||||
@Post('bulk-delete')
|
||||
@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({
|
||||
status: 200,
|
||||
description: 'The accounts have been successfully deleted.',
|
||||
})
|
||||
async bulkDeleteAccounts(
|
||||
@Body() bulkDeleteDto: BulkDeleteDto,
|
||||
@Query('skip_undeletable', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
skipUndeletable: boolean,
|
||||
): Promise<void> {
|
||||
return this.accountsApplication.bulkDeleteAccounts(bulkDeleteDto.ids);
|
||||
return this.accountsApplication.bulkDeleteAccounts(bulkDeleteDto.ids, {
|
||||
skipUndeletable,
|
||||
});
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
||||
@@ -42,7 +42,7 @@ export class AccountsApplication {
|
||||
private readonly getAccountsService: GetAccountsService,
|
||||
private readonly bulkDeleteAccountsService: BulkDeleteAccountsService,
|
||||
private readonly validateBulkDeleteAccountsService: ValidateBulkDeleteAccountsService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Creates a new account.
|
||||
@@ -148,7 +148,13 @@ export class AccountsApplication {
|
||||
/**
|
||||
* Deletes multiple accounts in bulk.
|
||||
*/
|
||||
public bulkDeleteAccounts = (accountIds: number[]): Promise<void> => {
|
||||
return this.bulkDeleteAccountsService.bulkDeleteAccounts(accountIds);
|
||||
public bulkDeleteAccounts = (
|
||||
accountIds: number[],
|
||||
options?: { skipUndeletable?: boolean },
|
||||
): Promise<void> => {
|
||||
return this.bulkDeleteAccountsService.bulkDeleteAccounts(
|
||||
accountIds,
|
||||
options,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,17 +15,25 @@ export class BulkDeleteAccountsService {
|
||||
*/
|
||||
async bulkDeleteAccounts(
|
||||
accountIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const accountsIds = uniq(castArray(accountIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(accountsIds)
|
||||
.process(async (accountId: number) => {
|
||||
await this.deleteAccountService.deleteAccount(accountId);
|
||||
try {
|
||||
await this.deleteAccountService.deleteAccount(accountId);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user