mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 14:00:12 +02:00
added crypto history
This commit is contained in:
parent
73fd9bf8a1
commit
f4abd98d8c
13
prisma/migrations/20240607134613_/migration.sql
Normal file
13
prisma/migrations/20240607134613_/migration.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "CryptoHistory" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"id_crypto" TEXT NOT NULL,
|
||||||
|
"value" DOUBLE PRECISION NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
CONSTRAINT "CryptoHistory_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "CryptoHistory" ADD CONSTRAINT "CryptoHistory_id_crypto_fkey" FOREIGN KEY ("id_crypto") REFERENCES "Crypto"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -19,8 +19,17 @@ model Crypto {
|
|||||||
UserHasCrypto UserHasCrypto[]
|
UserHasCrypto UserHasCrypto[]
|
||||||
Trade Trade[]
|
Trade Trade[]
|
||||||
Offer Offer[]
|
Offer Offer[]
|
||||||
|
CryptoHistory CryptoHistory[]
|
||||||
}
|
}
|
||||||
|
model CryptoHistory {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
id_crypto String
|
||||||
|
value Float
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt @default(now())
|
||||||
|
Crypto Crypto @relation(fields: [id_crypto], references: [id])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
model Offer {
|
model Offer {
|
||||||
|
@ -33,6 +33,11 @@ export class CryptoController {
|
|||||||
return this.promoService.searchCryptos(user.id, cryptoName);
|
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)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
@Post('/create')
|
@Post('/create')
|
||||||
createPromoCode(
|
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) {
|
async createCrypto(userId: string, dto: CryptoDto) {
|
||||||
await checkuserIsAdmin(userId);
|
await checkuserIsAdmin(userId);
|
||||||
|
|
||||||
@ -103,6 +120,13 @@ export class CryptoService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const newCryptoValue = crypto.value * 1.1;
|
const newCryptoValue = crypto.value * 1.1;
|
||||||
|
|
||||||
|
await this.prisma.cryptoHistory.create({
|
||||||
|
data: {
|
||||||
|
id_crypto: crypto.id,
|
||||||
|
value: newCryptoValue,
|
||||||
|
},
|
||||||
|
});
|
||||||
return this.prisma.crypto.update({
|
return this.prisma.crypto.update({
|
||||||
where: {
|
where: {
|
||||||
id: dto.id_crypto,
|
id: dto.id_crypto,
|
||||||
@ -111,8 +135,6 @@ export class CryptoService {
|
|||||||
value: newCryptoValue,
|
value: newCryptoValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return crypto;
|
|
||||||
}
|
}
|
||||||
async editCryptoById(userId: string, cryptoId: string, dto: CryptoDto) {
|
async editCryptoById(userId: string, cryptoId: string, dto: CryptoDto) {
|
||||||
await checkuserIsAdmin(userId);
|
await checkuserIsAdmin(userId);
|
||||||
|
@ -117,6 +117,12 @@ export class TradeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newValue = crypto.value * 1.1;
|
const newValue = crypto.value * 1.1;
|
||||||
|
await this.prisma.cryptoHistory.create({
|
||||||
|
data: {
|
||||||
|
id_crypto: crypto.id,
|
||||||
|
value: newValue,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await this.prisma.crypto.update({
|
await this.prisma.crypto.update({
|
||||||
where: {
|
where: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user