Skip to content

Commit

Permalink
Merge pull request #115 from WhyAsh5114/114-cuid2
Browse files Browse the repository at this point in the history
feat: cuid2
  • Loading branch information
WhyAsh5114 authored Oct 14, 2024
2 parents ce3129f + 304abaa commit 3d516b3
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 402 deletions.
43 changes: 24 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"@iconify/json": "^2.2.227",
"@paralleldrive/cuid2": "^2.2.2",
"@playwright/test": "^1.45.1",
"@sveltejs/adapter-auto": "^3.2.2",
"@sveltejs/kit": "^2.5.18",
Expand All @@ -24,7 +25,6 @@
"@typescript-eslint/parser": "^8.0.0",
"@vite-pwa/sveltekit": "^0.6.0",
"autoprefixer": "^10.4.19",
"cuid": "^3.0.0",
"dotenv": "^16.4.5",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
6 changes: 3 additions & 3 deletions prisma/schema/exerciseSplit.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
model ExerciseSplit {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
Expand All @@ -8,7 +8,7 @@ model ExerciseSplit {
}

model ExerciseSplitDay {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
dayIndex Int
isRestDay Boolean
Expand All @@ -18,7 +18,7 @@ model ExerciseSplitDay {
}

model ExerciseTemplate {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
exerciseIndex Int
targetMuscleGroup MuscleGroup
Expand Down
72 changes: 36 additions & 36 deletions prisma/schema/mesocycle.prisma
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
model Mesocycle {
id String @id @default(cuid())
name String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
exerciseSplit ExerciseSplit? @relation(fields: [exerciseSplitId], references: [id])
exerciseSplitId String?
RIRProgression Int[]
startDate DateTime?
endDate DateTime?
startOverloadPercentage Float
lastSetToFailure Boolean
forceRIRMatching Boolean
mesocycleExerciseSplitDays MesocycleExerciseSplitDay[]
mesocycleCyclicSetChanges MesocycleCyclicSetChange[]
workoutsOfMesocycle WorkoutOfMesocycle[]
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
exerciseSplit ExerciseSplit? @relation(fields: [exerciseSplitId], references: [id])
exerciseSplitId String?
RIRProgression Int[]
startDate DateTime?
endDate DateTime?
startOverloadPercentage Float
lastSetToFailure Boolean
forceRIRMatching Boolean
mesocycleExerciseSplitDays MesocycleExerciseSplitDay[]
mesocycleCyclicSetChanges MesocycleCyclicSetChange[]
workoutsOfMesocycle WorkoutOfMesocycle[]
}

model MesocycleCyclicSetChange {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
mesocycle Mesocycle @relation(fields: [mesocycleId], references: [id], onDelete: Cascade)
mesocycleId String
muscleGroup MuscleGroup
Expand All @@ -28,7 +28,7 @@ model MesocycleCyclicSetChange {
}

model MesocycleExerciseSplitDay {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
dayIndex Int
isRestDay Boolean
Expand All @@ -38,23 +38,23 @@ model MesocycleExerciseSplitDay {
}

model MesocycleExerciseTemplate {
id String @id @default(cuid())
name String
exerciseIndex Int
targetMuscleGroup MuscleGroup
customMuscleGroup String?
bodyweightFraction Float?
sets Int
setType SetType
repRangeStart Int
repRangeEnd Int
changeType ChangeType?
changeAmount Float?
note String?
mesocycleExerciseSplitDay MesocycleExerciseSplitDay @relation(fields: [mesocycleExerciseSplitDayId], references: [id], onDelete: Cascade)
mesocycleExerciseSplitDayId String
overloadPercentage Float?
lastSetToFailure Boolean?
forceRIRMatching Boolean?
minimumWeightChange Float?
id String @id @default(cuid()) /// @zod.string.cuid2()
name String
exerciseIndex Int
targetMuscleGroup MuscleGroup
customMuscleGroup String?
bodyweightFraction Float?
sets Int
setType SetType
repRangeStart Int
repRangeEnd Int
changeType ChangeType?
changeAmount Float?
note String?
mesocycleExerciseSplitDay MesocycleExerciseSplitDay @relation(fields: [mesocycleExerciseSplitDayId], references: [id], onDelete: Cascade)
mesocycleExerciseSplitDayId String
overloadPercentage Float?
lastSetToFailure Boolean?
forceRIRMatching Boolean?
minimumWeightChange Float?
}
6 changes: 3 additions & 3 deletions prisma/schema/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ generator zod {
}

model User {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
name String?
email String @unique
emailVerified DateTime?
Expand All @@ -24,8 +24,8 @@ model User {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
exerciseSplits ExerciseSplit[]
mesocycles Mesocycle[]
workouts Workout[]
mesocycles Mesocycle[]
workouts Workout[]
}

model Account {
Expand Down
46 changes: 23 additions & 23 deletions prisma/schema/workout.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
model WorkoutOfMesocycle {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
workoutId String @unique
mesocycleId String
splitDayIndex Int
Expand All @@ -9,7 +9,7 @@ model WorkoutOfMesocycle {
}

model Workout {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
workoutOfMesocycle WorkoutOfMesocycle?
userBodyweight Int
Expand All @@ -20,29 +20,29 @@ model Workout {
}

model WorkoutExercise {
id String @id @default(cuid())
exerciseIndex Int
name String
workout Workout @relation(fields: [workoutId], references: [id], onDelete: Cascade)
workoutId String
targetMuscleGroup MuscleGroup
customMuscleGroup String?
bodyweightFraction Float?
sets WorkoutExerciseSet[]
setType SetType
changeType ChangeType?
changeAmount Float?
repRangeStart Int
repRangeEnd Int
note String?
overloadPercentage Float?
lastSetToFailure Boolean?
forceRIRMatching Boolean?
minimumWeightChange Float?
id String @id @default(cuid()) /// @zod.string.cuid2()
exerciseIndex Int
name String
workout Workout @relation(fields: [workoutId], references: [id], onDelete: Cascade)
workoutId String
targetMuscleGroup MuscleGroup
customMuscleGroup String?
bodyweightFraction Float?
sets WorkoutExerciseSet[]
setType SetType
changeType ChangeType?
changeAmount Float?
repRangeStart Int
repRangeEnd Int
note String?
overloadPercentage Float?
lastSetToFailure Boolean?
forceRIRMatching Boolean?
minimumWeightChange Float?
}

model WorkoutExerciseSet {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
setIndex Int
workoutExercise WorkoutExercise @relation(fields: [workoutExerciseId], references: [id], onDelete: Cascade)
workoutExerciseId String
Expand All @@ -54,7 +54,7 @@ model WorkoutExerciseSet {
}

model WorkoutExerciseMiniSet {
id String @id @default(cuid())
id String @id @default(cuid()) /// @zod.string.cuid2()
miniSetIndex Int
reps Int
load Float
Expand Down
16 changes: 8 additions & 8 deletions src/lib/trpc/routes/exerciseSplits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ExerciseTemplateCreateWithoutExerciseSplitDayInputSchema
} from '$lib/zodSchemas';
import type { ExerciseSplit, ExerciseSplitDay, Prisma } from '@prisma/client';
import cuid from 'cuid';
import { createId } from '@paralleldrive/cuid2';

const zodExerciseSplitInput = z.strictObject({
splitName: z.string(),
Expand All @@ -19,20 +19,20 @@ const createOrEditExerciseSplit = async (
userId: string,
editingId?: string
) => {
const exerciseSplitId = editingId ?? cuid();
const exerciseSplitId = editingId ?? createId();
const exerciseSplit: ExerciseSplit = { id: exerciseSplitId, name: input.splitName, userId };

const exerciseSplitDays: ExerciseSplitDay[] = input.splitDays.map((splitDay) => ({
...splitDay,
id: cuid(),
id: createId(),
exerciseSplitId: exerciseSplit.id
}));

const exerciseTemplates: Prisma.ExerciseTemplateUncheckedCreateInput[] = input.splitExercises.flatMap(
(dayExercises, dayNumber) =>
dayExercises.map((exercise) => ({
...exercise,
id: cuid(),
id: createId(),
exerciseSplitDayId: exerciseSplitDays[dayNumber].id
}))
);
Expand All @@ -49,7 +49,7 @@ const createOrEditExerciseSplit = async (
};

export const exerciseSplits = t.router({
findById: t.procedure.input(z.string().cuid()).query(({ input, ctx }) =>
findById: t.procedure.input(z.string().cuid2()).query(({ input, ctx }) =>
prisma.exerciseSplit.findUnique({
where: { id: input, userId: ctx.userId },
include: {
Expand All @@ -64,7 +64,7 @@ export const exerciseSplits = t.router({
load: t.procedure
.input(
z.strictObject({
cursorId: z.string().cuid().optional(),
cursorId: z.string().cuid2().optional(),
searchString: z.string().optional()
})
)
Expand Down Expand Up @@ -92,13 +92,13 @@ export const exerciseSplits = t.router({
}),

editById: t.procedure
.input(z.strictObject({ id: z.string().cuid(), splitData: zodExerciseSplitInput }))
.input(z.strictObject({ id: z.string().cuid2(), splitData: zodExerciseSplitInput }))
.mutation(async ({ input, ctx }) => {
await createOrEditExerciseSplit(input.splitData, ctx.userId, input.id);
return { message: 'Exercise split edited successfully' };
}),

deleteById: t.procedure.input(z.string().cuid()).mutation(async ({ input, ctx }) => {
deleteById: t.procedure.input(z.string().cuid2()).mutation(async ({ input, ctx }) => {
await prisma.exerciseSplit.delete({ where: { userId: ctx.userId, id: input } });
return { message: 'Exercise split deleted successfully' };
})
Expand Down
Loading

0 comments on commit 3d516b3

Please sign in to comment.