fixed offer creation

This commit is contained in:
Kevsl 2024-06-13 12:15:42 +02:00
parent ebb017c07c
commit 8c571045f8
2 changed files with 13 additions and 1 deletions

View File

@ -29,6 +29,19 @@ export class OfferService {
async createOffer(userId: string, dto: OfferDto) {
await checkUserHasAccount(userId);
const userAssets = await this.prisma.userHasCrypto.findFirst({
where: {
id: userId,
Crypto: {
id: dto.id_crypto,
},
},
});
if (userAssets.amount < dto.amount) {
throw new ForbiddenException('Insuficient tokens avaiblable');
}
const offer = await this.prisma.offer.create({
data: {
id_crypto: dto.id_crypto,

View File

@ -2,7 +2,6 @@ import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { checkUserHasAccount, checkuserIsAdmin } from 'src/utils/checkUser';
import { TradeDto } from './dto';
import { of } from 'rxjs';
@Injectable()
export class TradeService {
constructor(private prisma: PrismaService) {}