diff options
Diffstat (limited to 'frontend/src/utils')
| -rw-r--r-- | frontend/src/utils/authApi.ts (renamed from frontend/src/utils/api.ts) | 2 | ||||
| -rw-r--r-- | frontend/src/utils/scoreUpload.ts | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/authApi.ts index 528c170..469553d 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/authApi.ts @@ -3,6 +3,7 @@ const API_BASE_URL = import.meta.env.VITE_API_URL; // Auth API functions export const authApi = { async login(credentials: { username: string; password: string }) { + credentials.username = credentials.username.trim(); try { const response = await fetch(`${API_BASE_URL}/authenticate`, { method: 'POST', @@ -31,6 +32,7 @@ export const authApi = { email: string; password: string; }) { + userData.username = userData.username.trim(); try { const response = await fetch(`${API_BASE_URL}/register`, { method: 'POST', diff --git a/frontend/src/utils/scoreUpload.ts b/frontend/src/utils/scoreUpload.ts new file mode 100644 index 0000000..7fa7c86 --- /dev/null +++ b/frontend/src/utils/scoreUpload.ts @@ -0,0 +1,39 @@ +interface UploadScoreData { + meta: { + game: string; + service: string; + playtype: string; + }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + scores: any[]; +} + +interface UploadScoreResponse { + scoreCount: number; + message?: string; +} + +export async function uploadScore(data: UploadScoreData): Promise<UploadScoreResponse> { + const response = await fetch(`${import.meta.env.VITE_API_URL}/uploadScore`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + body: JSON.stringify({ + meta: { + game: data.meta.game, + service: data.meta.service, + playtype: data.meta.playtype + }, + scores: data.scores + }) + }); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.error || 'Failed to upload scores'); + } + + return response.json(); +} |
