API+App+Admin: telemetria bytnosci w ogolnym widoku sirowni - GET /gyms/:id/presence-stats (heatmapa dzien×godzina, sredni pobyt, wizyty/dzien, szczyt, teraz w srodku, top urzadzenia; stale 30 dni), wspoldzielony komponent PresenceHeatmap, telemetria wyciagnieta z podstrony statystyk; pasek godzin w forma zegarowa z minutami, usuniete karta Dane i filtr okresu; swagger + testy integracyjne, unit i e2e
This commit is contained in:
@@ -439,6 +439,30 @@ export async function getGymStats(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Telemetria bytności dla widoku ogólnego siłowni (aplikacja): dostęp jak
|
||||
* mapa urządzeń — REAL: każdy zalogowany; VIRTUAL: tylko menedżer (OWNER) lub
|
||||
* admin (puste statystyki — bytność istnieje tylko dla REAL). 404 gdy brak siłowni.
|
||||
*/
|
||||
export async function getGymPresenceTelemetry(
|
||||
prisma: PrismaClient,
|
||||
gymId: string,
|
||||
range: Required<RangeQuery>,
|
||||
caller: { userId: string; isAdmin: boolean },
|
||||
) {
|
||||
const gym = await prisma.gym.findUnique({ where: { id: gymId }, select: { kind: true } });
|
||||
if (!gym) throw notFound('Gym not found');
|
||||
if (gym.kind !== 'REAL' && !caller.isAdmin) {
|
||||
const membership = await prisma.gymMembership.findUnique({
|
||||
where: { userId_gymId: { userId: caller.userId, gymId } },
|
||||
select: { roles: true },
|
||||
});
|
||||
if (!membership?.roles.includes('OWNER'))
|
||||
throw forbidden('You do not have access to this gym');
|
||||
}
|
||||
return getGymStats(prisma, gymId, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Przegląd statystyk właściciela siłowni (tylko REAL): telemetria bytności
|
||||
* (bez top urządzeń — jest na podstronie urządzeń) + członkowie i napływ +
|
||||
|
||||
Reference in New Issue
Block a user