refactoring
This commit is contained in:
37
src/services/locationService.js
Normal file
37
src/services/locationService.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import db from "../config/database.js";
|
||||
|
||||
class LocationService {
|
||||
static async getCountries() {
|
||||
return await db.allAsync('SELECT DISTINCT country FROM locations ORDER BY country');
|
||||
}
|
||||
|
||||
static async getCitiesByCountry(country) {
|
||||
return await db.allAsync(
|
||||
'SELECT DISTINCT city FROM locations WHERE country = ? ORDER BY city',
|
||||
[country]
|
||||
);
|
||||
}
|
||||
|
||||
static async getDistrictsByCountryAndCity(country, city) {
|
||||
return await db.allAsync(
|
||||
'SELECT district FROM locations WHERE country = ? AND city = ? ORDER BY district',
|
||||
[country, city]
|
||||
);
|
||||
}
|
||||
|
||||
static async getLocation(country, city, district) {
|
||||
return await db.getAsync(
|
||||
'SELECT id FROM locations WHERE country = ? AND city = ? AND district = ?',
|
||||
[country, city, district]
|
||||
);
|
||||
}
|
||||
|
||||
static async getLocationById(locationId) {
|
||||
return await db.getAsync(
|
||||
'SELECT country, city, district FROM locations WHERE id = ?',
|
||||
[locationId]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default LocationService;
|
||||
Reference in New Issue
Block a user