Plany: karta hero aktywnego planu z podgledem tygodnia - GET /plans zwieksza plans o summary (rozklad dni treningowych i liczba cwiczen tygodnia biezacego lub pierwszego), ActivePlanHero renderuje chipy dni i licznik cwiczen, helper dayShort w lib/format, swagger i i18n pl/en (testy unit api + integracyjne + unit i e2e app)
This commit is contained in:
@@ -196,6 +196,17 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
.filter((d) => d.status === 'PLANNED' && d.date)
|
||||
.sort((a, b) => a.date!.getTime() - b.date!.getTime());
|
||||
const next = pending.find((d) => d.date!.getTime() >= startOfToday.getTime());
|
||||
const currentWeek = pending.length > 0 ? pending[0].weekIndex : null;
|
||||
// Karta hero: podgląd tygodnia bieżącego (lub pierwszego) — rozkład dni
|
||||
// treningowych i liczba ćwiczeń w tygodniu.
|
||||
const orderedWeeks = [...(p.weeks ?? [])].sort((a, b) => a.index - b.index);
|
||||
const refWeek = orderedWeeks.find((w) => w.index === currentWeek) ?? orderedWeeks[0] ?? null;
|
||||
const summary = refWeek
|
||||
? {
|
||||
trainingDays: refWeek.days.map((d) => d.dayOfWeek).sort((a, b) => a - b),
|
||||
exercises: refWeek.days.reduce((sum, d) => sum + (d._count?.exercises ?? 0), 0),
|
||||
}
|
||||
: null;
|
||||
return {
|
||||
...rest,
|
||||
progress: {
|
||||
@@ -203,7 +214,7 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
total,
|
||||
percent: total > 0 ? Math.round((completed / total) * 100) : 0,
|
||||
},
|
||||
currentWeek: pending.length > 0 ? pending[0].weekIndex : null,
|
||||
currentWeek,
|
||||
nextDay: next
|
||||
? {
|
||||
date: next.date!.toISOString(),
|
||||
@@ -211,6 +222,7 @@ export async function listPlans(prisma: PrismaClient, userId: string) {
|
||||
exerciseCount: next._count.exercises,
|
||||
}
|
||||
: null,
|
||||
summary,
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1352,6 +1352,8 @@ export const openapi: Record<string, unknown> = {
|
||||
get: {
|
||||
tags: ['Plans'],
|
||||
summary: "User's plans",
|
||||
description:
|
||||
'List fields per plan: progress { completed, total, percent }, currentWeek (week of the nearest unresolved dated day), nextDay { date, dayOfWeek, exerciseCount } (first PLANNED day today or later), summary { trainingDays (dayOfWeek of the current or first week), exercises (weekly exercise count) } for the hero card',
|
||||
security: [{ bearerAuth: [] }],
|
||||
},
|
||||
post: {
|
||||
|
||||
Reference in New Issue
Block a user