fixed security breach in offers creation

This commit is contained in:
Kevsl
2024-06-18 21:27:12 +02:00
parent 3d38030791
commit 4a32d2b07a
3 changed files with 21 additions and 385 deletions

View File

@@ -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,