From b44ffcd380a68833c315976e71907395390d9c4d Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 8 Dec 2024 11:39:57 +0100 Subject: [PATCH] =?UTF-8?q?Stockage=20du=20montant=20de=20la=20modificatio?= =?UTF-8?q?n=20plut=C3=B4t=20que=20le=20avant/apr=C3=A8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 13 +++++++++++ server/prisma/schema.prisma | 22 +++++++++---------- .../dto/create-money-update.dto.ts | 16 +++++++------- .../entities/money-update.entity.ts | 11 +++++----- 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 server/prisma/migrations/20241208103715_store_money_update_amount/migration.sql diff --git a/server/prisma/migrations/20241208103715_store_money_update_amount/migration.sql b/server/prisma/migrations/20241208103715_store_money_update_amount/migration.sql new file mode 100644 index 0000000..b3c720a --- /dev/null +++ b/server/prisma/migrations/20241208103715_store_money_update_amount/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the column `after` on the `MoneyUpdate` table. All the data in the column will be lost. + - You are about to drop the column `before` on the `MoneyUpdate` table. All the data in the column will be lost. + - Added the required column `amount` to the `MoneyUpdate` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "MoneyUpdate" DROP COLUMN "after", +DROP COLUMN "before", +ADD COLUMN "amount" INTEGER NOT NULL, +ADD COLUMN "timestamp" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index e3ca76b..6770eb0 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -52,7 +52,7 @@ model ChallengeAction { end DateTime? @db.Timestamptz(3) penaltyStart DateTime? @db.Timestamptz(3) penaltyEnd DateTime? @db.Timestamptz(3) - moneyUpdate MoneyUpdate? + moneyUpdate MoneyUpdate? } model TrainTrip { @@ -69,16 +69,16 @@ model TrainTrip { } model MoneyUpdate { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId Int - before Int - after Int - reason MoneyUpdateType - action ChallengeAction? @relation(fields: [actionId], references: [id]) - actionId Int? @unique - trip TrainTrip? @relation(fields: [tripId], references: [id]) - tripId String? @unique + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId Int + amount Int + reason MoneyUpdateType + action ChallengeAction? @relation(fields: [actionId], references: [id]) + actionId Int? @unique + trip TrainTrip? @relation(fields: [tripId], references: [id]) + tripId String? @unique + timestamp DateTime @default(now()) @db.Timestamptz(3) } enum MoneyUpdateType { diff --git a/server/src/money-updates/dto/create-money-update.dto.ts b/server/src/money-updates/dto/create-money-update.dto.ts index 32aeb79..c3b8886 100644 --- a/server/src/money-updates/dto/create-money-update.dto.ts +++ b/server/src/money-updates/dto/create-money-update.dto.ts @@ -1,18 +1,13 @@ import { ApiProperty } from "@nestjs/swagger" import { MoneyUpdateType } from "@prisma/client" import { Type } from "class-transformer" -import { IsEnum, IsInt, IsOptional, IsUUID } from "class-validator" +import { IsDate, IsEnum, IsInt, IsOptional, IsUUID } from "class-validator" export class CreateMoneyUpdateDto { @IsInt() @Type(() => Number) - @ApiProperty({ description: "Solde avant modification" }) - before: number - - @IsInt() - @Type(() => Number) - @ApiProperty({ description: "Solde après modification" }) - after: number + @ApiProperty({ description: "Montant de la modification de solde" }) + amount: number @IsEnum(MoneyUpdateType) @ApiProperty({ description: "Type de modification de solde" }) @@ -28,4 +23,9 @@ export class CreateMoneyUpdateDto { @IsUUID() @ApiProperty({ description: "Identifiant du trajet acheté, si la mise à jour est liée à la réservation d'un train", nullable: true }) tripId?: string + + @IsDate() + @Type(() => Date) + @ApiProperty({ description: "Date et heure de la modification de solde" }) + timestamp: Date } diff --git a/server/src/money-updates/entities/money-update.entity.ts b/server/src/money-updates/entities/money-update.entity.ts index 7fb734d..d29560b 100644 --- a/server/src/money-updates/entities/money-update.entity.ts +++ b/server/src/money-updates/entities/money-update.entity.ts @@ -1,6 +1,5 @@ import { ApiProperty } from "@nestjs/swagger" import { MoneyUpdate, MoneyUpdateType } from "@prisma/client" -import { IsOptional } from "class-validator" export class MoneyUpdateEntity implements MoneyUpdate { constructor (partial: Partial) { @@ -13,11 +12,8 @@ export class MoneyUpdateEntity implements MoneyUpdate { @ApiProperty({ description: "Utilisateur⋅rice concerné⋅e par la mise à jour de solde" }) userId: number - @ApiProperty({ description: "Solde avant modification" }) - before: number - - @ApiProperty({ description: "Solde après modification" }) - after: number + @ApiProperty({ description: "Montant de la modification du solde" }) + amount: number @ApiProperty({ description: "Type de modification de solde" }) reason: MoneyUpdateType @@ -27,4 +23,7 @@ export class MoneyUpdateEntity implements MoneyUpdate { @ApiProperty({ description: "Identifiant du trajet acheté, si la mise à jour est liée à la réservation d'un train", nullable: true }) tripId: string + + @ApiProperty({ description: "Date et heure de la modification de solde" }) + timestamp: Date }