From a11194831d59429d0b7bf5afc47c69ebc964fcfd Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 2 Mar 2026 23:49:48 +0100 Subject: [PATCH] logs removed from api.ts --- frontend/src/lib/api.ts | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 621e1b9..a9fb88f 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,8 +1,8 @@ const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api/v1'; // Debug logging -console.log('API_BASE_URL:', API_BASE_URL); -console.log('VITE_API_URL env:', import.meta.env.VITE_API_URL); +// console.log('API_BASE_URL:', API_BASE_URL); +// console.log('VITE_API_URL env:', import.meta.env.VITE_API_URL); // Helper function to get auth headers function getAuthHeaders(): HeadersInit { @@ -10,18 +10,18 @@ function getAuthHeaders(): HeadersInit { const headers: HeadersInit = { 'Content-Type': 'application/json', }; - + if (token) { headers['Authorization'] = `Bearer ${token}`; } - + return headers; } // Enhanced fetch wrapper async function authFetch(url: string, options: RequestInit = {}): Promise { const headers = getAuthHeaders(); - + const response = await fetch(url, { ...options, headers: { @@ -29,14 +29,14 @@ async function authFetch(url: string, options: RequestInit = {}): Promise { - console.log('fetchArticles called with params:', params, 'API_BASE_URL:', API_BASE_URL); + // console.log('fetchArticles called with params:', params, 'API_BASE_URL:', API_BASE_URL); const searchParams = new URLSearchParams(); // Convert parameters to proper types for URLSearchParams @@ -157,17 +157,17 @@ export async function fetchArticles(params: FindArticlesParams = {}): Promise { const searchParams = new URLSearchParams(); - + Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null) { if (typeof value === 'number') { @@ -375,8 +375,8 @@ export async function fetchLiveBlogs(params: FindLiveBlogsParams = {}): Promise< export async function fetchLiveBlogBySlug(slugOrId: string): Promise { const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(slugOrId); - const endpoint = isUuid - ? `${API_BASE_URL}/live-blogs/${slugOrId}` + const endpoint = isUuid + ? `${API_BASE_URL}/live-blogs/${slugOrId}` : `${API_BASE_URL}/live-blogs/slug/${slugOrId}`; const response = await authFetch(endpoint); if (!response.ok) { @@ -550,12 +550,12 @@ export async function login(dto: LoginDto): Promise { }, body: JSON.stringify(dto), }); - + if (!response.ok) { const error = await response.json(); throw new Error(error.message || 'Login failed'); } - + return response.json(); } @@ -567,12 +567,12 @@ export async function register(dto: RegisterDto): Promise { }, body: JSON.stringify(dto), }); - + if (!response.ok) { const error = await response.json(); throw new Error(error.message || 'Registration failed'); } - + return response.json(); } @@ -580,11 +580,11 @@ export async function getProfile(): Promise { const response = await authFetch(`${API_BASE_URL}/users/profile`, { method: 'GET', }); - + if (!response.ok) { throw new Error('Failed to fetch profile'); } - + return response.json(); } @@ -701,14 +701,14 @@ function mapBackendComment(comment: BackendComment): Comment { export async function fetchComments(params: FindCommentsParams = {}): Promise { const searchParams = new URLSearchParams(); - + // Map parentCommentId to parentId for backend compatibility const backendParams = { ...params }; if (backendParams.parentCommentId) { backendParams.parentId = backendParams.parentCommentId; delete backendParams.parentCommentId; } - + Object.entries(backendParams).forEach(([key, value]) => { if (value !== undefined && value !== null) { if (typeof value === 'number') { @@ -723,11 +723,11 @@ export async function fetchComments(params: FindCommentsParams = {}): Promise { liveBlogId: dto.liveBlogId, parentId: dto.parentCommentId, }; - + const response = await authFetch(`${API_BASE_URL}/comments`, { method: 'POST', body: JSON.stringify(backendDto), @@ -750,9 +750,9 @@ export async function createComment(dto: CreateCommentDto): Promise { if (!response.ok) { throw new Error('Failed to create comment'); } - + const comment = await response.json() as BackendComment; - + // Map backend response to frontend interface return mapBackendComment(comment); } @@ -793,7 +793,7 @@ export async function getReactionCounts( commentId?: string ): Promise { const searchParams = new URLSearchParams(); - + if (articleId) searchParams.append('articleId', articleId); if (liveBlogId) searchParams.append('liveBlogId', liveBlogId); if (commentId) searchParams.append('commentId', commentId); @@ -812,7 +812,7 @@ export async function getUserReaction( commentId?: string ): Promise<{ type: string | null }> { const searchParams = new URLSearchParams(); - + if (articleId) searchParams.append('articleId', articleId); if (liveBlogId) searchParams.append('liveBlogId', liveBlogId); if (commentId) searchParams.append('commentId', commentId);