mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 06:00:12 +02:00
fixed offer creation
This commit is contained in:
parent
ebb017c07c
commit
8c571045f8
@ -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,
|
||||
|
@ -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) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user