2026-01-03 14:07:04 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000';
|
|
|
|
|
|
|
|
|
|
const api = axios.create({
|
|
|
|
|
baseURL: API_URL,
|
|
|
|
|
withCredentials: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Auth endpoints
|
|
|
|
|
export const authApi = {
|
|
|
|
|
createAnonymous: (name) => api.post('/auth/anonymous', { name }),
|
|
|
|
|
register: (email, password, name) => api.post('/auth/register', { email, password, name }),
|
|
|
|
|
login: (email, password) => api.post('/auth/login', { email, password }),
|
2026-01-10 22:17:30 +00:00
|
|
|
updateName: (token, name) =>
|
|
|
|
|
api.patch('/auth/user', { name }, {
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` }
|
|
|
|
|
}),
|
2026-01-03 14:07:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Rooms endpoints
|
|
|
|
|
export const roomsApi = {
|
2026-01-09 21:36:49 +00:00
|
|
|
create: (hostId, questionPackId, settings, hostName) =>
|
|
|
|
|
api.post('/rooms', { hostId, questionPackId, settings, hostName }),
|
2026-01-10 00:18:08 +00:00
|
|
|
getByCode: (code, password, userId) => {
|
|
|
|
|
const params = {};
|
|
|
|
|
if (password) params.password = password;
|
|
|
|
|
if (userId) params.userId = userId;
|
|
|
|
|
return api.get(`/rooms/${code}`, { params });
|
|
|
|
|
},
|
2026-01-03 14:07:04 +00:00
|
|
|
join: (roomId, userId, name, role) =>
|
|
|
|
|
api.post(`/rooms/${roomId}/join`, { userId, name, role }),
|
2026-01-06 20:27:50 +00:00
|
|
|
updateQuestionPack: (roomId, questionPackId) =>
|
|
|
|
|
api.patch(`/rooms/${roomId}/question-pack`, { questionPackId }),
|
2026-01-08 17:56:00 +00:00
|
|
|
updateRoomPack: (roomId, questions) =>
|
|
|
|
|
api.patch(`/rooms/${roomId}/room-pack`, { questions }),
|
|
|
|
|
getRoomPack: (roomId) =>
|
|
|
|
|
api.get(`/rooms/${roomId}/room-pack`),
|
2026-01-03 14:07:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Questions endpoints
|
|
|
|
|
export const questionsApi = {
|
|
|
|
|
createPack: (data) => api.post('/questions/packs', data),
|
|
|
|
|
getPacks: (userId) => api.get('/questions/packs', { params: { userId } }),
|
|
|
|
|
getPack: (id) => api.get(`/questions/packs/${id}`),
|
|
|
|
|
updatePack: (id, data) => api.put(`/questions/packs/${id}`, data),
|
|
|
|
|
deletePack: (id) => api.delete(`/questions/packs/${id}`),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Stats endpoints
|
|
|
|
|
export const statsApi = {
|
|
|
|
|
createHistory: (data) => api.post('/stats/game-history', data),
|
|
|
|
|
getHistory: (userId) => api.get(`/stats/game-history/${userId}`),
|
|
|
|
|
getUserStats: (userId) => api.get(`/stats/user/${userId}`),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default api;
|