Api+app: usuniecie PlanSet.difficulty z kontraktu planu (trudnosc pozostaje wynikiem rzeczywistym serii)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- Usuniecie PlanSet.difficulty (trudnosc jest wynikiem rzeczywistym, nie planowanym)
|
||||
ALTER TABLE "PlanSet" DROP COLUMN "difficulty";
|
||||
@@ -576,7 +576,6 @@ model PlanSet {
|
||||
loadKg Float?
|
||||
restSec Int?
|
||||
rir Int?
|
||||
difficulty Int?
|
||||
cardioBpm Int?
|
||||
timeSec Int?
|
||||
speed Float?
|
||||
|
||||
@@ -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 }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -522,7 +522,6 @@ export const openapi: Record<string, unknown> = {
|
||||
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 },
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() ?? '',
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ function SessionStatusCard({
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
||||
{/* kolorowe badge'y zgrupowane po lewej; data nie rozdziela ich */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge color={SESSION_STATUS[session.status].color}>{SESSION_STATUS[session.status].label}</Badge>
|
||||
<Badge color={SESSION_STATUS[session.status].color}>
|
||||
{SESSION_STATUS[session.status].label}
|
||||
</Badge>
|
||||
{extraDone > 0 && <Badge color="green">+{extraDone} bonus</Badge>}
|
||||
</div>
|
||||
<span className="text-dim text-[0.875rem]">start: {fmtDate(session.startedAt)}</span>
|
||||
@@ -90,7 +92,10 @@ function SessionStatusCard({
|
||||
</b>
|
||||
/ {Math.floor(rest.totalSec / 60)}:{String(rest.totalSec % 60).padStart(2, '0')}
|
||||
</span>
|
||||
<ProgressBar percent={Math.round((restRemaining / rest.totalSec) * 100)} className="min-w-24 flex-1" />
|
||||
<ProgressBar
|
||||
percent={Math.round((restRemaining / rest.totalSec) * 100)}
|
||||
className="min-w-24 flex-1"
|
||||
/>
|
||||
<Button variant="ghost" size="sm" onClick={onEndRest}>
|
||||
Zakończ
|
||||
</Button>
|
||||
@@ -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 <span className="ml-0.5 text-[0.55em] font-semibold tracking-normal text-dim">{children}</span>;
|
||||
return (
|
||||
<span className="ml-0.5 text-[0.55em] font-semibold tracking-normal text-dim">{children}</span>
|
||||
);
|
||||
}
|
||||
|
||||
/* 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.` : ''}
|
||||
</span>
|
||||
) : null,
|
||||
planned?.restSec != null ? <span key="rest">przerwa {planned.restSec} s</span> : null,
|
||||
planned?.restSec != null ? (
|
||||
<span key="rest">przerwa {planned.restSec} s</span>
|
||||
) : null,
|
||||
planned?.rir != null ? <span key="rir">RIR {planned.rir}</span> : 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 (
|
||||
<Card>
|
||||
{/* nagłówek = akordeon: klik rozwija/zwija; aktywne ćwiczenie (z następną serią) rozwija się samo */}
|
||||
@@ -260,7 +270,9 @@ function ExerciseAccordion({
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<H3 className="mb-0">{exercise.exercise.name}</H3>
|
||||
<Badge color="green">Ćwiczenie {order} / {total}</Badge>
|
||||
<Badge color="green">
|
||||
Ćwiczenie {order} / {total}
|
||||
</Badge>
|
||||
{exercise.planExercise === null && <Badge color="blue">dodane do sesji</Badge>}
|
||||
{isNextEx && !expanded && <Badge color="green">Następna</Badge>}
|
||||
</div>
|
||||
@@ -269,7 +281,11 @@ function ExerciseAccordion({
|
||||
{MUSCLE_NAMES[exercise.exercise.primaryMuscle] || exercise.exercise.primaryMuscle}
|
||||
</span>
|
||||
{!expanded && (
|
||||
<Badge color={doneCount === exercise.sets.length && exercise.sets.length > 0 ? 'green' : 'gray'}>
|
||||
<Badge
|
||||
color={
|
||||
doneCount === exercise.sets.length && exercise.sets.length > 0 ? 'green' : 'gray'
|
||||
}
|
||||
>
|
||||
{doneCount}/{exercise.sets.length}
|
||||
</Badge>
|
||||
)}
|
||||
@@ -282,7 +298,9 @@ function ExerciseAccordion({
|
||||
Usuń
|
||||
</Button>
|
||||
)}
|
||||
<ChevronDown className={`w-5 h-5 text-dim transition-transform ${expanded ? 'rotate-180' : ''}`} />
|
||||
<ChevronDown
|
||||
className={`w-5 h-5 text-dim transition-transform ${expanded ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -312,7 +330,13 @@ function ExerciseAccordion({
|
||||
))}
|
||||
</div>
|
||||
{inProgress && (
|
||||
<Button variant="secondary" size="sm" className="mt-2" onClick={onAddSet} disabled={!canAddExtra}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
className="mt-2"
|
||||
onClick={onAddSet}
|
||||
disabled={!canAddExtra}
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
Dodaj serię
|
||||
</Button>
|
||||
@@ -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"
|
||||
>
|
||||
<span className="font-semibold">{p.name}</span>
|
||||
<span className="text-dim text-[0.8rem]">{MUSCLE_NAMES[p.primaryMuscle] || p.primaryMuscle}</span>
|
||||
<span className="text-dim text-[0.8rem]">
|
||||
{MUSCLE_NAMES[p.primaryMuscle] || p.primaryMuscle}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -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<string | null>(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' && (
|
||||
<Card>
|
||||
<p className="text-dim">
|
||||
Dzień jest {dayInfo.status === 'COMPLETED' ? 'ukończony' : 'pominięty'}. Brak aktywnej sesji.
|
||||
Dzień jest {dayInfo.status === 'COMPLETED' ? 'ukończony' : 'pominięty'}. Brak aktywnej
|
||||
sesji.
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
|
||||
@@ -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() ?? '',
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -84,7 +84,6 @@ function planDetail(overrides: Record<string, unknown> = {}) {
|
||||
loadKg: 60,
|
||||
restSec: 90,
|
||||
rir: 2,
|
||||
difficulty: 3,
|
||||
cardioBpm: null,
|
||||
timeSec: null,
|
||||
speed: null,
|
||||
|
||||
@@ -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 },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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 }],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user