Ongoing workout session data is persistent now
This commit is contained in:
@@ -27,6 +27,15 @@ export const api = {
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
put: async (endpoint: string, data: any) => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'PUT',
|
||||
headers: headers(),
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
},
|
||||
delete: async (endpoint: string) => {
|
||||
const res = await fetch(`${API_URL}${endpoint}`, {
|
||||
method: 'DELETE',
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { User, UserRole, UserProfile } from '../types';
|
||||
import { api, setAuthToken, removeAuthToken } from './api';
|
||||
|
||||
export const getUsers = (): any[] => {
|
||||
// Not used in frontend anymore
|
||||
return [];
|
||||
export const getUsers = async (): Promise<{ success: boolean; users?: User[]; error?: string }> => {
|
||||
try {
|
||||
const res = await api.get('/auth/users');
|
||||
return res;
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Failed to fetch users' };
|
||||
}
|
||||
};
|
||||
|
||||
export const login = async (email: string, password: string): Promise<{ success: boolean; user?: User; error?: string }> => {
|
||||
@@ -43,11 +47,21 @@ export const createUser = async (email: string, password: string): Promise<{ suc
|
||||
};
|
||||
|
||||
export const deleteUser = async (userId: string) => {
|
||||
// Admin only, not implemented in frontend UI yet
|
||||
try {
|
||||
const res = await api.delete(`/auth/users/${userId}`);
|
||||
return res;
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Failed to delete user' };
|
||||
}
|
||||
};
|
||||
|
||||
export const toggleBlockUser = (userId: string, block: boolean) => {
|
||||
// Admin only
|
||||
export const toggleBlockUser = async (userId: string, block: boolean) => {
|
||||
try {
|
||||
const res = await api.patch(`/auth/users/${userId}/block`, { block });
|
||||
return res;
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Failed to update user status' };
|
||||
}
|
||||
};
|
||||
|
||||
export const adminResetPassword = (userId: string, newPass: string) => {
|
||||
|
||||
@@ -24,6 +24,37 @@ export const saveSession = async (userId: string, session: WorkoutSession): Prom
|
||||
await api.post('/sessions', session);
|
||||
};
|
||||
|
||||
export const getActiveSession = async (userId: string): Promise<WorkoutSession | null> => {
|
||||
try {
|
||||
const response = await api.get('/sessions/active');
|
||||
if (!response.success || !response.session) {
|
||||
return null;
|
||||
}
|
||||
const session = response.session;
|
||||
// Convert ISO date strings to timestamps
|
||||
return {
|
||||
...session,
|
||||
startTime: new Date(session.startTime).getTime(),
|
||||
endTime: session.endTime ? new Date(session.endTime).getTime() : undefined,
|
||||
sets: session.sets.map((set: any) => ({
|
||||
...set,
|
||||
exerciseName: set.exercise?.name || 'Unknown',
|
||||
type: set.exercise?.type || 'STRENGTH'
|
||||
}))
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateActiveSession = async (userId: string, session: WorkoutSession): Promise<void> => {
|
||||
await api.put('/sessions/active', session);
|
||||
};
|
||||
|
||||
export const deleteActiveSession = async (userId: string): Promise<void> => {
|
||||
await api.delete('/sessions/active');
|
||||
};
|
||||
|
||||
export const deleteSession = async (userId: string, id: string): Promise<void> => {
|
||||
await api.delete(`/sessions/${id}`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user