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
7f00cfb382
commit
def7d6ed69
@ -60,6 +60,10 @@ export class CryptoService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user = await this.prisma.user.findFirst({
|
||||||
|
where: { id: userId },
|
||||||
|
});
|
||||||
|
|
||||||
if (!crypto || !crypto.id) {
|
if (!crypto || !crypto.id) {
|
||||||
throw new ForbiddenException('Crypto doesnt exist');
|
throw new ForbiddenException('Crypto doesnt exist');
|
||||||
}
|
}
|
||||||
@ -82,6 +86,17 @@ export class CryptoService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const price = crypto.value * dto.amount;
|
||||||
|
const newBalanceSeller = user.dollarAvailables + price;
|
||||||
|
|
||||||
|
await this.prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
dollarAvailables: newBalanceSeller,
|
||||||
|
},
|
||||||
|
});
|
||||||
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