Plany: PATCH z startDate (aktywacja przy zapisie) i udostepnianie planow trener-podopieczny (PlanShare, sekcja Udostepnione mi, widok read-only)

This commit is contained in:
tisachi
2026-09-13 02:28:29 +02:00
parent 8049c4bc47
commit 1f29ce7003
19 changed files with 1791 additions and 76 deletions

View File

@@ -0,0 +1,25 @@
-- CreateTable
CREATE TABLE "PlanShare" (
"id" TEXT NOT NULL,
"planId" TEXT NOT NULL,
"sharedById" TEXT NOT NULL,
"sharedWithId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "PlanShare_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "PlanShare_sharedWithId_idx" ON "PlanShare"("sharedWithId");
-- CreateIndex
CREATE UNIQUE INDEX "PlanShare_planId_sharedWithId_key" ON "PlanShare"("planId", "sharedWithId");
-- AddForeignKey
ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_planId_fkey" FOREIGN KEY ("planId") REFERENCES "TrainingPlan"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_sharedById_fkey" FOREIGN KEY ("sharedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PlanShare" ADD CONSTRAINT "PlanShare_sharedWithId_fkey" FOREIGN KEY ("sharedWithId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -110,6 +110,8 @@ model User {
memberships GymMembership[]
plans TrainingPlan[]
createdPlans TrainingPlan[] @relation("PlanCreator")
planSharesBy PlanShare[] @relation("PlanShareBy")
planSharesWith PlanShare[] @relation("PlanShareWith")
weightEntries BodyMeasurement[]
circumferenceEntries CircumferenceMeasurement[]
coachingsAsTrainer Coaching[] @relation("CoachingTrainer")
@@ -484,15 +486,33 @@ model TrainingPlan {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
creator User? @relation("PlanCreator", fields: [creatorId], references: [id], onDelete: SetNull)
gym Gym? @relation(fields: [gymId], references: [id], onDelete: SetNull)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
creator User? @relation("PlanCreator", fields: [creatorId], references: [id], onDelete: SetNull)
gym Gym? @relation(fields: [gymId], references: [id], onDelete: SetNull)
weeks PlanWeek[]
shares PlanShare[]
@@index([userId, status])
@@index([gymId])
}
/// Explicit plan sharing (trainer <-> trainee): the owner shares a plan with a user
/// in an ACTIVE coaching relation. Recipients get read-only access.
model PlanShare {
id String @id @default(cuid())
planId String
sharedById String
sharedWithId String
createdAt DateTime @default(now())
plan TrainingPlan @relation(fields: [planId], references: [id], onDelete: Cascade)
sharedBy User @relation("PlanShareBy", fields: [sharedById], references: [id], onDelete: Cascade)
sharedWith User @relation("PlanShareWith", fields: [sharedWithId], references: [id], onDelete: Cascade)
@@unique([planId, sharedWithId])
@@index([sharedWithId])
}
model PlanWeek {
id String @id @default(cuid())
planId String