mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 14: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,
|
id_crypto: dto.id_crypto,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const newCryptoValue = crypto.value * 0.9;
|
||||||
if (!userAsset || userAsset.amount < dto.amount) {
|
if (!userAsset || userAsset.amount < dto.amount) {
|
||||||
throw new ForbiddenException(`Seller dont have enough asset`);
|
throw new ForbiddenException(`Seller dont have enough asset`);
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +83,7 @@ export class CryptoService {
|
|||||||
id: crypto.id,
|
id: crypto.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
value: crypto.value * 0.9,
|
value: newCryptoValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -97,6 +98,12 @@ export class CryptoService {
|
|||||||
dollarAvailables: newBalanceSeller,
|
dollarAvailables: newBalanceSeller,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
await this.prisma.cryptoHistory.create({
|
||||||
|
data: {
|
||||||
|
id_crypto: crypto.id,
|
||||||
|
value: newCryptoValue,
|
||||||
|
},
|
||||||
|
});
|
||||||
const newBalance = userAsset.amount - dto.amount;
|
const newBalance = userAsset.amount - dto.amount;
|
||||||
if (newBalance > 0) {
|
if (newBalance > 0) {
|
||||||
return this.prisma.userHasCrypto.update({
|
return this.prisma.userHasCrypto.update({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user