Dashboard: rozdzielenie statystyk 'Aktywny plan' (ring + postep) od 'Historia' (killstreak, ukonczone plany, treningi, serie); API /dashboard += history

This commit is contained in:
Tilumca
2026-10-15 02:47:42 +02:00
parent 3a5e352b96
commit 94f8fc2e57
7 changed files with 189 additions and 52 deletions

View File

@@ -25,6 +25,28 @@ export async function getDashboard(prisma: PrismaClient, userId: string) {
let extra: { sets: number } | null = null;
let missing: { sets: number } | null = null;
// Historia — globalna (ponad wszystkimi planami), w kontrze do progress/extra/missing,
// które dotyczą wyłącznie aktywnego planu.
const completedSessionWhere = {
status: 'COMPLETED' as const,
day: { week: { plan: { userId } } },
};
const [completedPlans, historySessions, historySets] = await Promise.all([
prisma.trainingPlan.count({ where: { userId, status: 'COMPLETED' } }),
prisma.trainingSession.count({ where: completedSessionWhere }),
prisma.sessionSet.count({
where: {
reps: { not: null },
exercise: { removed: false, hidden: false, session: completedSessionWhere },
},
}),
]);
const history = {
completedPlans,
sessions: historySessions,
sets: historySets,
};
if (activePlan) {
const days = await prisma.planDay.findMany({
where: { week: { planId: activePlan.id } },
@@ -103,6 +125,7 @@ export async function getDashboard(prisma: PrismaClient, userId: string) {
return {
killstreak,
history,
nextTraining,
progress,
extra,

View File

@@ -1086,7 +1086,8 @@ export const openapi: Record<string, unknown> = {
'/dashboard': {
get: {
tags: ['Dashboard'],
summary: 'Dashboard — killstreak, next training, plan progress',
summary:
'Dashboard — killstreak, globalna historia (plany/sesje/serie), next training, progress aktywnego planu',
security: [{ bearerAuth: [] }],
},
},