Sesje: start treningu tylko dla dni aktywnego planu (DRAFT/ABANDONED -> 400)
This commit is contained in:
@@ -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 } } } },
|
||||
|
||||
Reference in New Issue
Block a user