From 2fb288e029996525c441eddfeeb0d52aee2eabdc Mon Sep 17 00:00:00 2001 From: tisachi Date: Sun, 11 Oct 2026 15:52:33 +0200 Subject: [PATCH] Api+app: usuniecie PlanSet.difficulty z kontraktu planu (trudnosc pozostaje wynikiem rzeczywistym serii) --- .../migration.sql | 2 + api/prisma/schema.prisma | 1 - api/scripts/smoke-test.mjs | 4 +- api/src/routes/plans-schemas.ts | 1 - api/src/services/plans.ts | 1 - api/src/swagger.ts | 1 - api/test/integration/plans.test.ts | 196 +++++++++++++----- app/src/api/queries.ts | 1 - app/src/api/types.ts | 1 - app/src/components/ui/dialogs.tsx | 3 +- app/src/pages/DayExecution.tsx | 100 ++++++--- app/src/pages/plans/PlanEditor.tsx | 1 - app/src/pages/plans/plan-editor/types.ts | 4 - app/test/DayExecution.test.tsx | 4 +- app/test/PlanDetail.test.tsx | 1 - app/test/e2e/mock-api.ts | 4 +- app/test/plan-editor-state.test.ts | 2 +- app/test/trainee-plans.test.tsx | 2 - 18 files changed, 230 insertions(+), 99 deletions(-) create mode 100644 api/prisma/migrations/20261011010000_remove_plan_set_difficulty/migration.sql diff --git a/api/prisma/migrations/20261011010000_remove_plan_set_difficulty/migration.sql b/api/prisma/migrations/20261011010000_remove_plan_set_difficulty/migration.sql new file mode 100644 index 0000000..0ae4915 --- /dev/null +++ b/api/prisma/migrations/20261011010000_remove_plan_set_difficulty/migration.sql @@ -0,0 +1,2 @@ +-- Usuniecie PlanSet.difficulty (trudnosc jest wynikiem rzeczywistym, nie planowanym) +ALTER TABLE "PlanSet" DROP COLUMN "difficulty"; diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma index 0a8bad8..a214b29 100644 --- a/api/prisma/schema.prisma +++ b/api/prisma/schema.prisma @@ -576,7 +576,6 @@ model PlanSet { loadKg Float? restSec Int? rir Int? - difficulty Int? cardioBpm Int? timeSec Int? speed Float? diff --git a/api/scripts/smoke-test.mjs b/api/scripts/smoke-test.mjs index 803a713..051c2e8 100644 --- a/api/scripts/smoke-test.mjs +++ b/api/scripts/smoke-test.mjs @@ -66,8 +66,8 @@ async function main() { { dayOfWeek: 1, exercises: [ - { puzzleId: bench.id, order: 0, sets: [{ index: 0, reps: 10, loadKg: 60 + index * 2.5, restSec: 90, rir: 2, difficulty: 3 }] }, - { puzzleId: squat.id, order: 1, sets: [{ index: 0, reps: 8, loadKg: 80 + index * 2.5, restSec: 120, rir: 1, difficulty: 4 }] }, + { puzzleId: bench.id, order: 0, sets: [{ index: 0, reps: 10, loadKg: 60 + index * 2.5, restSec: 90, rir: 2 }] }, + { puzzleId: squat.id, order: 1, sets: [{ index: 0, reps: 8, loadKg: 80 + index * 2.5, restSec: 120, rir: 1 }] }, ], }, ], diff --git a/api/src/routes/plans-schemas.ts b/api/src/routes/plans-schemas.ts index 8cdd93c..d87b06b 100644 --- a/api/src/routes/plans-schemas.ts +++ b/api/src/routes/plans-schemas.ts @@ -6,7 +6,6 @@ export const planSetSchema = z.object({ loadKg: z.number().positive().max(1000).nullable().optional(), restSec: z.number().int().positive().max(3600).nullable().optional(), rir: z.number().int().min(0).max(10).nullable().optional(), - difficulty: z.number().int().min(1).max(5).nullable().optional(), cardioBpm: z.number().int().positive().max(300).nullable().optional(), timeSec: z.number().int().positive().max(86400).nullable().optional(), speed: z.number().positive().max(100).nullable().optional(), diff --git a/api/src/services/plans.ts b/api/src/services/plans.ts index c5edb6c..3036a6a 100644 --- a/api/src/services/plans.ts +++ b/api/src/services/plans.ts @@ -8,7 +8,6 @@ export interface PlanSetInput { loadKg?: number | null; restSec?: number | null; rir?: number | null; - difficulty?: number | null; cardioBpm?: number | null; timeSec?: number | null; speed?: number | null; diff --git a/api/src/swagger.ts b/api/src/swagger.ts index 6a77faa..a22e456 100644 --- a/api/src/swagger.ts +++ b/api/src/swagger.ts @@ -522,7 +522,6 @@ export const openapi: Record = { loadKg: { type: 'number', nullable: true }, restSec: { type: 'integer', nullable: true }, rir: { type: 'integer', nullable: true }, - difficulty: { type: 'integer', nullable: true }, cardioBpm: { type: 'integer', nullable: true }, timeSec: { type: 'integer', nullable: true }, speed: { type: 'number', nullable: true }, diff --git a/api/test/integration/plans.test.ts b/api/test/integration/plans.test.ts index e52a759..c33548e 100644 --- a/api/test/integration/plans.test.ts +++ b/api/test/integration/plans.test.ts @@ -46,7 +46,7 @@ describe('plans routes', () => { exerciseId, order: 0, sets: [ - { index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, difficulty: 3 }, + { index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2 }, { index: 1, reps: 8, loadKg: 62.5, restSec: 90 }, ], }, @@ -65,14 +65,20 @@ describe('plans routes', () => { const exercise = await createExercise(); exerciseId = exercise.id; const app = buildApp(); - const res = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Mój plan')); + const res = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Mój plan')); expect(res.status).toBe(201); planId = res.body.plan.id; }); it('creates a draft plan with the given structure', async () => { const app = buildApp(); - const res = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Draft 2')); + const res = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Draft 2')); expect(res.status).toBe(201); expect(res.body.plan).toMatchObject({ title: 'Draft 2', status: 'DRAFT', weeksCount: 2 }); expect(res.body.plan.startDate).toBeNull(); @@ -154,7 +160,9 @@ describe('plans routes', () => { it('returns 404 for another user plan', async () => { const app = buildApp(); - const res = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${otherToken}`); + const res = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${otherToken}`); expect(res.status).toBe(404); }); @@ -162,7 +170,10 @@ describe('plans routes', () => { const app = buildApp(); const body = planBody('Zmieniony'); body.weeks[0].days[0].exercises[0].sets = [{ index: 0, reps: 5 }]; - const res = await app.patch(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${token}`).send(body); + const res = await app + .patch(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${token}`) + .send(body); expect(res.status).toBe(200); const detail = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${token}`); @@ -201,7 +212,10 @@ describe('plans routes', () => { it('rejects activation with a past-week startDate with 400', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Past activate')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Past activate')); const res = await app .post(`/api/v1/plans/${created.body.plan.id}/activate`) .set('Authorization', `Bearer ${token}`) @@ -212,7 +226,10 @@ describe('plans routes', () => { it('rejects activation on a non-Monday date with 400', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Sunday plan')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Sunday plan')); const res = await app .post(`/api/v1/plans/${created.body.plan.id}/activate`) .set('Authorization', `Bearer ${token}`) @@ -223,7 +240,10 @@ describe('plans routes', () => { it('rejects an invalid start date with 400', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Bad date')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Bad date')); const res = await app .post(`/api/v1/plans/${created.body.plan.id}/activate`) .set('Authorization', `Bearer ${token}`) @@ -233,7 +253,10 @@ describe('plans routes', () => { it('rejects activating a second plan while one is active with 409', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('Second active')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('Second active')); const res = await app .post(`/api/v1/plans/${created.body.plan.id}/activate`) .set('Authorization', `Bearer ${token}`) @@ -244,7 +267,10 @@ describe('plans routes', () => { it('rejects editing an active plan with 400', async () => { const app = buildApp(); - const res = await app.patch(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${token}`).send(planBody('Edit active')); + const res = await app + .patch(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${token}`) + .send(planBody('Edit active')); expect(res.status).toBe(400); expect(res.body.error.message).toBe('Only draft plans can be edited'); }); @@ -258,32 +284,50 @@ describe('plans routes', () => { it('abandons an active plan and refuses to close it twice', async () => { const app = buildApp(); - const res = await app.post(`/api/v1/plans/${planId}/abandon`).set('Authorization', `Bearer ${token}`); + const res = await app + .post(`/api/v1/plans/${planId}/abandon`) + .set('Authorization', `Bearer ${token}`); expect(res.status).toBe(200); - const again = await app.post(`/api/v1/plans/${planId}/abandon`).set('Authorization', `Bearer ${token}`); + const again = await app + .post(`/api/v1/plans/${planId}/abandon`) + .set('Authorization', `Bearer ${token}`); expect(again.status).toBe(400); expect(again.body.error.message).toBe('Plan is already closed'); }); it('completes a draft plan and refuses to close it twice', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('To complete')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('To complete')); const id = created.body.plan.id; - const res = await app.post(`/api/v1/plans/${id}/complete`).set('Authorization', `Bearer ${token}`); + const res = await app + .post(`/api/v1/plans/${id}/complete`) + .set('Authorization', `Bearer ${token}`); expect(res.status).toBe(200); - const again = await app.post(`/api/v1/plans/${id}/complete`).set('Authorization', `Bearer ${token}`); + const again = await app + .post(`/api/v1/plans/${id}/complete`) + .set('Authorization', `Bearer ${token}`); expect(again.status).toBe(400); }); it('deletes a draft plan', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(planBody('To delete')); - const res = await app.delete(`/api/v1/plans/${created.body.plan.id}`).set('Authorization', `Bearer ${token}`); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(planBody('To delete')); + const res = await app + .delete(`/api/v1/plans/${created.body.plan.id}`) + .set('Authorization', `Bearer ${token}`); expect(res.status).toBe(204); - const detail = await app.get(`/api/v1/plans/${created.body.plan.id}`).set('Authorization', `Bearer ${token}`); + const detail = await app + .get(`/api/v1/plans/${created.body.plan.id}`) + .set('Authorization', `Bearer ${token}`); expect(detail.status).toBe(404); }); @@ -320,7 +364,9 @@ describe('plans routes', () => { expect(res.body.plan).toMatchObject({ title: 'One-step plan', status: 'ACTIVE' }); expect(res.body.plan.startDate).not.toBeNull(); - const detail = await app.get(`/api/v1/plans/${res.body.plan.id}`).set('Authorization', `Bearer ${token}`); + const detail = await app + .get(`/api/v1/plans/${res.body.plan.id}`) + .set('Authorization', `Bearer ${token}`); expect(detail.body.plan.status).toBe('ACTIVE'); const localDate = (iso: string) => { const d = new Date(iso); @@ -397,7 +443,9 @@ describe('plans routes', () => { expect(conflicted).toHaveLength(1); const after = await app.get('/api/v1/plans').set('Authorization', `Bearer ${token}`); - const activeCount = after.body.plans.filter((p: { status: string }) => p.status === 'ACTIVE').length; + const activeCount = after.body.plans.filter( + (p: { status: string }) => p.status === 'ACTIVE', + ).length; expect(activeCount).toBe(1); }); }); @@ -415,7 +463,9 @@ describe('plans: gym and week alias', () => { { index: 0, customName: 'Deload', - days: [{ dayOfWeek: 1, exercises: [{ exerciseId, order: 0, sets: [{ index: 0, reps: 10 }] }] }], + days: [ + { dayOfWeek: 1, exercises: [{ exerciseId, order: 0, sets: [{ index: 0, reps: 10 }] }] }, + ], }, ], }); @@ -428,7 +478,9 @@ describe('plans: gym and week alias', () => { gymId = gym.id; const other = await prisma.gym.create({ data: { name: `Other Gym ${rand()}` } }); otherGymId = other.id; - await prisma.gymMembership.create({ data: { userId: reg.user.id, gymId, roles: ['MEMBER'] as never } }); + await prisma.gymMembership.create({ + data: { userId: reg.user.id, gymId, roles: ['MEMBER'] as never }, + }); }); it('creates a plan with gymId and per-week customName', async () => { @@ -441,7 +493,9 @@ describe('plans: gym and week alias', () => { expect(res.body.plan.gym).toMatchObject({ id: gymId }); expect(res.body.plan.gym.name).toBeTruthy(); - const detail = await app.get(`/api/v1/plans/${res.body.plan.id}`).set('Authorization', `Bearer ${token}`); + const detail = await app + .get(`/api/v1/plans/${res.body.plan.id}`) + .set('Authorization', `Bearer ${token}`); expect(detail.body.plan.gym).toMatchObject({ id: gymId }); expect(detail.body.plan.weeks[0].customName).toBe('Deload'); }); @@ -483,7 +537,10 @@ describe('plans: gym and week alias', () => { it('updates gymId and customName via PATCH', async () => { const app = buildApp(); - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(body('Do zmiany')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(body('Do zmiany')); const id = created.body.plan.id; const res = await app .patch(`/api/v1/plans/${id}`) @@ -536,8 +593,8 @@ describe('plans: direct seeding sanity', () => { expect(day.exercises).toHaveLength(1); expect(day.exercises[0].sets).toHaveLength(1); expect(day.exercises[0].sets[0].reps).toBe(10); - expect(day.exercises[0].exercise.id).toBe(exercise.id); - await prisma.trainingPlan.delete({ where: { id: plan.id } }); + expect(day.exercises[0].exercise.id).toBe(exercise.id); + await prisma.trainingPlan.delete({ where: { id: plan.id } }); }); }); @@ -558,7 +615,10 @@ describe('plans: trainer-created plan (creator + owner access)', () => { { index: 0, days: [ - { dayOfWeek: 1, exercises: [{ exerciseId, order: 0, sets: [{ index: 0, reps: 10, loadKg: 60 }] }] }, + { + dayOfWeek: 1, + exercises: [{ exerciseId, order: 0, sets: [{ index: 0, reps: 10, loadKg: 60 }] }], + }, ], }, ], @@ -572,9 +632,15 @@ describe('plans: trainer-created plan (creator + owner access)', () => { trainerId = t.user.id; traineeId = tr.user.id; const gym = await prisma.gym.create({ data: { name: `Vis Gym ${rand()}` } }); - await prisma.gymMembership.create({ data: { userId: trainerId, gymId: gym.id, roles: ['TRAINER'] as never } }); - await prisma.gymMembership.create({ data: { userId: traineeId, gymId: gym.id, roles: ['MEMBER'] as never } }); - await prisma.gymMembership.create({ data: { userId: p.user.id, gymId: gym.id, roles: ['MEMBER'] as never } }); + await prisma.gymMembership.create({ + data: { userId: trainerId, gymId: gym.id, roles: ['TRAINER'] as never }, + }); + await prisma.gymMembership.create({ + data: { userId: traineeId, gymId: gym.id, roles: ['MEMBER'] as never }, + }); + await prisma.gymMembership.create({ + data: { userId: p.user.id, gymId: gym.id, roles: ['MEMBER'] as never }, + }); trainerToken = (await loginViaApi(t.user.email, PASSWORD)).token; traineeToken = (await loginViaApi(tr.user.email, PASSWORD)).token; plainToken = (await loginViaApi(p.user.email, PASSWORD)).token; @@ -615,13 +681,17 @@ describe('plans: trainer-created plan (creator + owner access)', () => { }); it('a third user gets 404 for the plan', async () => { - const res = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${plainToken}`); + const res = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${plainToken}`); expect(res.status).toBe(404); }); it('trainer can attach a gym the trainee is a member of', async () => { const gym = await prisma.gym.create({ data: { name: `Trainee Gym ${rand()}` } }); - await prisma.gymMembership.create({ data: { userId: traineeId, gymId: gym.id, roles: ['MEMBER'] as never } }); + await prisma.gymMembership.create({ + data: { userId: traineeId, gymId: gym.id, roles: ['MEMBER'] as never }, + }); const res = await app .post(`/api/v1/trainer/trainees/${traineeId}/plans`) .set('Authorization', `Bearer ${trainerToken}`) @@ -632,7 +702,9 @@ describe('plans: trainer-created plan (creator + owner access)', () => { it('trainer cannot attach a gym the trainee is NOT a member of (400)', async () => { const gym = await prisma.gym.create({ data: { name: `Trainer-only Gym ${rand()}` } }); - await prisma.gymMembership.create({ data: { userId: trainerId, gymId: gym.id, roles: ['TRAINER'] as never } }); + await prisma.gymMembership.create({ + data: { userId: trainerId, gymId: gym.id, roles: ['TRAINER'] as never }, + }); const res = await app .post(`/api/v1/trainer/trainees/${traineeId}/plans`) .set('Authorization', `Bearer ${trainerToken}`) @@ -681,7 +753,10 @@ describe('plans: sharing (PlanShare)', () => { const ex = await createExercise(); exerciseId = ex.id; // plan należy do podopiecznego (właściciel = podopieczny) - const res = await app.post('/api/v1/plans').set('Authorization', `Bearer ${trainee.token}`).send(body('Plan do udostępnienia')); + const res = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${trainee.token}`) + .send(body('Plan do udostępnienia')); expect(res.status).toBe(201); planId = res.body.plan.id; }); @@ -732,16 +807,23 @@ describe('plans: sharing (PlanShare)', () => { }); it('the owner sees the recipients in the plan detail', async () => { - const res = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${trainee.token}`); + const res = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${trainee.token}`); expect(res.status).toBe(200); expect(res.body.plan.shares).toEqual([ - { userId: trainer.user.id, user: { id: trainer.user.id, firstName: 'ShareTrainer', lastName: null } }, + { + userId: trainer.user.id, + user: { id: trainer.user.id, firstName: 'ShareTrainer', lastName: null }, + }, ]); expect(res.body.plan.canManage).toBe(true); }); it('the recipient sees the plan in /plans/shared-with-me', async () => { - const res = await app.get('/api/v1/plans/shared-with-me').set('Authorization', `Bearer ${trainer.token}`); + const res = await app + .get('/api/v1/plans/shared-with-me') + .set('Authorization', `Bearer ${trainer.token}`); expect(res.status).toBe(200); const found = res.body.plans.find((p: { id: string }) => p.id === planId); expect(found).toBeTruthy(); @@ -750,7 +832,9 @@ describe('plans: sharing (PlanShare)', () => { }); it('the trainee sees the trainer in /me/trainers', async () => { - const res = await app.get('/api/v1/me/trainers').set('Authorization', `Bearer ${trainee.token}`); + const res = await app + .get('/api/v1/me/trainers') + .set('Authorization', `Bearer ${trainee.token}`); expect(res.status).toBe(200); expect(res.body.trainers).toEqual([ { id: trainer.user.id, firstName: 'ShareTrainer', lastName: null, nickname: null }, @@ -770,14 +854,18 @@ describe('plans: sharing (PlanShare)', () => { where: { trainerId: trainer.user.id, userId: trainee.user.id }, data: { status: 'ARCHIVED' }, }); - const res = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${trainer.token}`); + const res = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${trainer.token}`); expect(res.status).toBe(200); expect(res.body.plan.canManage).toBe(false); expect(res.body.plan.shares).toBeUndefined(); }); it('a stranger gets 404 for the shared plan', async () => { - const res = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${stranger.token}`); + const res = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${stranger.token}`); expect(res.status).toBe(404); }); @@ -787,10 +875,14 @@ describe('plans: sharing (PlanShare)', () => { .set('Authorization', `Bearer ${trainee.token}`); expect(res.status).toBe(204); - const detail = await app.get(`/api/v1/plans/${planId}`).set('Authorization', `Bearer ${trainer.token}`); + const detail = await app + .get(`/api/v1/plans/${planId}`) + .set('Authorization', `Bearer ${trainer.token}`); expect(detail.status).toBe(404); - const list = await app.get('/api/v1/plans/shared-with-me').set('Authorization', `Bearer ${trainer.token}`); + const list = await app + .get('/api/v1/plans/shared-with-me') + .set('Authorization', `Bearer ${trainer.token}`); expect(list.body.plans.find((p: { id: string }) => p.id === planId)).toBeUndefined(); }); @@ -829,7 +921,10 @@ describe('plans: PATCH with startDate (update + activate)', () => { userId = reg.user.id; const ex = await createExercise(); exerciseId = ex.id; - const res = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(body('Draft do aktywacji')); + const res = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(body('Draft do aktywacji')); expect(res.status).toBe(201); planId = res.body.plan.id; }); @@ -882,14 +977,17 @@ describe('plans: PATCH with startDate (update + activate)', () => { return [d.getFullYear(), d.getMonth() + 1, d.getDate()]; }; const [sy, sm, sd] = mondayIso(1).split('-').map(Number); - const day1 = detail.body.plan.weeks.find((w: { index: number }) => w.index === 0).days.find( - (d: { dayOfWeek: number }) => d.dayOfWeek === 1, - ); + const day1 = detail.body.plan.weeks + .find((w: { index: number }) => w.index === 0) + .days.find((d: { dayOfWeek: number }) => d.dayOfWeek === 1); expect(localDate(day1.date)).toEqual([sy, sm, sd]); }); it('PATCH with startDate while another plan is active saves the structure as a DRAFT (activationSkipped)', async () => { - const created = await app.post('/api/v1/plans').set('Authorization', `Bearer ${token}`).send(body('Konflikt')); + const created = await app + .post('/api/v1/plans') + .set('Authorization', `Bearer ${token}`) + .send(body('Konflikt')); const res = await app .patch(`/api/v1/plans/${created.body.plan.id}`) .set('Authorization', `Bearer ${token}`) @@ -897,7 +995,9 @@ describe('plans: PATCH with startDate (update + activate)', () => { expect(res.status).toBe(200); expect(res.body).toMatchObject({ ok: true, activationSkipped: true }); - const detail = await app.get(`/api/v1/plans/${created.body.plan.id}`).set('Authorization', `Bearer ${token}`); + const detail = await app + .get(`/api/v1/plans/${created.body.plan.id}`) + .set('Authorization', `Bearer ${token}`); expect(detail.body.plan).toMatchObject({ status: 'DRAFT' }); expect(detail.body.plan.startDate).toBeNull(); }); diff --git a/app/src/api/queries.ts b/app/src/api/queries.ts index 5af19cc..ae273ae 100644 --- a/app/src/api/queries.ts +++ b/app/src/api/queries.ts @@ -409,7 +409,6 @@ export interface PlanSetInput { loadKg?: number | null; restSec?: number | null; rir?: number | null; - difficulty?: number | null; cardioBpm?: number | null; timeSec?: number | null; speed?: number | null; diff --git a/app/src/api/types.ts b/app/src/api/types.ts index 49e34a8..05eeb6c 100644 --- a/app/src/api/types.ts +++ b/app/src/api/types.ts @@ -240,7 +240,6 @@ export interface PlanSet { loadKg: number | null; restSec: number | null; rir: number | null; - difficulty: number | null; cardioBpm: number | null; timeSec: number | null; speed: number | null; diff --git a/app/src/components/ui/dialogs.tsx b/app/src/components/ui/dialogs.tsx index b61ee98..ce572ee 100644 --- a/app/src/components/ui/dialogs.tsx +++ b/app/src/components/ui/dialogs.tsx @@ -233,7 +233,7 @@ const SET_FIELD_META: { key: 'reps' | 'rir' | 'difficulty'; label: string; hint: export type SetFieldValues = { reps: string; rir: string; difficulty: string; note: string }; -export type PlannedValues = { reps: number | null; rir: number | null; difficulty: number | null }; +export type PlannedValues = { reps: number | null; rir: number | null }; /* Trwająca przerwa pokazana w oknie serii (timer + informacja, że zapis zrestartuje odliczanie). */ export type SetEditRestInfo = { remaining: number; total: number; resetsOnSave: boolean }; @@ -280,7 +280,6 @@ export function SetEditDialog({ ...d, reps: planned.reps?.toString() ?? '', rir: planned.rir?.toString() ?? '', - difficulty: planned.difficulty?.toString() ?? '', })); }; diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index c7343bd..a127b01 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -63,7 +63,9 @@ function SessionStatusCard({
{/* kolorowe badge'y zgrupowane po lewej; data nie rozdziela ich */}
- {SESSION_STATUS[session.status].label} + + {SESSION_STATUS[session.status].label} + {extraDone > 0 && +{extraDone} bonus}
start: {fmtDate(session.startedAt)} @@ -90,7 +92,10 @@ function SessionStatusCard({ / {Math.floor(rest.totalSec / 60)}:{String(rest.totalSec % 60).padStart(2, '0')} - + @@ -102,7 +107,9 @@ function SessionStatusCard({ /* Mała jednostka przy dużej liczbie (np. 70 + „kg” w 0.55em, dim). */ function Unit({ children }: { children: ReactNode }) { - return {children}; + return ( + {children} + ); } /* Wiersz serii: lewo (Seria N, Następna/bonus, cel z planu) | prawo (wynik, Edytuj/Uzupełnij, Usuń serię). */ @@ -177,7 +184,9 @@ function SetRow({ {planned.reps != null ? `${planned.reps} powt.` : ''} ) : null, - planned?.restSec != null ? przerwa {planned.restSec} s : null, + planned?.restSec != null ? ( + przerwa {planned.restSec} s + ) : null, planned?.rir != null ? RIR {planned.rir} : null, ] .filter(Boolean) @@ -247,7 +256,8 @@ function ExerciseAccordion({ }) { const isNextEx = exercise.sets.some((s) => s.id === nextSetId); const doneCount = exercise.sets.filter((s) => s.reps != null).length; - const setPercent = exercise.sets.length > 0 ? Math.round((doneCount / exercise.sets.length) * 100) : 0; + const setPercent = + exercise.sets.length > 0 ? Math.round((doneCount / exercise.sets.length) * 100) : 0; return ( {/* nagłówek = akordeon: klik rozwija/zwija; aktywne ćwiczenie (z następną serią) rozwija się samo */} @@ -260,7 +270,9 @@ function ExerciseAccordion({ >

{exercise.exercise.name}

- Ćwiczenie {order} / {total} + + Ćwiczenie {order} / {total} + {exercise.planExercise === null && dodane do sesji} {isNextEx && !expanded && Następna}
@@ -269,7 +281,11 @@ function ExerciseAccordion({ {MUSCLE_NAMES[exercise.exercise.primaryMuscle] || exercise.exercise.primaryMuscle} {!expanded && ( - 0 ? 'green' : 'gray'}> + 0 ? 'green' : 'gray' + } + > {doneCount}/{exercise.sets.length} )} @@ -282,7 +298,9 @@ function ExerciseAccordion({ Usuń )} - +
@@ -312,7 +330,13 @@ function ExerciseAccordion({ ))} {inProgress && ( - @@ -349,7 +373,9 @@ function AddExerciseModal({ className="flex items-center justify-between gap-3 w-full px-3 py-2.5 rounded-[10px] text-left hover:bg-line/22 cursor-pointer transition-colors" > {p.name} - {MUSCLE_NAMES[p.primaryMuscle] || p.primaryMuscle} + + {MUSCLE_NAMES[p.primaryMuscle] || p.primaryMuscle} + ))} @@ -376,7 +402,7 @@ export default function DayExecution() { const [editSet, setEditSet] = useState<{ setId: string; index: number; - planned: { reps: number | null; rir: number | null; difficulty: number | null }; + planned: { reps: number | null; rir: number | null }; restSec: number | null; } | null>(null); @@ -421,7 +447,8 @@ export default function DayExecution() { // Akordeon: rozwinięte jest ćwiczenie zawierające następną serię (aktywne); // kliknięcie nagłówka przełącza rozwinięcie (jedno ćwiczenie naraz). const nextExerciseId = session - ? session.exercises.find((ex) => !ex.removed && ex.sets.some((s) => s.id === nextSetId))?.id ?? null + ? (session.exercises.find((ex) => !ex.removed && ex.sets.some((s) => s.id === nextSetId))?.id ?? + null) : null; const [expandedExId, setExpandedExId] = useState(null); @@ -445,7 +472,11 @@ export default function DayExecution() { setRest(null); }, [sessionId]); - const [dayInfo, setDayInfo] = useState<{ date: string | null; status: string; dayOfWeek: number } | null>(null); + const [dayInfo, setDayInfo] = useState<{ + date: string | null; + status: string; + dayOfWeek: number; + } | null>(null); useEffect(() => { // Fetch day info through a direct API call. @@ -455,9 +486,14 @@ export default function DayExecution() { const fetchDayInfo = async () => { try { - const data = await api<{ day: { date: string | null; status: string; dayOfWeek: number; sessions: { id: string; status: string }[] } }>( - `/days/${dayId}`, - ); + const data = await api<{ + day: { + date: string | null; + status: string; + dayOfWeek: number; + sessions: { id: string; status: string }[]; + }; + }>(`/days/${dayId}`); setDayInfo({ date: data.day.date, status: data.day.status, dayOfWeek: data.day.dayOfWeek }); const active = data.day.sessions.find((s) => s.status === 'IN_PROGRESS'); if (active) setSessionId(active.id); @@ -528,13 +564,19 @@ export default function DayExecution() { back: '/calendar', // akcje sesji (Ukończ/Porzuć) widoczne na starcie — grupa otwarta domyślnie defaultOpenGroup: 'actions', - actions: session?.status === 'IN_PROGRESS' - ? [ - { label: 'Dodaj ćwiczenie', onClick: () => setAddExerciseOpen(true), icon: Plus }, - { label: 'Ukończ sesję', onClick: complete, disabled: busy || normPending > 0 }, - { label: 'Porzuć sesję', onClick: () => setConfirmAbandon(true), variant: 'danger' as const, disabled: busy }, - ] - : undefined, + actions: + session?.status === 'IN_PROGRESS' + ? [ + { label: 'Dodaj ćwiczenie', onClick: () => setAddExerciseOpen(true), icon: Plus }, + { label: 'Ukończ sesję', onClick: complete, disabled: busy || normPending > 0 }, + { + label: 'Porzuć sesję', + onClick: () => setConfirmAbandon(true), + variant: 'danger' as const, + disabled: busy, + }, + ] + : undefined, }); const addExercise = async (exerciseId: string) => { @@ -645,7 +687,8 @@ export default function DayExecution() { {!session && dayInfo && dayInfo.status !== 'PLANNED' && (

- Dzień jest {dayInfo.status === 'COMPLETED' ? 'ukończony' : 'pominięty'}. Brak aktywnej sesji. + Dzień jest {dayInfo.status === 'COMPLETED' ? 'ukończony' : 'pominięty'}. Brak aktywnej + sesji.

)} @@ -683,8 +726,8 @@ export default function DayExecution() { setId: s.id, index: i, planned: planned - ? { reps: planned.reps, rir: planned.rir, difficulty: planned.difficulty } - : { reps: null, rir: null, difficulty: null }, + ? { reps: planned.reps, rir: planned.rir } + : { reps: null, rir: null }, restSec: planned?.restSec ?? null, }); }} @@ -721,9 +764,10 @@ export default function DayExecution() { open={editSet != null} setIndex={editSet?.index ?? 0} values={editValues} - planned={editSet?.planned ?? { reps: null, rir: null, difficulty: null }} + planned={editSet?.planned ?? { reps: null, rir: null }} title={ - editSet && (editValues.reps !== '' || editValues.rir !== '' || editValues.difficulty !== '') + editSet && + (editValues.reps !== '' || editValues.rir !== '' || editValues.difficulty !== '') ? `Edytuj serię ${editSet.index + 1}` : undefined } diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index 6fd0219..8149f5c 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -310,7 +310,6 @@ export default function PlanEditor() { loadKg: s.loadKg ? parseFloat(s.loadKg) : null, restSec: s.restSec ? parseInt(s.restSec) : null, rir: s.rir !== '' ? parseInt(s.rir) : null, - difficulty: s.difficulty ? parseInt(s.difficulty) : null, })), })), })), diff --git a/app/src/pages/plans/plan-editor/types.ts b/app/src/pages/plans/plan-editor/types.ts index 257e188..f9819cf 100644 --- a/app/src/pages/plans/plan-editor/types.ts +++ b/app/src/pages/plans/plan-editor/types.ts @@ -3,7 +3,6 @@ export interface EditorSet { loadKg: string; restSec: string; rir: string; - difficulty: string; } export interface EditorExercise { @@ -29,7 +28,6 @@ export const DEFAULT_SET: EditorSet = { restSec: '90', rir: '2', // trudności nie planujemy — uzupełnia ją ćwiczący po wykonaniu serii (sesja) - difficulty: '', }; export function emptyWeek(): EditorWeek { @@ -54,7 +52,6 @@ export function weekFromApi(week: { loadKg: number | null; restSec: number | null; rir: number | null; - difficulty: number | null; }[]; }[]; }[]; @@ -70,7 +67,6 @@ export function weekFromApi(week: { loadKg: s.loadKg?.toString() ?? '', restSec: s.restSec?.toString() ?? '', rir: s.rir?.toString() ?? '', - difficulty: s.difficulty?.toString() ?? '', })), })), })), diff --git a/app/test/DayExecution.test.tsx b/app/test/DayExecution.test.tsx index aa2b96e..3d4d81c 100644 --- a/app/test/DayExecution.test.tsx +++ b/app/test/DayExecution.test.tsx @@ -71,8 +71,8 @@ function sessionBody( planExercise: { id: 'pe-1', sets: [ - { id: 'ps-1', index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, difficulty: null, cardioBpm: null, timeSec: null, speed: null }, - { id: 'ps-2', index: 1, reps: 8, loadKg: 60, restSec: 90, rir: 2, difficulty: null, cardioBpm: null, timeSec: null, speed: null }, + { id: 'ps-1', index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null }, + { id: 'ps-2', index: 1, reps: 8, loadKg: 60, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null }, ], }, sets: [ diff --git a/app/test/PlanDetail.test.tsx b/app/test/PlanDetail.test.tsx index 470a871..1bcb8d5 100644 --- a/app/test/PlanDetail.test.tsx +++ b/app/test/PlanDetail.test.tsx @@ -84,7 +84,6 @@ function planDetail(overrides: Record = {}) { loadKg: 60, restSec: 90, rir: 2, - difficulty: 3, cardioBpm: null, timeSec: null, speed: null, diff --git a/app/test/e2e/mock-api.ts b/app/test/e2e/mock-api.ts index a1d467c..3526852 100644 --- a/app/test/e2e/mock-api.ts +++ b/app/test/e2e/mock-api.ts @@ -530,7 +530,7 @@ export const TEST_TRAINEE_PLAN_DETAIL = { order: 0, exercise: { id: 'ex-1', name: 'Przysiady', primaryMuscle: 'legs' }, sets: [ - { id: 'tps-1', index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, difficulty: 3, cardioBpm: null, timeSec: null, speed: null }, + { id: 'tps-1', index: 0, reps: 10, loadKg: 60, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null }, ], }, ], @@ -585,7 +585,7 @@ export const TEST_TRAINEE_PLAN_DETAIL_ACTIVE = { order: 0, exercise: { id: 'ex-2', name: 'Wyciskanie', primaryMuscle: 'chest' }, sets: [ - { id: 'tps-2', index: 0, reps: 8, loadKg: 40, restSec: 90, rir: 2, difficulty: 3, cardioBpm: null, timeSec: null, speed: null }, + { id: 'tps-2', index: 0, reps: 8, loadKg: 40, restSec: 90, rir: 2, cardioBpm: null, timeSec: null, speed: null }, ], }, ], diff --git a/app/test/plan-editor-state.test.ts b/app/test/plan-editor-state.test.ts index cd49e4c..760109d 100644 --- a/app/test/plan-editor-state.test.ts +++ b/app/test/plan-editor-state.test.ts @@ -146,7 +146,7 @@ describe('usePlanEditorState — akcje mutacji', () => { exercises: [ { exerciseId: 'ex-1', - sets: [{ reps: 10, loadKg: 20, restSec: 90, rir: 2, difficulty: 3 }], + sets: [{ reps: 10, loadKg: 20, restSec: 90, rir: 2 }], }, ], }, diff --git a/app/test/trainee-plans.test.tsx b/app/test/trainee-plans.test.tsx index 26be9b2..30c4ff4 100644 --- a/app/test/trainee-plans.test.tsx +++ b/app/test/trainee-plans.test.tsx @@ -102,7 +102,6 @@ const DRAFT_DETAIL = { loadKg: 60, restSec: 90, rir: 2, - difficulty: 3, cardioBpm: null, timeSec: null, speed: null, @@ -149,7 +148,6 @@ const ACTIVE_DETAIL = { loadKg: 40, restSec: 90, rir: 2, - difficulty: 3, cardioBpm: null, timeSec: null, speed: null,