added crypto history

This commit is contained in:
Kevsl
2024-06-07 15:55:20 +02:00
parent 73fd9bf8a1
commit f4abd98d8c
5 changed files with 57 additions and 2 deletions

View File

@@ -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(

View File

@@ -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);

View File

@@ -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: {