mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2026-02-05 02:16:14 +01:00
added token sell to bank
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user