Skip to content

Commit

Permalink
src/withdrawal: Allow deletion of withdrawal records
Browse files Browse the repository at this point in the history
When withdrawal record is deleted decrement blockedAmount of the vault, with the amount of the withdrawal
  • Loading branch information
sashko9807 committed Dec 10, 2023
1 parent 3a41008 commit 7bcdecb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions apps/api/src/withdrawal/withdrawal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,21 @@ export class WithdrawalService {
return result
}

// Functionality will be reworked soon
async remove(id: string): Promise<Withdrawal | null> {
throw new ForbiddenException()
const result = await this.prisma.withdrawal.delete({ where: { id: id } })
if (!result) throw new NotFoundException('Not found')
const result = await this.prisma.withdrawal
.delete({
where: { id: id, status: { not: WithdrawStatus.succeeded } },
})
.catch(() => {
throw new BadRequestException("Withdrawal record couldn't be deleted")
})

await this.prisma.vault.update({
where: { id: result.sourceVaultId },
data: {
blockedAmount: { decrement: result.amount },
},
})
return result
}
}

0 comments on commit 7bcdecb

Please sign in to comment.