Browse Source

refactor(workout-set): remove unused columns valueInt, valueSec, and unit from workout_sets table and related schemas to simplify data structure
feat(workout-session): implement nullToUndefined utility function to handle null values in workout session data more gracefully

Mathias 1 month ago
parent
commit
015f3bbee8

+ 12 - 0
prisma/migrations/20250614153656_remove_value_int_value_sec_unit_from_workoutset/migration.sql

@@ -0,0 +1,12 @@
+/*
+  Warnings:
+
+  - You are about to drop the column `unit` on the `workout_sets` table. All the data in the column will be lost.
+  - You are about to drop the column `valueInt` on the `workout_sets` table. All the data in the column will be lost.
+  - You are about to drop the column `valueSec` on the `workout_sets` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "workout_sets" DROP COLUMN "unit",
+DROP COLUMN "valueInt",
+DROP COLUMN "valueSec";

+ 0 - 3
prisma/schema.prisma

@@ -296,11 +296,8 @@ model WorkoutSet {
   setIndex                 Int
   type                     WorkoutSetType
   types                    WorkoutSetType[]       @default([])
-  valueInt                 Int? // reps, poids, minutes, etc.
   valuesInt                Int[]                  @default([])
-  valueSec                 Int? // secondes si TIME
   valuesSec                Int[]                  @default([])
-  unit                     WorkoutSetUnit?
   units                    WorkoutSetUnit[]       @default([])
   completed                Boolean                @default(false)
   workoutSessionExercise   WorkoutSessionExercise @relation(fields: [workoutSessionExerciseId], references: [id])

+ 0 - 9
src/features/workout-session/actions/sync-workout-sessions.action.ts

@@ -11,11 +11,8 @@ const workoutSetSchema = z.object({
   id: z.string(),
   setIndex: z.number(),
   types: z.array(z.enum(["TIME", "WEIGHT", "REPS", "BODYWEIGHT", "NA"])),
-  valueInt: z.number().optional(),
   valuesInt: z.array(z.number()).optional(),
-  valueSec: z.number().optional(),
   valuesSec: z.array(z.number()).optional(),
-  unit: z.enum(["kg", "lbs"]).optional(),
   units: z.array(z.enum(["kg", "lbs"])).optional(),
   completed: z.boolean(),
 });
@@ -55,11 +52,8 @@ export const syncWorkoutSessionAction = actionClient.schema(syncWorkoutSessionSc
               create: exercise.sets.map((set) => ({
                 setIndex: set.setIndex,
                 types: set.types,
-                valueInt: set.valueInt,
                 valuesInt: set.valuesInt,
-                valueSec: set.valueSec,
                 valuesSec: set.valuesSec,
-                unit: set.unit,
                 units: set.units,
                 completed: set.completed,
                 type: set.types && set.types.length > 0 ? set.types[0] : "NA",
@@ -81,11 +75,8 @@ export const syncWorkoutSessionAction = actionClient.schema(syncWorkoutSessionSc
               create: exercise.sets.map((set) => ({
                 setIndex: set.setIndex,
                 types: set.types,
-                valueInt: set.valueInt,
                 valuesInt: set.valuesInt,
-                valueSec: set.valueSec,
                 valuesSec: set.valuesSec,
-                unit: set.unit,
                 units: set.units,
                 completed: set.completed,
                 type: set.types && set.types.length > 0 ? set.types[0] : "NA",

+ 0 - 1
src/features/workout-session/schema/workout-session-set.schema.ts

@@ -5,7 +5,6 @@ export const workoutSessionSetSchema = z.object({
   setIndex: z.number().int().min(0),
   type: z.enum(["TIME", "WEIGHT", "REPS", "BODYWEIGHT", "NA"]),
   types: z.array(z.enum(["TIME", "WEIGHT", "REPS", "BODYWEIGHT", "NA"])).optional(),
-  valueInt: z.number().int().optional(),
   valuesInt: z.array(z.number().int()).optional(),
   valueSec: z.number().int().min(0).max(59).optional(),
   valuesSec: z.array(z.number().int().min(0).max(59)).optional(),

+ 0 - 3
src/features/workout-session/types/workout-set.ts

@@ -7,11 +7,8 @@ export interface WorkoutSet {
   id: string;
   setIndex: number;
   types: WorkoutSetType[]; // To support multiple columns
-  valueInt?: number; // reps, weight, minutes, etc.
   valuesInt?: number[]; // To support multiple columns
-  valueSec?: number; // seconds (if TIME)
   valuesSec?: number[]; // To support multiple columns
-  unit?: WorkoutSetUnit;
   units?: WorkoutSetUnit[]; // Pour supporter plusieurs colonnes
   completed: boolean;
 }

+ 3 - 0
src/shared/lib/format.ts

@@ -0,0 +1,3 @@
+export function nullToUndefined<T>(value: T | null): T | undefined {
+  return value === null ? undefined : value;
+}

+ 8 - 8
src/shared/lib/workout-session/use-workout-session.service.ts

@@ -1,3 +1,4 @@
+import { nullToUndefined } from "@/shared/lib/format";
 import { syncWorkoutSessionAction } from "@/features/workout-session/actions/sync-workout-sessions.action";
 import { getWorkoutSessionsAction } from "@/features/workout-session/actions/get-workout-sessions.action";
 import { useSession } from "@/features/auth/lib/auth-client";
@@ -32,17 +33,16 @@ export const useWorkoutSessionService = () => {
             : typeof session.endedAt === "string"
               ? session.endedAt
               : undefined,
-        duration: session.duration === null ? undefined : session.duration,
+        duration: nullToUndefined(session.duration),
         exercises: session.exercises.map(({ exercise, order, sets }) => ({
           ...exercise,
           order,
-          sets: sets.map((set) => ({
-            ...set,
-            valueInt: set.valueInt === null ? undefined : set.valueInt,
-            valueSec: set.valueSec === null ? undefined : set.valueSec,
-            unit: set.unit === null ? undefined : set.unit,
-            units: set.units === null ? undefined : set.units,
-          })),
+          sets: sets.map((set) => {
+            return {
+              ...set,
+              units: nullToUndefined(set.units),
+            };
+          }),
         })),
       }));
       const localSessions = workoutSessionLocal.getAll().filter((s) => s.status !== "synced");