mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 06:00:12 +02:00
added token sell to bank
This commit is contained in:
parent
def7d6ed69
commit
fa1bd8b757
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user