mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 22:00:12 +02:00
fixed offers creation
This commit is contained in:
parent
03e83e5392
commit
5068cab40a
@ -1,4 +1,8 @@
|
|||||||
import { ForbiddenException, Injectable } from '@nestjs/common';
|
import {
|
||||||
|
ForbiddenException,
|
||||||
|
ImATeapotException,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { checkUserHasAccount, checkuserIsAdmin } from 'src/utils/checkUser';
|
import { checkUserHasAccount, checkuserIsAdmin } from 'src/utils/checkUser';
|
||||||
import { OfferDto } from './dto';
|
import { OfferDto } from './dto';
|
||||||
@ -38,6 +42,11 @@ export class OfferService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!userAssets) {
|
||||||
|
throw new ForbiddenException('No tokens available');
|
||||||
|
}
|
||||||
|
|
||||||
if (userAssets.amount < dto.amount) {
|
if (userAssets.amount < dto.amount) {
|
||||||
throw new ForbiddenException('Insuficient tokens avaiblable');
|
throw new ForbiddenException('Insuficient tokens avaiblable');
|
||||||
}
|
}
|
||||||
@ -52,9 +61,10 @@ export class OfferService {
|
|||||||
currentUserOffers.forEach((offer) => {
|
currentUserOffers.forEach((offer) => {
|
||||||
totalAmountsInOffers += offer.amount;
|
totalAmountsInOffers += offer.amount;
|
||||||
});
|
});
|
||||||
|
console.log(totalAmountsInOffers);
|
||||||
|
|
||||||
if (totalAmountsInOffers > userAssets.amount) {
|
if (totalAmountsInOffers >= userAssets.amount) {
|
||||||
throw new ForbiddenException('Insuficient tokens avaiblable');
|
throw new ImATeapotException('Insuficient tokens avaiblable');
|
||||||
}
|
}
|
||||||
|
|
||||||
const offer = await this.prisma.offer.create({
|
const offer = await this.prisma.offer.create({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user