Plany: wizard 3-etapowy tworzenia/edycji, silownia i alias tygodnia (UX + API + migracja)

This commit is contained in:
tisachi
2026-09-12 15:16:13 +02:00
parent a2d31ee46b
commit ef2fa726bb
26 changed files with 1340 additions and 361 deletions

View File

@@ -25,12 +25,16 @@ const planDaySchema = z.object({
const planWeekSchema = z.object({
index: z.number().int().min(0),
// Opcjonalny alias tygodnia (np. „Deload").
customName: z.string().max(40).nullable().optional(),
days: z.array(planDaySchema),
});
const planBaseSchema = z.object({
title: z.string().min(1).max(200),
weeksCount: z.number().int().min(1).max(8),
// Informacyjna — siłownia, w której realizowany jest plan (właściciel musi być jej członkiem).
gymId: z.string().nullable().optional(),
weeks: z.array(planWeekSchema),
});
@@ -51,7 +55,5 @@ export const updatePlanSchema = planBaseSchema.refine((d) => d.weeks.length ===
});
export const activateSchema = z.object({
startDate: z
.string()
.refine((v) => !Number.isNaN(new Date(v).getTime()), 'Invalid date'),
startDate: z.string().refine((v) => !Number.isNaN(new Date(v).getTime()), 'Invalid date'),
});

View File

@@ -21,7 +21,10 @@ import {
withdrawInvitation,
} from '../services/trainer.js';
import { addTraineeComment, deleteTraineeComment } from '../services/comments.js';
import { getTraineeExerciseProgress, getTraineeLatestResults } from '../services/exerciseProgress.js';
import {
getTraineeExerciseProgress,
getTraineeLatestResults,
} from '../services/exerciseProgress.js';
import {
abandonPlan,
activatePlan,
@@ -206,7 +209,12 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
asyncHandler(async (req, res) => {
const parsed = searchQuerySchema.safeParse(req.query);
if (!parsed.success) throw badRequest('firstName and lastName query parameters are required');
const result = await searchUsers(prisma, req.user!.id, parsed.data.firstName, parsed.data.lastName);
const result = await searchUsers(
prisma,
req.user!.id,
parsed.data.firstName,
parsed.data.lastName,
);
res.json(result);
}),
);
@@ -351,7 +359,12 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
asyncHandler(async (req, res) => {
const parsed = calendarQuerySchema.safeParse(req.query);
if (!parsed.success) throw badRequest('month must be in YYYY-MM format');
const result = await getTraineeCalendar(prisma, req.user!.id, req.params.userId, parsed.data.month);
const result = await getTraineeCalendar(
prisma,
req.user!.id,
req.params.userId,
parsed.data.month,
);
res.json(result);
}),
);
@@ -421,11 +434,12 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
* @openapi
* /trainer/trainees/{userId}/plans:
* post:
* summary: Create a plan for the trainee (owner = trainee, creator = trainer)
* summary: Create a plan for the trainee (owner = trainee, creator = trainer).
* Optional gymId (the trainee must be a gym member) and per-week customName (alias, max 40)
* tags: [Trainer]
* responses:
* 201: { description: Created }
* 400: { description: Validation error / start date not a Monday / start week in the past }
* 400: { description: Validation error / start date not a Monday / start week in the past / gym not a trainee membership }
* 403: { description: Trainer role required }
* 404: { description: Trainee not found }
* 409: { description: Trainee already has an active plan }
@@ -474,11 +488,11 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
* @openapi
* /trainer/trainees/{userId}/plans/{planId}:
* patch:
* summary: Replace plan structure (draft only)
* summary: Replace plan structure (draft only). Same body as POST (gymId, weeks[].customName)
* tags: [Trainer]
* responses:
* 200: { description: OK }
* 400: { description: Not a draft }
* 400: { description: Not a draft / gym not a trainee membership }
* 403: { description: Trainer role required }
* 404: { description: Trainee or plan not found }
*/