Sesje: start treningu tylko dla dni aktywnego planu (DRAFT/ABANDONED -> 400)

This commit is contained in:
tisachi
2026-10-11 16:17:35 +02:00
parent f505fa1910
commit 6cf71e4c15
3 changed files with 32 additions and 1 deletions

View File

@@ -45,6 +45,8 @@ export async function startSession(prisma: PrismaClient, dayId: string, userId:
});
if (!day || day.week.plan.userId !== userId) throw notFound('Day not found');
if (day.status !== 'PLANNED') throw badRequest('Day is not in planned state');
// dzień należy do planu — trening ma sens tylko w aktywnym planie (bez DRAFT/ABANDONED/COMPLETED)
if (day.week.plan.status !== 'ACTIVE') throw badRequest('Training plan is not active');
// Szybka ścieżka — rozstrzygające sprawdzenie jest w transakcji (pod blokadą).
const active = await prisma.trainingSession.findFirst({
where: { status: 'IN_PROGRESS', day: { week: { plan: { userId } } } },