mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2026-02-05 18:26:12 +01:00
added crypto history
This commit is contained in:
@@ -33,6 +33,11 @@ export class CryptoController {
|
||||
return this.promoService.searchCryptos(user.id, cryptoName);
|
||||
}
|
||||
|
||||
@Get('/history/:id')
|
||||
CryptoHistory(@GetUser() user: User, @Param('id') cryptoId: string) {
|
||||
return this.promoService.getCryptoHistory(user.id, cryptoId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post('/create')
|
||||
createPromoCode(
|
||||
|
||||
@@ -32,6 +32,23 @@ export class CryptoService {
|
||||
});
|
||||
}
|
||||
|
||||
async getCryptoHistory(userId: string, cryptoId: string) {
|
||||
await checkUserHasAccount(userId);
|
||||
|
||||
if (cryptoId) {
|
||||
return this.prisma.crypto.findMany({
|
||||
where: {
|
||||
id: cryptoId,
|
||||
},
|
||||
orderBy: {
|
||||
created_at: 'desc',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
throw new ForbiddenException('Crypto UUID required');
|
||||
}
|
||||
}
|
||||
|
||||
async createCrypto(userId: string, dto: CryptoDto) {
|
||||
await checkuserIsAdmin(userId);
|
||||
|
||||
@@ -103,6 +120,13 @@ export class CryptoService {
|
||||
}
|
||||
}
|
||||
const newCryptoValue = crypto.value * 1.1;
|
||||
|
||||
await this.prisma.cryptoHistory.create({
|
||||
data: {
|
||||
id_crypto: crypto.id,
|
||||
value: newCryptoValue,
|
||||
},
|
||||
});
|
||||
return this.prisma.crypto.update({
|
||||
where: {
|
||||
id: dto.id_crypto,
|
||||
@@ -111,8 +135,6 @@ export class CryptoService {
|
||||
value: newCryptoValue,
|
||||
},
|
||||
});
|
||||
|
||||
return crypto;
|
||||
}
|
||||
async editCryptoById(userId: string, cryptoId: string, dto: CryptoDto) {
|
||||
await checkuserIsAdmin(userId);
|
||||
|
||||
@@ -117,6 +117,12 @@ export class TradeService {
|
||||
}
|
||||
|
||||
const newValue = crypto.value * 1.1;
|
||||
await this.prisma.cryptoHistory.create({
|
||||
data: {
|
||||
id_crypto: crypto.id,
|
||||
value: newValue,
|
||||
},
|
||||
});
|
||||
|
||||
await this.prisma.crypto.update({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user