Baseline: stan przed refaktoryzacja struktury
This commit is contained in:
85
app/src/api/client.ts
Normal file
85
app/src/api/client.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { API_BASE } from '../config';
|
||||
import type { ApiErrorBody } from './types';
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
public status: number,
|
||||
public body: ApiErrorBody | null,
|
||||
) {
|
||||
super(body?.error?.message || `HTTP ${status}`);
|
||||
}
|
||||
}
|
||||
|
||||
let accessToken: string | null = localStorage.getItem('fitos_access');
|
||||
let refreshing: Promise<boolean> | null = null;
|
||||
|
||||
export function setAccessToken(token: string | null) {
|
||||
accessToken = token;
|
||||
if (token) localStorage.setItem('fitos_access', token);
|
||||
else localStorage.removeItem('fitos_access');
|
||||
}
|
||||
|
||||
export function getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
async function tryRefresh(): Promise<boolean> {
|
||||
if (!refreshing) {
|
||||
refreshing = fetch(`${API_BASE}/auth/refresh`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) return false;
|
||||
const data = await res.json();
|
||||
setAccessToken(data.accessToken);
|
||||
return true;
|
||||
})
|
||||
.catch(() => false)
|
||||
.finally(() => {
|
||||
setTimeout(() => (refreshing = null), 0);
|
||||
});
|
||||
}
|
||||
return refreshing;
|
||||
}
|
||||
|
||||
export async function api<T>(path: string, opts: { method?: string; body?: unknown } = {}): Promise<T> {
|
||||
const isFormData = typeof FormData !== 'undefined' && opts.body instanceof FormData;
|
||||
const doFetch = () =>
|
||||
fetch(`${API_BASE}${path}`, {
|
||||
method: opts.method || 'GET',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
// FormData: przeglądarka sama stawia multipart boundary
|
||||
...(isFormData ? {} : { 'Content-Type': 'application/json' }),
|
||||
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
||||
},
|
||||
body: opts.body === undefined ? undefined : isFormData ? (opts.body as FormData) : JSON.stringify(opts.body),
|
||||
});
|
||||
|
||||
let res = await doFetch();
|
||||
|
||||
if (res.status === 401 && path !== '/auth/refresh' && path !== '/auth/login' && path !== '/auth/register') {
|
||||
const ok = await tryRefresh();
|
||||
if (ok) res = await doFetch();
|
||||
else {
|
||||
setAccessToken(null);
|
||||
window.dispatchEvent(new Event('fitos:logout'));
|
||||
}
|
||||
}
|
||||
|
||||
const text = await res.text();
|
||||
let json: unknown = null;
|
||||
if (text) {
|
||||
try {
|
||||
json = JSON.parse(text);
|
||||
} catch {
|
||||
// ciało nie-JSON (np. rate limiter, proxy) — traktujemy jako nieprzezroczysty błąd
|
||||
}
|
||||
}
|
||||
if (!res.ok) {
|
||||
const body = (json ?? (text ? { error: { code: `HTTP_${res.status}`, message: text } } : null)) as ApiErrorBody | null;
|
||||
throw new ApiError(res.status, body);
|
||||
}
|
||||
return json as T;
|
||||
}
|
||||
715
app/src/api/queries.ts
Normal file
715
app/src/api/queries.ts
Normal file
@@ -0,0 +1,715 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from './client';
|
||||
import { API_BASE } from '../config';
|
||||
import type {
|
||||
ActiveSession,
|
||||
Availability,
|
||||
CalendarDay,
|
||||
Conversation,
|
||||
ConversationThread,
|
||||
Dashboard,
|
||||
Equipment,
|
||||
ExerciseComment,
|
||||
ExerciseProgress,
|
||||
FocusArea,
|
||||
FocusChain,
|
||||
HistorySession,
|
||||
Gym,
|
||||
GymDetailResponse,
|
||||
GymException,
|
||||
GymRole,
|
||||
Message,
|
||||
Plan,
|
||||
Exercise,
|
||||
Session,
|
||||
User,
|
||||
GymMembership,
|
||||
WeightPoint,
|
||||
CircumferenceSeries,
|
||||
Invitation,
|
||||
GymClaim,
|
||||
GymInvitation,
|
||||
GymKind,
|
||||
VirtualGym,
|
||||
Trainee,
|
||||
TraineeDetail,
|
||||
TraineeReport,
|
||||
DayMoveEntry,
|
||||
UserSearchResult,
|
||||
LatestExerciseResult,
|
||||
} from './types';
|
||||
|
||||
/** Pełny adres URL zdjęcia siłowni (url = `/gyms/:id/photos/:photoId`). */
|
||||
export const gymPhotoSrc = (url: string): string => `${API_BASE}${url}`;
|
||||
|
||||
// ---------- me / profile ----------
|
||||
export function useMe() {
|
||||
return useQuery({
|
||||
queryKey: ['me'],
|
||||
queryFn: () => api<{ user: User; memberships: GymMembership[] }>('/me'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useBodyParameters() {
|
||||
return useQuery({
|
||||
queryKey: ['me', 'body-parameters'],
|
||||
queryFn: () =>
|
||||
api<{ weight: WeightPoint[]; circumferences: CircumferenceSeries[] }>(
|
||||
'/me/body-parameters',
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateProfile(body: Record<string, unknown>) {
|
||||
return api<{ user: User }>('/me', { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
/** `YYYY-MM-DD` (z pola date) → ISO; puste = API używa bieżącej daty. */
|
||||
function toIsoDate(date: string | undefined): string | undefined {
|
||||
return date ? new Date(`${date}T00:00:00Z`).toISOString() : undefined;
|
||||
}
|
||||
|
||||
export function addWeight(value: number, date?: string) {
|
||||
const iso = toIsoDate(date);
|
||||
return api('/me/body-parameters/weight', { method: 'POST', body: { value, ...(iso ? { date: iso } : {}) } });
|
||||
}
|
||||
|
||||
export function addCircumference(name: string, value: number, date?: string) {
|
||||
const iso = toIsoDate(date);
|
||||
return api('/me/body-parameters/circumference', { method: 'POST', body: { name, value, ...(iso ? { date: iso } : {}) } });
|
||||
}
|
||||
|
||||
export function removeWeightPoint(id: string) {
|
||||
return api(`/me/body-parameters/weight/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function removeCircumferencePoint(id: string) {
|
||||
return api(`/me/body-parameters/circumference/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function useHistory() {
|
||||
return useQuery({
|
||||
queryKey: ['me', 'history'],
|
||||
queryFn: () => api<{ sessions: HistorySession[] }>('/me/history'),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- gyms ----------
|
||||
export interface UserGym extends Gym {
|
||||
roles: GymRole[];
|
||||
}
|
||||
|
||||
export function useGyms() {
|
||||
return useQuery({
|
||||
queryKey: ['gyms'],
|
||||
queryFn: () => api<{ gyms: UserGym[] }>('/gyms'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAllGyms() {
|
||||
return useQuery({
|
||||
queryKey: ['gyms', 'all'],
|
||||
queryFn: () => api<{ gyms: Gym[] }>('/gyms/all'),
|
||||
});
|
||||
}
|
||||
|
||||
/** Publiczny detal siłowni (REAL widoczny dla każdego; VIRTUAL tylko dla menedżerów). */
|
||||
export function useGymDetail(id: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['gym', id],
|
||||
queryFn: () => api<GymDetailResponse>(`/gyms/${id}`),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
/** Dodaje zdjęcia do galerii siłowni REAL (multipart, pole `photos`). */
|
||||
export function addGymPhotos(gymId: string, files: File[]) {
|
||||
const form = new FormData();
|
||||
for (const f of files) form.append('photos', f);
|
||||
return api<{ gym: Gym & { photos: { id: string; url: string; order: number; createdAt: string }[] } }>(
|
||||
`/gyms/${gymId}/photos`,
|
||||
{ method: 'POST', body: form },
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteGymPhoto(gymId: string, photoId: string) {
|
||||
return api(`/gyms/${gymId}/photos/${encodeURIComponent(photoId)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function setGymPhotoCover(gymId: string, photoId: string) {
|
||||
return api(`/gyms/${gymId}/photos/${encodeURIComponent(photoId)}/cover`, { method: 'PATCH' });
|
||||
}
|
||||
|
||||
export function joinGym(gymId: string) {
|
||||
return api<{ membership: { gymId: string; name: string; roles: GymRole[] } }>(
|
||||
`/gyms/${gymId}/join`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
}
|
||||
|
||||
export function createGym(body: {
|
||||
name: string;
|
||||
location?: string | null;
|
||||
availability?: Availability | null;
|
||||
capacity?: number | null;
|
||||
kind?: GymKind;
|
||||
isPrivate?: boolean;
|
||||
}) {
|
||||
return api<{ gym: UserGym }>('/gyms', { method: 'POST', body });
|
||||
}
|
||||
|
||||
/** Public virtual gyms (+ the caller's own private ones) with rating counts and claim status. */
|
||||
export function useVirtualGyms() {
|
||||
return useQuery({
|
||||
queryKey: ['gyms', 'virtual'],
|
||||
queryFn: () => api<{ gyms: VirtualGym[] }>('/gyms/virtual'),
|
||||
});
|
||||
}
|
||||
|
||||
/** Thumb vote on a public virtual gym (same vote again removes it). */
|
||||
export function rateGym(gymId: string, vote: 'UP' | 'DOWN') {
|
||||
return api<{ vote: 'UP' | 'DOWN' | null; up: number; down: number }>(`/gyms/${gymId}/rate`, {
|
||||
method: 'POST',
|
||||
body: { vote },
|
||||
});
|
||||
}
|
||||
|
||||
export function addGymEquipment(gymId: string, equipmentId: string, quantity = 1) {
|
||||
return api<{ gym: Gym }>(`/gyms/${gymId}/equipment`, {
|
||||
method: 'POST',
|
||||
body: { equipmentId, quantity },
|
||||
});
|
||||
}
|
||||
|
||||
export function updateGymEquipmentQuantity(gymId: string, equipmentId: string, quantity: number) {
|
||||
return api<{ gym: Gym }>(`/gyms/${gymId}/equipment/${encodeURIComponent(equipmentId)}`, {
|
||||
method: 'PATCH',
|
||||
body: { quantity },
|
||||
});
|
||||
}
|
||||
|
||||
export function removeGymEquipment(gymId: string, equipmentId: string) {
|
||||
return api(`/gyms/${gymId}/equipment/${encodeURIComponent(equipmentId)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/** The user's gyms where they hold the OWNER role (for gym management). */
|
||||
export function useOwnedGyms() {
|
||||
const { data, ...rest } = useGyms();
|
||||
const owned = (data?.gyms ?? []).filter((g) => g.roles.includes('OWNER'));
|
||||
return { ...rest, data: { gyms: owned } };
|
||||
}
|
||||
|
||||
export function updateGym(
|
||||
gymId: string,
|
||||
body: {
|
||||
name?: string;
|
||||
location?: string | null;
|
||||
availability?: Availability | null;
|
||||
capacity?: number | null;
|
||||
isPrivate?: boolean;
|
||||
},
|
||||
) {
|
||||
return api<{ gym: Gym }>(`/gyms/${gymId}`, { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
export function deleteGym(gymId: string) {
|
||||
return api(`/gyms/${gymId}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function useGymExceptions(gymId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['gym-exceptions', gymId],
|
||||
queryFn: () => api<{ exceptions: GymException[] }>(`/gyms/${gymId}/exceptions`),
|
||||
enabled: !!gymId,
|
||||
});
|
||||
}
|
||||
|
||||
export function createGymException(gymId: string, body: { date: string; availability: { start: string; end: string } | null }) {
|
||||
return api<{ exception: GymException }>(`/gyms/${gymId}/exceptions`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteGymException(gymId: string, exceptionId: string) {
|
||||
return api(`/gyms/${gymId}/exceptions/${encodeURIComponent(exceptionId)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
// ---------- gym claims (verification / new real gym) ----------
|
||||
export interface GymClaimInput {
|
||||
/** Set = verification of that virtual gym; omit = claim for a NEW real gym. */
|
||||
gymId?: string;
|
||||
description: string;
|
||||
companyName?: string;
|
||||
nip?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
/** Verification only: overrides gym.location on approval. */
|
||||
address?: string;
|
||||
/** New-real only: */
|
||||
gymName?: string;
|
||||
gymLocation?: string;
|
||||
gymAvailability?: Availability | null;
|
||||
gymCapacity?: number | null;
|
||||
}
|
||||
|
||||
/** Create a gym claim (multipart). `files` optional (jpg/png/pdf, ≤5×5 MB). */
|
||||
export function createGymClaim(data: GymClaimInput, files: File[] = []) {
|
||||
const form = new FormData();
|
||||
if (data.gymId) form.append('gymId', data.gymId);
|
||||
form.append('description', data.description);
|
||||
if (data.companyName) form.append('companyName', data.companyName);
|
||||
if (data.nip) form.append('nip', data.nip);
|
||||
if (data.phone) form.append('phone', data.phone);
|
||||
if (data.email) form.append('email', data.email);
|
||||
if (data.address) form.append('address', data.address);
|
||||
if (data.gymName) form.append('gymName', data.gymName);
|
||||
if (data.gymLocation) form.append('gymLocation', data.gymLocation);
|
||||
if (data.gymAvailability) form.append('gymAvailability', JSON.stringify(data.gymAvailability));
|
||||
if (data.gymCapacity != null) form.append('gymCapacity', String(data.gymCapacity));
|
||||
for (const f of files) form.append('files', f);
|
||||
return api<{ claim: GymClaim }>('/gyms/claims', { method: 'POST', body: form });
|
||||
}
|
||||
|
||||
export function useMyGymClaims() {
|
||||
return useQuery({
|
||||
queryKey: ['gyms', 'claims'],
|
||||
queryFn: () => api<{ claims: GymClaim[] }>('/gyms/claims'),
|
||||
});
|
||||
}
|
||||
|
||||
export function withdrawGymClaim(claimId: string) {
|
||||
return api(`/gyms/claims/${encodeURIComponent(claimId)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
// ---------- gym invitations (private virtual gyms) ----------
|
||||
export function useGymInvitations() {
|
||||
return useQuery({
|
||||
queryKey: ['gym-invitations'],
|
||||
queryFn: () => api<{ invitations: GymInvitation[] }>('/gyms/invitations'),
|
||||
});
|
||||
}
|
||||
|
||||
export function sendGymInvitation(gymId: string, userId: string) {
|
||||
return api<{ invitation: GymInvitation }>('/gyms/invitations', {
|
||||
method: 'POST',
|
||||
body: { gymId, userId },
|
||||
});
|
||||
}
|
||||
|
||||
export function acceptGymInvitation(id: string) {
|
||||
return api(`/gyms/invitations/${encodeURIComponent(id)}/accept`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function declineGymInvitation(id: string) {
|
||||
return api(`/gyms/invitations/${encodeURIComponent(id)}/decline`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function withdrawGymInvitation(id: string) {
|
||||
return api(`/gyms/invitations/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/** Search users to invite to a private virtual gym (owner only). */
|
||||
export function useGymInviteeSearch(gymId: string, firstName: string, lastName: string) {
|
||||
return useQuery({
|
||||
queryKey: ['gym-invitee-search', gymId, firstName, lastName],
|
||||
queryFn: () =>
|
||||
api<{ users: UserSearchResult[] }>(
|
||||
`/gyms/invitations/search?gymId=${encodeURIComponent(gymId)}&firstName=${encodeURIComponent(firstName)}&lastName=${encodeURIComponent(lastName)}`,
|
||||
),
|
||||
enabled: !!gymId && firstName.trim().length > 0 && lastName.trim().length > 0,
|
||||
});
|
||||
}
|
||||
|
||||
/** List the equipment (machine/device) catalog. */
|
||||
export function useEquipment() {
|
||||
return useQuery({ queryKey: ['equipment'], queryFn: () => api<{ equipment: Equipment[] }>('/equipment') });
|
||||
}
|
||||
|
||||
// ---------- exercises ----------
|
||||
export function useExercises() {
|
||||
return useQuery({ queryKey: ['exercises'], queryFn: () => api<{ exercises: Exercise[] }>('/exercises') });
|
||||
}
|
||||
|
||||
// ---------- focus areas (priorities/exclusions) ----------
|
||||
export function useFocusAreas() {
|
||||
return useQuery({ queryKey: ['focus-areas'], queryFn: () => api<{ focusAreas: FocusArea[] }>('/focus-areas') });
|
||||
}
|
||||
|
||||
export function useFocusChain() {
|
||||
return useQuery({ queryKey: ['focus-chain'], queryFn: () => api<FocusChain>('/me/focus-chain') });
|
||||
}
|
||||
|
||||
// ---------- plans ----------
|
||||
export function usePlans() {
|
||||
return useQuery({ queryKey: ['plans'], queryFn: () => api<{ plans: Plan[] }>('/plans') });
|
||||
}
|
||||
|
||||
export function usePlan(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['plans', id],
|
||||
queryFn: () => api<{ plan: Plan }>(`/plans/${id}`),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export interface PlanSetInput {
|
||||
index: number;
|
||||
reps?: number | null;
|
||||
loadKg?: number | null;
|
||||
restSec?: number | null;
|
||||
rir?: number | null;
|
||||
difficulty?: number | null;
|
||||
cardioBpm?: number | null;
|
||||
timeSec?: number | null;
|
||||
speed?: number | null;
|
||||
}
|
||||
|
||||
export interface PlanExerciseInput {
|
||||
exerciseId: string;
|
||||
order: number;
|
||||
sets: PlanSetInput[];
|
||||
}
|
||||
|
||||
export interface PlanDayInput {
|
||||
dayOfWeek: number;
|
||||
exercises: PlanExerciseInput[];
|
||||
}
|
||||
|
||||
export interface PlanWeekInput {
|
||||
index: number;
|
||||
days: PlanDayInput[];
|
||||
}
|
||||
|
||||
export function createPlan(body: {
|
||||
title: string;
|
||||
weeksCount: number;
|
||||
weeks: PlanWeekInput[];
|
||||
/** Opcjonalna data startu (poniedziałek) — plan tworzony i aktywowany w jednym kroku. */
|
||||
startDate?: string;
|
||||
}) {
|
||||
return api<{ plan: { id: string } }>('/plans', { method: 'POST', body });
|
||||
}
|
||||
|
||||
export function updatePlan(id: string, body: { title: string; weeksCount: number; weeks: PlanWeekInput[] }) {
|
||||
return api(`/plans/${id}`, { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
export function deletePlan(id: string) {
|
||||
return api(`/plans/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function activatePlan(id: string, startDate: string) {
|
||||
return api(`/plans/${id}/activate`, { method: 'POST', body: { startDate } });
|
||||
}
|
||||
|
||||
export function abandonPlan(id: string) {
|
||||
return api(`/plans/${id}/abandon`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function completePlan(id: string) {
|
||||
return api(`/plans/${id}/complete`, { method: 'POST' });
|
||||
}
|
||||
|
||||
// ---------- sessions ----------
|
||||
export function useSession(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['sessions', id],
|
||||
queryFn: () => api<{ session: Session }>(`/sessions/${id}`),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
/** Aktywna (IN_PROGRESS) sesja użytkownika — null, gdy żadna nie trwa. */
|
||||
export function useActiveSession() {
|
||||
return useQuery({
|
||||
queryKey: ['active-session'],
|
||||
queryFn: () => api<{ session: ActiveSession | null }>('/me/active-session'),
|
||||
});
|
||||
}
|
||||
|
||||
export function startSession(dayId: string) {
|
||||
return api<{ sessionId: string }>(`/days/${dayId}/sessions`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function addSessionExercise(sessionId: string, exerciseId: string) {
|
||||
return api<{ exerciseId: string }>(`/sessions/${sessionId}/exercises`, {
|
||||
method: 'POST',
|
||||
body: { exerciseId },
|
||||
});
|
||||
}
|
||||
|
||||
export function setSessionExerciseState(exerciseId: string, data: { hidden?: boolean; removed?: boolean }) {
|
||||
return api(`/sessions/exercises/${exerciseId}`, { method: 'PATCH', body: data });
|
||||
}
|
||||
|
||||
export function addSessionSet(exerciseId: string) {
|
||||
return api<{ setId: string }>(`/sessions/exercises/${exerciseId}/sets`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function updateSessionSet(setId: string, data: { reps?: number | null; rir?: number | null; difficulty?: number | null; note?: string | null }) {
|
||||
return api(`/sessions/sets/${setId}`, { method: 'PATCH', body: data });
|
||||
}
|
||||
|
||||
export function deleteSessionSet(setId: string) {
|
||||
return api(`/sessions/sets/${setId}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function completeSession(sessionId: string) {
|
||||
return api(`/sessions/${sessionId}/complete`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function abandonSession(sessionId: string) {
|
||||
return api(`/sessions/${sessionId}/abandon`, { method: 'POST' });
|
||||
}
|
||||
|
||||
// ---------- dashboard / calendar ----------
|
||||
export function useDashboard() {
|
||||
return useQuery({ queryKey: ['dashboard'], queryFn: () => api<Dashboard>('/dashboard') });
|
||||
}
|
||||
|
||||
// ---------- trainer / trainees ----------
|
||||
/** True when the user holds the TRAINER role in at least one gym. */
|
||||
export function useIsTrainer() {
|
||||
const { data } = useMe();
|
||||
return (data?.memberships ?? []).some((m) => m.roles.includes('TRAINER'));
|
||||
}
|
||||
|
||||
export function useTrainees(gymId?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', gymId ?? 'all'],
|
||||
queryFn: () =>
|
||||
api<{ trainees: Trainee[] }>(`/trainer/trainees${gymId ? `?gymId=${gymId}` : ''}`),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTrainee(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId],
|
||||
queryFn: () => api<TraineeDetail>(`/trainer/trainees/${userId}`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeHistory(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'history'],
|
||||
queryFn: () => api<{ sessions: HistorySession[] }>(`/trainer/trainees/${userId}/history`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeReport(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'report'],
|
||||
queryFn: () => api<TraineeReport>(`/trainer/trainees/${userId}/report`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeMoves(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'moves'],
|
||||
queryFn: () => api<{ moves: DayMoveEntry[] }>(`/trainer/trainees/${userId}/moves`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
/** Kalendarz podopiecznego (dni aktywnego planu w miesiącu YYYY-MM). */
|
||||
export function useTraineeCalendar(userId: string, month?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'calendar', month],
|
||||
queryFn: () =>
|
||||
api<{ month: string; days: CalendarDay[] }>(
|
||||
`/trainer/trainees/${userId}/calendar${month ? `?month=${month}` : ''}`,
|
||||
),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeSearch(firstName: string, lastName: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainee-search', firstName, lastName],
|
||||
queryFn: () =>
|
||||
api<{ users: UserSearchResult[] }>(
|
||||
`/trainer/search?firstName=${encodeURIComponent(firstName)}&lastName=${encodeURIComponent(lastName)}`,
|
||||
),
|
||||
enabled: firstName.trim().length > 0 && lastName.trim().length > 0,
|
||||
});
|
||||
}
|
||||
|
||||
export function sendInvitation(userId: string) {
|
||||
return api<{ coaching: { id: string } }>('/trainer/invitations', { method: 'POST', body: { userId } });
|
||||
}
|
||||
|
||||
export function archiveTrainee(userId: string) {
|
||||
return api(`/trainer/trainees/${encodeURIComponent(userId)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function useInvitations() {
|
||||
return useQuery({
|
||||
queryKey: ['invitations'],
|
||||
queryFn: () => api<{ invitations: Invitation[] }>('/trainer/invitations'),
|
||||
});
|
||||
}
|
||||
|
||||
export function acceptInvitation(id: string) {
|
||||
return api(`/trainer/invitations/${encodeURIComponent(id)}/accept`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function declineInvitation(id: string) {
|
||||
return api(`/trainer/invitations/${encodeURIComponent(id)}/decline`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function withdrawInvitation(id: string) {
|
||||
return api(`/trainer/invitations/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function useCalendar(month?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['calendar', month],
|
||||
queryFn: () =>
|
||||
api<{ month: string; days: CalendarDay[] }>(
|
||||
`/calendar${month ? `?month=${month}` : ''}`,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- komunikator (messages) ----------
|
||||
export function useConversations() {
|
||||
return useQuery({
|
||||
queryKey: ['conversations'],
|
||||
queryFn: () => api<{ conversations: Conversation[] }>('/messages/conversations'),
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useMessages(coachingId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['messages', coachingId],
|
||||
queryFn: () => api<ConversationThread>(`/messages/conversations/${coachingId}`),
|
||||
enabled: !!coachingId,
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function sendMessage(
|
||||
coachingId: string,
|
||||
body: string,
|
||||
attachment?: { sessionId?: string; sessionExerciseId?: string },
|
||||
) {
|
||||
return api<{ message: Message }>('/messages/conversations/' + coachingId, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
body,
|
||||
...(attachment?.sessionId ? { sessionId: attachment.sessionId } : {}),
|
||||
...(attachment?.sessionExerciseId ? { sessionExerciseId: attachment.sessionExerciseId } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteMessage(id: string) {
|
||||
return api(`/messages/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
// ---------- komentarze pod ćwiczeniami ----------
|
||||
export function addTraineeComment(
|
||||
userId: string,
|
||||
data: { body: string; sessionId?: string; sessionExerciseId?: string },
|
||||
) {
|
||||
return api<{ comment: ExerciseComment }>(`/trainer/trainees/${encodeURIComponent(userId)}/comments`, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
});
|
||||
}
|
||||
|
||||
export function addMyComment(data: { body: string; sessionId: string; sessionExerciseId?: string }) {
|
||||
return api<{ comment: ExerciseComment }>('/me/comments', { method: 'POST', body: data });
|
||||
}
|
||||
|
||||
/** Usuwa komentarz: scope 'me' → /me/comments/:id, { userId } → /trainer/trainees/:userId/comments/:id. */
|
||||
export function deleteComment(commentId: string, scope: 'me' | { userId: string }) {
|
||||
const path =
|
||||
scope === 'me'
|
||||
? `/me/comments/${encodeURIComponent(commentId)}`
|
||||
: `/trainer/trainees/${encodeURIComponent(scope.userId)}/comments/${encodeURIComponent(commentId)}`;
|
||||
return api(path, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
// ---------- postępy per ćwiczenie ----------
|
||||
export function useExerciseProgress() {
|
||||
return useQuery({
|
||||
queryKey: ['me', 'exercise-progress'],
|
||||
queryFn: () => api<{ exercises: ExerciseProgress[] }>('/me/exercise-progress'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeExerciseProgress(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'exercise-progress'],
|
||||
queryFn: () => api<{ exercises: ExerciseProgress[] }>(`/trainer/trainees/${userId}/exercise-progress`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineeLatestResults(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'exercise-latest'],
|
||||
queryFn: () => api<{ results: LatestExerciseResult[] }>(`/trainer/trainees/${userId}/exercise-latest`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- plany podopiecznego (trener) ----------
|
||||
export function useTraineePlans(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'plans'],
|
||||
queryFn: () => api<{ plans: Plan[] }>(`/trainer/trainees/${userId}/plans`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTraineePlan(userId: string, planId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'plans', planId],
|
||||
queryFn: () => api<{ plan: Plan }>(`/trainer/trainees/${userId}/plans/${planId}`),
|
||||
enabled: !!userId && !!planId,
|
||||
});
|
||||
}
|
||||
|
||||
export function createTraineePlan(
|
||||
userId: string,
|
||||
body: {
|
||||
title: string;
|
||||
weeksCount: number;
|
||||
weeks: PlanWeekInput[];
|
||||
/** Opcjonalna data startu (poniedziałek) — plan tworzony i aktywowany w jednym kroku. */
|
||||
startDate?: string;
|
||||
},
|
||||
) {
|
||||
return api<{ plan: { id: string } }>(`/trainer/trainees/${userId}/plans`, { method: 'POST', body });
|
||||
}
|
||||
|
||||
export function updateTraineePlan(userId: string, planId: string, body: { title: string; weeksCount: number; weeks: PlanWeekInput[] }) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}`, { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
export function deleteTraineePlan(userId: string, planId: string) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function activateTraineePlan(userId: string, planId: string, startDate: string) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}/activate`, { method: 'POST', body: { startDate } });
|
||||
}
|
||||
|
||||
export function abandonTraineePlan(userId: string, planId: string) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}/abandon`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function completeTraineePlan(userId: string, planId: string) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}/complete`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function invalidateAll() {
|
||||
return useQueryClient().invalidateQueries();
|
||||
}
|
||||
541
app/src/api/types.ts
Normal file
541
app/src/api/types.ts
Normal file
@@ -0,0 +1,541 @@
|
||||
export interface DayAvailability {
|
||||
start: string;
|
||||
end: string;
|
||||
}
|
||||
|
||||
export type Availability = Array<DayAvailability | null>;
|
||||
|
||||
export type SocialMediaPlatform = 'INSTAGRAM' | 'TIKTOK' | 'YOUTUBE' | 'FACEBOOK' | 'X' | 'OTHER';
|
||||
|
||||
export interface SocialMediaEntry {
|
||||
platform: SocialMediaPlatform;
|
||||
url: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
nickname: string | null;
|
||||
socialMedia: SocialMediaEntry[] | null;
|
||||
age: number | null;
|
||||
heightCm: number | null;
|
||||
phone: string | null;
|
||||
isAdmin: boolean;
|
||||
availability: Availability | null;
|
||||
priorities: string | null;
|
||||
exclusions: string | null;
|
||||
developMuscles: string[];
|
||||
canDoMuscles: string[];
|
||||
difficultMuscles: string[];
|
||||
avoidMuscles: string[];
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface FocusArea {
|
||||
id: string;
|
||||
name: string;
|
||||
muscle: string;
|
||||
description: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface FocusChainEntry {
|
||||
muscle: string;
|
||||
name: string;
|
||||
exercises: { id: string; name: string }[];
|
||||
}
|
||||
|
||||
export interface FocusChain {
|
||||
develop: FocusChainEntry[];
|
||||
canDo: FocusChainEntry[];
|
||||
difficult: FocusChainEntry[];
|
||||
avoid: FocusChainEntry[];
|
||||
}
|
||||
|
||||
export type EquipmentKind =
|
||||
| 'DUMBBELL'
|
||||
| 'KETTLEBELL'
|
||||
| 'BARBELL'
|
||||
| 'CABLE'
|
||||
| 'MACHINE'
|
||||
| 'BENCH'
|
||||
| 'CARDIO'
|
||||
| 'BODYWEIGHT'
|
||||
| 'OTHER';
|
||||
|
||||
/** Type-specific spec payload: DUMBBELL/KETTLEBELL/CABLE/MACHINE → { minKg, maxKg }, BARBELL/BENCH → { maxLoadKg }, CARDIO → { maxSpeedKmh?, maxInclinePct? }. */
|
||||
export interface EquipmentSpec {
|
||||
minKg?: number;
|
||||
maxKg?: number;
|
||||
maxLoadKg?: number;
|
||||
maxSpeedKmh?: number;
|
||||
maxInclinePct?: number;
|
||||
}
|
||||
|
||||
export interface Equipment {
|
||||
id: string;
|
||||
name: string;
|
||||
kind: EquipmentKind;
|
||||
spec: EquipmentSpec | null;
|
||||
description: string | null;
|
||||
}
|
||||
|
||||
/** A gym's equipment instance: how many units of a catalog item the gym has. */
|
||||
export interface GymEquipment {
|
||||
id: string;
|
||||
gymId: string;
|
||||
equipmentId: string;
|
||||
quantity: number;
|
||||
equipment: Equipment;
|
||||
}
|
||||
|
||||
export type GymKind = 'VIRTUAL' | 'REAL';
|
||||
|
||||
/** Zdjęcie w galerii siłowni REAL. `url` = ścieżka względna API (dopełnij `API_BASE`). */
|
||||
export interface GymPhoto {
|
||||
id: string;
|
||||
url: string;
|
||||
order: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Gym {
|
||||
id: string;
|
||||
name: string;
|
||||
location: string | null;
|
||||
availability: Availability | null;
|
||||
capacity: number | null;
|
||||
kind: GymKind;
|
||||
isPrivate: boolean;
|
||||
equipment: GymEquipment[];
|
||||
/** Okładka galerii (pierwsze zdjęcie) — tylko siłownie REAL; null = brak zdjęć. */
|
||||
coverPhoto: string | null;
|
||||
}
|
||||
|
||||
/** Odpowiedź detalu siłowni (GET /gyms/:id): siłownia + galeria + role zalogowanego. */
|
||||
export interface GymDetailResponse {
|
||||
gym: Gym & { photos: GymPhoto[] };
|
||||
roles: GymRole[];
|
||||
isAdmin: boolean;
|
||||
}
|
||||
|
||||
/** Wpis listy wirtualnych siłowni: publiczne (z ocenami) + własne prywatne (bez ocen). */
|
||||
export interface VirtualGym {
|
||||
id: string;
|
||||
name: string;
|
||||
location: string | null;
|
||||
availability: Availability | null;
|
||||
capacity: number | null;
|
||||
kind: GymKind;
|
||||
isPrivate: boolean;
|
||||
equipment: GymEquipment[];
|
||||
/** Publiczne: liczba głosów; prywatne (własne): 0/0. */
|
||||
up: number;
|
||||
down: number;
|
||||
/** Liczba członkostw w tej siłowni. */
|
||||
memberCount?: number;
|
||||
/** Głos zalogowanego usera (publiczne); null = nie głosował. */
|
||||
myVote: 'UP' | 'DOWN' | null;
|
||||
/** Status wniosku zalogowanego o weryfikację tej siłowni. */
|
||||
claimStatus: 'PENDING' | 'REJECTED' | null;
|
||||
rejectReason: string | null;
|
||||
}
|
||||
|
||||
export interface GymClaimDocument {
|
||||
id: string;
|
||||
originalName: string;
|
||||
mimeType: string;
|
||||
sizeBytes: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface GymClaim {
|
||||
id: string;
|
||||
/** null = wniosek o NOWĄ realną siłownię. */
|
||||
gymId: string | null;
|
||||
type: 'verification' | 'new';
|
||||
gym: { id: string; name: string; kind: GymKind; isPrivate: boolean } | null;
|
||||
gymName: string | null;
|
||||
gymLocation: string | null;
|
||||
gymAvailability: Availability | null;
|
||||
gymCapacity: number | null;
|
||||
description: string;
|
||||
companyName: string | null;
|
||||
nip: string | null;
|
||||
phone: string | null;
|
||||
email: string | null;
|
||||
address: string | null;
|
||||
status: 'PENDING' | 'APPROVED' | 'REJECTED';
|
||||
rejectReason: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
documents: GymClaimDocument[];
|
||||
}
|
||||
|
||||
/** Zaproszenie do prywatnej wirtualnej siłowni (wysłane lub otrzymane). */
|
||||
export interface GymInvitation {
|
||||
id: string;
|
||||
direction: 'sent' | 'received';
|
||||
gym: { id: string; name: string; location: string | null; kind: GymKind; isPrivate: boolean };
|
||||
/** Kto został zaproszony (tylko direction = 'sent'). */
|
||||
user: { id: string; firstName: string | null; lastName: string | null; email: string } | null;
|
||||
/** Kto zaprosił (tylko direction = 'received'). */
|
||||
invitedBy: { id: string; firstName: string | null; lastName: string | null; email: string } | null;
|
||||
invitedAt: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
export type GymRole = 'OWNER' | 'TRAINER' | 'MEMBER';
|
||||
|
||||
export interface GymMembership {
|
||||
gymId: string;
|
||||
roles: GymRole[];
|
||||
gym: Gym;
|
||||
}
|
||||
|
||||
/** One-off gym schedule override (null availability = closed). */
|
||||
export interface GymException {
|
||||
id: string;
|
||||
gymId: string;
|
||||
date: string;
|
||||
availability: DayAvailability | null;
|
||||
}
|
||||
|
||||
export interface Exercise {
|
||||
id: string;
|
||||
slug: string;
|
||||
name: string;
|
||||
primaryMuscle: string;
|
||||
secondaryMuscles: string[];
|
||||
equipment: Equipment[];
|
||||
hasReps: boolean;
|
||||
hasLoad: boolean;
|
||||
hasRest: boolean;
|
||||
hasSets: boolean;
|
||||
hasRir: boolean;
|
||||
hasDifficulty: boolean;
|
||||
hasCardio: boolean;
|
||||
hasTime: boolean;
|
||||
hasSpeed: boolean;
|
||||
description: string | null;
|
||||
howTo: string | null;
|
||||
commonMistakes: string | null;
|
||||
difficulty: number;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface PlanSet {
|
||||
id: string;
|
||||
index: number;
|
||||
reps: number | null;
|
||||
loadKg: number | null;
|
||||
restSec: number | null;
|
||||
rir: number | null;
|
||||
difficulty: number | null;
|
||||
cardioBpm: number | null;
|
||||
timeSec: number | null;
|
||||
speed: number | null;
|
||||
}
|
||||
|
||||
export interface PlanExercise {
|
||||
id: string;
|
||||
exerciseId: string;
|
||||
order: number;
|
||||
exercise: Exercise;
|
||||
sets: PlanSet[];
|
||||
}
|
||||
|
||||
export interface PlanDay {
|
||||
id: string;
|
||||
dayOfWeek: number;
|
||||
date: string | null;
|
||||
status: 'PLANNED' | 'COMPLETED' | 'SKIPPED';
|
||||
exercises: PlanExercise[];
|
||||
moveLog: { id: string; fromDate: string; toDate: string; reason: string | null }[];
|
||||
sessions: { id: string; status: string; startedAt: string }[];
|
||||
}
|
||||
|
||||
export interface PlanWeek {
|
||||
id: string;
|
||||
index: number;
|
||||
days: PlanDay[];
|
||||
}
|
||||
|
||||
export interface Plan {
|
||||
id: string;
|
||||
title: string;
|
||||
status: 'DRAFT' | 'ACTIVE' | 'COMPLETED' | 'ABANDONED';
|
||||
weeksCount: number;
|
||||
startDate: string | null;
|
||||
/** Kto utworzył plan (trener, gdy plan należy do podopiecznego); null = podopieczny sam. */
|
||||
creator: { id: string; firstName: string | null; lastName: string | null } | null;
|
||||
/** Podsumowanie postępu (lista planów); brak = dane niedostępne. */
|
||||
progress?: { completed: number; total: number; percent: number };
|
||||
weeks: PlanWeek[];
|
||||
}
|
||||
|
||||
export interface SessionSet {
|
||||
id: string;
|
||||
planSetId: string | null;
|
||||
index: number;
|
||||
reps: number | null;
|
||||
rir: number | null;
|
||||
difficulty: number | null;
|
||||
note: string | null;
|
||||
removed: boolean;
|
||||
}
|
||||
|
||||
export interface SessionExercise {
|
||||
id: string;
|
||||
order: number;
|
||||
hidden: boolean;
|
||||
removed: boolean;
|
||||
exercise: Exercise;
|
||||
planExercise: { id: string; sets: PlanSet[] } | null;
|
||||
sets: SessionSet[];
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
id: string;
|
||||
status: 'IN_PROGRESS' | 'COMPLETED' | 'ABANDONED';
|
||||
startedAt: string;
|
||||
day: {
|
||||
id: string;
|
||||
date: string | null;
|
||||
status: string;
|
||||
week: { plan: { id: string; title: string; status: string } };
|
||||
moveLog: { id: string; fromDate: string; toDate: string; reason: string | null }[];
|
||||
};
|
||||
exercises: SessionExercise[];
|
||||
}
|
||||
|
||||
/** Aktywna (IN_PROGRESS) sesja użytkownika — skrót w menu bocznym i na dashboardzie. */
|
||||
export interface ActiveSession {
|
||||
id: string;
|
||||
dayId: string;
|
||||
dayDate: string | null;
|
||||
dayOfWeek: number;
|
||||
planTitle: string;
|
||||
startedAt: string;
|
||||
}
|
||||
|
||||
export interface Dashboard {
|
||||
killstreak: number;
|
||||
nextTraining: { dayId: string; date: string; exercises: { name: string; muscle: string }[] } | null;
|
||||
progress: { completed: number; total: number; percent: number } | null;
|
||||
/** Serie wykonane ponad plan (planSetId = null) w ukończonych sesjach aktywnego planu. */
|
||||
extra: { sets: number } | null;
|
||||
/** Niewykonane serie z planu (reps = null) w ukończonych sesjach aktywnego planu. */
|
||||
missing: { sets: number } | null;
|
||||
activePlan: { id: string; title: string; startDate: string } | null;
|
||||
}
|
||||
|
||||
export interface CalendarDay {
|
||||
id: string;
|
||||
date: string;
|
||||
status: 'PLANNED' | 'COMPLETED' | 'SKIPPED';
|
||||
dayOfWeek: number;
|
||||
exercises: { name: string; muscle: string }[];
|
||||
}
|
||||
|
||||
export interface WeightPoint {
|
||||
id: string;
|
||||
value: number;
|
||||
date: string;
|
||||
}
|
||||
|
||||
export interface HistorySet {
|
||||
index: number;
|
||||
reps: number | null;
|
||||
rir: number | null;
|
||||
difficulty: number | null;
|
||||
planned: { reps: number | null; loadKg: number | null; restSec: number | null; rir: number | null } | null;
|
||||
}
|
||||
|
||||
export interface ExerciseComment {
|
||||
id: string;
|
||||
authorId: string;
|
||||
authorName: string;
|
||||
body: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface HistoryExercise {
|
||||
/** Id `SessionExercise` — kotwica komentarzy i załączników. */
|
||||
id: string;
|
||||
name: string;
|
||||
muscle: string;
|
||||
/** true = ćwiczenie dodane do sesji ponad plan (brak planExerciseId). */
|
||||
isExtra: boolean;
|
||||
comments: ExerciseComment[];
|
||||
sets: HistorySet[];
|
||||
}
|
||||
|
||||
export interface HistorySession {
|
||||
id: string;
|
||||
status: 'IN_PROGRESS' | 'COMPLETED' | 'ABANDONED';
|
||||
startedAt: string;
|
||||
endedAt: string | null;
|
||||
date: string | null;
|
||||
dayOfWeek: number;
|
||||
plan: string;
|
||||
/** Serie normowe (zaplanowane): wykonane / wszystkie. */
|
||||
norm: { done: number; total: number };
|
||||
/** Serie bonusowe (dodane ponad plan) z zapisanymi wynikami. */
|
||||
bonus: number;
|
||||
/** Niewyrobione serie normowe (deficyt). */
|
||||
deficit: number;
|
||||
exercises: HistoryExercise[];
|
||||
}
|
||||
|
||||
export interface CircumferenceSeries {
|
||||
name: string;
|
||||
points: WeightPoint[];
|
||||
}
|
||||
|
||||
// ---------- komunikator (messages) ----------
|
||||
export interface Conversation {
|
||||
coachingId: string;
|
||||
other: { id: string; firstName: string | null; lastName: string | null; nickname: string | null };
|
||||
lastMessage: { body: string; createdAt: string; senderId: string } | null;
|
||||
unreadCount: number;
|
||||
}
|
||||
|
||||
/** Załącznik wyniku: ukończona sesja podopiecznego + opcjonalnie konkretne ćwiczenie. */
|
||||
export interface MessageAttachment {
|
||||
sessionId: string;
|
||||
sessionDate: string;
|
||||
plan: string;
|
||||
exercise: {
|
||||
name: string;
|
||||
sets: {
|
||||
index: number;
|
||||
reps: number | null;
|
||||
rir: number | null;
|
||||
planned: { reps: number | null; loadKg: number | null; restSec: number | null; rir: number | null } | null;
|
||||
}[];
|
||||
} | null;
|
||||
/** Tylko gdy exercise == null. */
|
||||
exercises: { name: string; setsDone: number; setsTotal: number }[];
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
id: string;
|
||||
senderId: string;
|
||||
body: string;
|
||||
createdAt: string;
|
||||
attachment: MessageAttachment | null;
|
||||
}
|
||||
|
||||
export interface ConversationThread {
|
||||
/** Rola zalogowanego w tej relacji. */
|
||||
role: 'trainer' | 'trainee';
|
||||
other: { id: string; firstName: string | null; lastName: string | null; nickname: string | null };
|
||||
messages: Message[];
|
||||
}
|
||||
|
||||
// ---------- postępy per ćwiczenie ----------
|
||||
export interface ExerciseProgressPoint {
|
||||
date: string;
|
||||
oneRm: number | null;
|
||||
volumeKg: number | null;
|
||||
reps: number;
|
||||
sets: number;
|
||||
}
|
||||
|
||||
export interface ExerciseProgress {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
muscle: string;
|
||||
/** Rosnąco, 1 punkt per ukończona sesja. */
|
||||
points: ExerciseProgressPoint[];
|
||||
}
|
||||
|
||||
/** Ostatnia ukończona sesja per ćwiczenie — serie do prefylu planu + 1RM Epley. */
|
||||
export interface LatestExerciseResult {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
muscle: string;
|
||||
date: string;
|
||||
sets: { reps: number | null; loadKg: number | null }[];
|
||||
oneRm: number | null;
|
||||
}
|
||||
|
||||
// ---------- trainer / trainees ----------
|
||||
export type TraineeFlag = 'streak_reset' | 'no_session_7d' | 'high_deficit';
|
||||
|
||||
export interface UserSearchResult {
|
||||
id: string;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
nickname: string | null;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
gyms: { id: string; name: string }[];
|
||||
}
|
||||
|
||||
export interface Trainee {
|
||||
user: { id: string; firstName: string | null; lastName: string | null; nickname: string | null };
|
||||
gyms: { id: string; name: string }[];
|
||||
activePlan: { id: string; title: string; progress: { completed: number; total: number; percent: number } } | null;
|
||||
killstreak: number;
|
||||
lastSessionAt: string | null;
|
||||
flags: TraineeFlag[];
|
||||
}
|
||||
|
||||
export interface TraineeDetail {
|
||||
user: { id: string; firstName: string | null; lastName: string | null; nickname: string | null };
|
||||
socialMedia: SocialMediaEntry[] | null;
|
||||
gyms: { id: string; name: string }[];
|
||||
activePlan: { id: string; title: string; startDate: string } | null;
|
||||
progress: { completed: number; total: number; percent: number } | null;
|
||||
killstreak: number;
|
||||
nextTraining: { dayId: string; date: string; exercises: { name: string; muscle: string }[] } | null;
|
||||
extra: { sets: number } | null;
|
||||
missing: { sets: number } | null;
|
||||
lastSessionAt: string | null;
|
||||
flags: TraineeFlag[];
|
||||
}
|
||||
|
||||
export interface MuscleReport {
|
||||
muscle: string;
|
||||
planned: { sets: number; reps: number };
|
||||
actual: { sets: number; reps: number };
|
||||
extra: { sets: number };
|
||||
missing: { sets: number };
|
||||
completionPct: number;
|
||||
/** Weekly range scaled to the plan duration; null when the muscle has no range. */
|
||||
recommendedRange: { setsMin: number; setsMax: number } | null;
|
||||
outOfRange: boolean;
|
||||
}
|
||||
|
||||
export interface TraineeReport {
|
||||
plan: { id: string; title: string; startDate: string | null } | null;
|
||||
muscles: MuscleReport[];
|
||||
days: { date: string; status: 'PLANNED' | 'COMPLETED' | 'SKIPPED'; moved: boolean }[];
|
||||
}
|
||||
|
||||
export interface DayMoveEntry {
|
||||
dayId: string;
|
||||
date: string | null;
|
||||
fromDate: string;
|
||||
toDate: string;
|
||||
reason: string | null;
|
||||
movedAt: string;
|
||||
}
|
||||
|
||||
export interface Invitation {
|
||||
id: string;
|
||||
direction: 'sent' | 'received';
|
||||
other: { id: string; firstName: string | null; lastName: string | null; nickname: string | null; email: string; phone: string | null } | null;
|
||||
invitedAt: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
export interface ApiErrorBody {
|
||||
error: { code: string; message: string; details?: unknown };
|
||||
}
|
||||
Reference in New Issue
Block a user