From 0a89676b7e6af822adf753a2512618ef3e33392f Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 7 Dec 2024 21:11:37 +0100 Subject: [PATCH] =?UTF-8?q?Stockage=20de=20l'heure=20de=20d=C3=A9but=20et?= =?UTF-8?q?=20des=20heures=20de=20p=C3=A9nalit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 5 +++++ server/prisma/schema.prisma | 18 +++++++++++------- .../entities/challenge-action.entity.ts | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 server/prisma/migrations/20241207200719_challenge_penalty/migration.sql diff --git a/server/prisma/migrations/20241207200719_challenge_penalty/migration.sql b/server/prisma/migrations/20241207200719_challenge_penalty/migration.sql new file mode 100644 index 0000000..19ab9bf --- /dev/null +++ b/server/prisma/migrations/20241207200719_challenge_penalty/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "ChallengeAction" ADD COLUMN "end" TIMESTAMP(3), +ADD COLUMN "penaltyEnd" TIMESTAMP(3), +ADD COLUMN "penaltyStart" TIMESTAMP(3), +ADD COLUMN "start" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index c5a5104..a84b425 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -41,13 +41,17 @@ model Challenge { } model ChallengeAction { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId Int - challenge Challenge @relation(fields: [challengeId], references: [id]) - challengeId Int @unique - active Boolean @default(false) - success Boolean @default(false) + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId Int + challenge Challenge @relation(fields: [challengeId], references: [id]) + challengeId Int @unique + active Boolean @default(false) + success Boolean @default(false) + start DateTime @default(now()) + end DateTime? + penaltyStart DateTime? + penaltyEnd DateTime? moneyUpdate MoneyUpdate? } diff --git a/server/src/challenge-actions/entities/challenge-action.entity.ts b/server/src/challenge-actions/entities/challenge-action.entity.ts index 3990d05..8c990d8 100644 --- a/server/src/challenge-actions/entities/challenge-action.entity.ts +++ b/server/src/challenge-actions/entities/challenge-action.entity.ts @@ -1,7 +1,8 @@ import { ApiProperty } from "@nestjs/swagger" import { ChallengeAction } from "@prisma/client" +import { IsOptional } from "class-validator" -export class ChallengeActionEntity implements ChallengeAction { +export default class ChallengeActionEntity implements ChallengeAction { constructor(partial: Partial) { Object.assign(this, partial) } @@ -20,4 +21,19 @@ export class ChallengeActionEntity implements ChallengeAction { @ApiProperty({ description: "Est-ce que le défi a été réussi" }) success: boolean + + @ApiProperty({ description: "Heure à laquelle le défi a été démarré" }) + start: Date + + @IsOptional() + @ApiProperty({ description: "Heure à laquelle le défi a été terminé", required: false, nullable: true }) + end: Date + + @IsOptional() + @ApiProperty({ description: "Heure à laquelle la pénalité a commencé, si applicable", required: false, nullable: true }) + penaltyStart: Date + + @IsOptional() + @ApiProperty({ description: "Heure à laquelle la pénalité s'est terminée, si applicable", required: false, nullable: true }) + penaltyEnd: Date }