Dashboard: rozdzielenie statystyk 'Aktywny plan' (ring + postep) od 'Historia' (killstreak, ukonczone plany, treningi, serie); API /dashboard += history
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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: [] }],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user