Plans: wznawianie planu tylko dla wlasciciela (usuniete akcje trenera)

This commit is contained in:
tisachi
2026-10-22 23:53:49 +02:00
parent 50df81dbf0
commit 83ee38dc3a
13 changed files with 54 additions and 175 deletions

View File

@@ -429,12 +429,13 @@ export async function completePlan(prisma: PrismaClient, planId: string, userId:
* pomyłek (np. błędnie oznaczony plan) — dni SKIPPED nie są wskrzeszane, a plan
* bez dni zaplanowanych zostanie ponownie ukończony przez scheduler, gdy tylko
* wszystkie dni pozostaną domknięte.
* Wznowić może wyłącznie właściciel planu (trener nie ma takiej akcji).
*/
export async function reopenPlan(prisma: PrismaClient, planId: string, userId: string) {
const plan = await assertPlanAccess(prisma, planId, userId);
const plan = await assertPlanOwner(prisma, planId, userId);
if (plan.status !== 'COMPLETED' && plan.status !== 'ABANDONED')
throw badRequest('Only a completed or abandoned plan can be reopened');
// Jeden aktywny plan dotyczy właściciela (inicjatorem może być trener).
// Jeden aktywny plan dotyczy właściciela.
// Pre-check + częściowy indeks unikalny (TrainingPlan_userId_active_key)
// rozstrzyga równoległe wznowienia/aktywacje.
const otherActive = await prisma.trainingPlan.findFirst({