|
| 1 | +import axiosInstance from './axiosInstance'; |
| 2 | + |
| 3 | +// Search for users with various filters |
| 4 | +export const searchUsers = async (params) => { |
| 5 | + try { |
| 6 | + // Log the params being sent to the API |
| 7 | + console.log('Sending search params to API:', params); |
| 8 | + |
| 9 | + // Make sure we're using the correct endpoint |
| 10 | + const response = await axiosInstance.get('/search/users', { |
| 11 | + params, |
| 12 | + // Add timeout to prevent long-hanging requests |
| 13 | + timeout: 10000 |
| 14 | + }); |
| 15 | + |
| 16 | + // Log the response for debugging |
| 17 | + console.log('Search API response:', response.data); |
| 18 | + |
| 19 | + return response.data; |
| 20 | + } catch (error) { |
| 21 | + console.error('Error searching users:', error.response || error); |
| 22 | + // Return a structured error object instead of throwing |
| 23 | + return { |
| 24 | + success: false, |
| 25 | + message: error.response?.data?.message || 'Error searching users', |
| 26 | + error: error.message |
| 27 | + }; |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +// Search for jobs with various filters |
| 32 | +export const searchJobs = async (params) => { |
| 33 | + try { |
| 34 | + // Create a copy of params to avoid modifying the original |
| 35 | + const searchParams = { ...params }; |
| 36 | + |
| 37 | + // Fix the query format for Solr |
| 38 | + // If query is "*:*", leave it as is, otherwise format it properly |
| 39 | + if (searchParams.query && searchParams.query !== "*:*") { |
| 40 | + // Remove special characters that might cause parsing issues |
| 41 | + const sanitizedQuery = searchParams.query.replace(/:/g, " "); |
| 42 | + searchParams.query = sanitizedQuery; |
| 43 | + } |
| 44 | + |
| 45 | + // Log the params being sent to the API for debugging |
| 46 | + console.log('Sending job search params to API:', searchParams); |
| 47 | + |
| 48 | + const response = await axiosInstance.get('/search/jobs', { |
| 49 | + params: searchParams, |
| 50 | + timeout: 10000 // Add timeout to prevent long-hanging requests |
| 51 | + }); |
| 52 | + |
| 53 | + console.log('Search jobs API response:', response.data); |
| 54 | + |
| 55 | + return { |
| 56 | + success: true, |
| 57 | + jobs: response.data.jobs || [], |
| 58 | + total: response.data.total || 0, |
| 59 | + ...response.data |
| 60 | + }; |
| 61 | + } catch (error) { |
| 62 | + console.error('Error searching jobs:', error.response || error); |
| 63 | + return { |
| 64 | + success: false, |
| 65 | + message: error.response?.data?.message || 'Error searching jobs', |
| 66 | + error: error.message, |
| 67 | + jobs: [] |
| 68 | + }; |
| 69 | + } |
| 70 | +}; |
| 71 | + |
| 72 | + |
0 commit comments