Trening: dodanie cwiczenia tworzy automatycznie pierwsza serie; limit niezapisanego bonusu liczony na cwiczenie (wczesniej na sesje)

This commit is contained in:
Tilumca
2026-10-14 22:11:49 +02:00
parent 1bed564bfc
commit 7d89f5bcca
8 changed files with 95 additions and 24 deletions

View File

@@ -241,8 +241,8 @@ export async function updateExercise(
/**
* Add an extra (bonus) set to a session exercise.
* Allowed once every planned (norm) set of THIS exercise is recorded (exercises
* added to the session have no norm — vacuously satisfied), and no extra set is
* still pending — at most one pending extra set per session.
* added to the session have no norm — vacuously satisfied), and this exercise has
* no extra set still pending — at most one pending extra set per exercise.
* Norm of other exercises must not block exceeding one that is already done:
* "nie dowożę / dowożę / przekraczam" is an option per exercise, in order.
*/
@@ -259,13 +259,7 @@ export async function addSet(prisma: PrismaClient, exerciseId: string, userId: s
'All planned sets of this exercise must be recorded before adding an extra set',
);
const pendingExtra = await tx.sessionSet.count({
where: {
// usunięte ćwiczenia nie liczą się do limitu — ich seria „w toku" jest nietykalna
exercise: { sessionId: exercise.sessionId, removed: false },
planSetId: null,
reps: null,
removed: false,
},
where: { exerciseId: exercise.id, planSetId: null, reps: null, removed: false },
});
if (pendingExtra > 0) throw badRequest('An extra set is already in progress');
const maxIndex = await tx.sessionSet.aggregate({