refactoring

This commit is contained in:
Artyom Ashirov
2024-11-23 05:03:30 +03:00
parent dcc678a42b
commit 5d4f56e265
22 changed files with 1109 additions and 1014 deletions

View 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;