@@ -3,13 +3,21 @@ import geolib from 'geolib';
33import queryString from 'query-string' ;
44import { createRequire } from 'module' ;
55const require = createRequire ( import . meta. url ) ;
6- const pharmaciesData = require ( '../db/pharmacies.json' ) ;
6+ import fs from 'fs' ;
7+ import path from 'path' ;
8+ import { fileURLToPath } from 'url' ;
9+
10+ const __filename = fileURLToPath ( import . meta. url ) ;
11+ const __dirname = path . dirname ( __filename ) ;
712
813// Kullanıcı konumunu alıp il ve ilçeye göre eczaneleri bulan fonksiyon
914async function findPharmaciesFromDb ( city , district , userLocation ) {
1015 const upperCaseCity = city . toLocaleUpperCase ( 'tr' ) ;
1116 const upperCaseDistrict = district . toLocaleUpperCase ( 'tr' ) ;
1217
18+ // JSON dosyasını her çağrıldığında yeniden oku (doğru path ile)
19+ const pharmaciesData = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../db/pharmacies.json' ) , 'utf-8' ) ) ;
20+
1321 // Eczaneleri il ve ilçe bilgisine göre filtrele
1422 const filteredPharmacies = pharmaciesData . filter ( pharmacy =>
1523 pharmacy . city . toLocaleUpperCase ( 'tr' ) === upperCaseCity &&
@@ -22,7 +30,7 @@ async function findPharmaciesFromDb(city, district, userLocation) {
2230 latitude : parseFloat ( pharmacy . location . lat ) ,
2331 longitude : parseFloat ( pharmacy . location . lon )
2432 } ;
25- console . log ( pharmacyLocation ) ;
33+ // console.log(pharmacyLocation);
2634
2735 const addressQuery = queryString . stringify ( { query : pharmacy . address } ) ;
2836 const googleMapsUrl = `${ process . env . GOOGLE_MAPS_URI } &${ addressQuery } ` ;
0 commit comments