Trening: ukonczenie sesji zablokowane przy niezapisanej serii bonusowej (serwer 400 + alert modal); niepelne ukonczenie pozostaje przez porzucenie
This commit is contained in:
@@ -196,12 +196,12 @@ export function createSessionRoutes({ prisma }: AppDeps) {
|
||||
* @openapi
|
||||
* /sessions/{id}/complete:
|
||||
* post:
|
||||
* summary: Complete session (requires all planned/norm sets recorded; extra sets are
|
||||
* a bonus and don't block; day -> completed)
|
||||
* summary: Complete session (requires all planned/norm sets recorded and no extra set
|
||||
* still in progress — recorded bonus sets don't block; day -> completed)
|
||||
* tags: [Sessions]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
* 400: { description: Session not in progress or planned sets still pending }
|
||||
* 400: { description: Session not in progress, planned sets still pending, or an extra set in progress }
|
||||
*/
|
||||
router.post(
|
||||
'/sessions/:id/complete',
|
||||
|
||||
@@ -341,7 +341,7 @@ export async function completeSession(prisma: PrismaClient, sessionId: string, u
|
||||
where: { sessionId: session.id, removed: false },
|
||||
include: { sets: true },
|
||||
});
|
||||
// Only planned (norm) sets must be recorded; extra sets are a bonus and don't block.
|
||||
// Tylko serie planowe (normowe) muszą być zapisane, żeby trening był ważny.
|
||||
const pending = exercises.reduce(
|
||||
(n, e) =>
|
||||
n + e.sets.filter((s) => !s.removed && s.planSetId != null && s.reps == null).length,
|
||||
@@ -351,6 +351,17 @@ export async function completeSession(prisma: PrismaClient, sessionId: string, u
|
||||
throw badRequest(
|
||||
`All planned sets must be recorded before completing the session (${pending} remaining)`,
|
||||
);
|
||||
// Seria bonusowa „w toku" nie może przeżyć sesji — koniec treningu wymaga jej
|
||||
// domknięcia (zapis lub usunięcie), inaczej kończenie sprzyja niechlujstwu.
|
||||
const pendingExtra = exercises.reduce(
|
||||
(n, e) =>
|
||||
n + e.sets.filter((s) => !s.removed && s.planSetId == null && s.reps == null).length,
|
||||
0,
|
||||
);
|
||||
if (pendingExtra > 0)
|
||||
throw badRequest(
|
||||
`Extra sets must be recorded or removed before completing the session (${pendingExtra} remaining)`,
|
||||
);
|
||||
const s = await tx.trainingSession.updateMany({
|
||||
where: { id: session.id, status: 'IN_PROGRESS' },
|
||||
data: { status: 'COMPLETED', endedAt: now },
|
||||
|
||||
Reference in New Issue
Block a user