diff --git a/functions/src/index.ts b/functions/src/index.ts index 67c4ab5..eb4913a 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -569,3 +569,44 @@ export const getPlacesAutocomplete = onRequest({ } }); }); + +export const getPlaceDetails = onRequest({ + region: '#{SERVICES_RGN}#' +}, async (request: Request, response: express.Response) => { + return corsHandler(request, response, async () => { + try { + const { place_id, fields } = request.query; + + if (!place_id) { + response.status(400).json({ + error: 'place_id parameter is required' + }); + return; + } + + const apiKey = process.env.GOOGLE_MAPS_API_KEY; + if (!apiKey) { + logger.error('Google Places API key is not configured'); + response.status(500).json({ error: 'Server configuration error' }); + return; + } + + const url = 'https://maps.googleapis.com/maps/api/place/details/json'; + const params: any = { + key: apiKey, + place_id: place_id, + fields: fields || 'geometry' + }; + + const result = await axios.get(url, { params }); + logger.info('Google Places Details API request completed successfully'); + response.json(result.data); + } catch (error) { + logger.error('Error fetching place details:', error); + response.status(500).json({ + success: false, + error: error instanceof Error ? error.message : String(error) + }); + } + }); +});