mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2026-02-06 10:36:12 +01:00
fixed security breach in offers creation
This commit is contained in:
@@ -42,6 +42,20 @@ export class OfferService {
|
||||
throw new ForbiddenException('Insuficient tokens avaiblable');
|
||||
}
|
||||
|
||||
const currentUserOffers = await this.prisma.offer.findMany({
|
||||
where: {
|
||||
id_user: userId,
|
||||
id_crypto: dto.id_crypto,
|
||||
},
|
||||
});
|
||||
let totalAmountsInOffers = 0;
|
||||
currentUserOffers.forEach((offer) => {
|
||||
totalAmountsInOffers += offer.amount;
|
||||
});
|
||||
if (totalAmountsInOffers > userAssets.amount) {
|
||||
throw new ForbiddenException('Insuficient tokens avaiblable');
|
||||
}
|
||||
|
||||
const offer = await this.prisma.offer.create({
|
||||
data: {
|
||||
id_crypto: dto.id_crypto,
|
||||
|
||||
Reference in New Issue
Block a user