mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
wip
This commit is contained in:
@@ -12,17 +12,25 @@ export class BulkDeleteCreditNotesService {
|
||||
|
||||
async bulkDeleteCreditNotes(
|
||||
creditNoteIds: number | Array<number>,
|
||||
options?: { skipUndeletable?: boolean },
|
||||
trx?: Knex.Transaction,
|
||||
): Promise<void> {
|
||||
const { skipUndeletable = false } = options ?? {};
|
||||
const notesIds = uniq(castArray(creditNoteIds));
|
||||
|
||||
const results = await PromisePool.withConcurrency(1)
|
||||
.for(notesIds)
|
||||
.process(async (creditNoteId: number) => {
|
||||
await this.deleteCreditNoteService.deleteCreditNote(creditNoteId);
|
||||
try {
|
||||
await this.deleteCreditNoteService.deleteCreditNote(creditNoteId);
|
||||
} 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