added token sell to bank

This commit is contained in:
Kevsl 2024-06-14 12:24:36 +02:00
parent def7d6ed69
commit fa1bd8b757

View File

@ -74,6 +74,7 @@ export class CryptoService {
id_crypto: dto.id_crypto,
},
});
const newCryptoValue = crypto.value * 0.9;
if (!userAsset || userAsset.amount < dto.amount) {
throw new ForbiddenException(`Seller dont have enough asset`);
} else {
@ -82,7 +83,7 @@ export class CryptoService {
id: crypto.id,
},
data: {
value: crypto.value * 0.9,
value: newCryptoValue,
},
});
@ -97,6 +98,12 @@ export class CryptoService {
dollarAvailables: newBalanceSeller,
},
});
await this.prisma.cryptoHistory.create({
data: {
id_crypto: crypto.id,
value: newCryptoValue,
},
});
const newBalance = userAsset.amount - dto.amount;
if (newBalance > 0) {
return this.prisma.userHasCrypto.update({