Skip to content

Commit

Permalink
Fix requête récupération de la ville/département
Browse files Browse the repository at this point in the history
  • Loading branch information
totakoko committed Feb 13, 2025
1 parent 3de849a commit f198ad3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pages/api/location-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ export default handleRouteErrors(async (req: NextApiRequest) => {
.first(),
db('communes')
.select('departement_id', 'temperature_ref_altitude_moyenne')
.where('id', cityCode)
.orWhere('commune', city.toUpperCase())
.orWhere('commune', 'like', `${city.toUpperCase()}-%-ARRONDISSEMENT`)
.where(
'id',
db.raw(
`COALESCE(
(SELECT id FROM communes WHERE id = ?),
(SELECT id FROM communes WHERE commune = ?),
(SELECT id FROM communes WHERE commune LIKE ?)
)`,
[cityCode, city.toUpperCase(), `${city.toUpperCase()}-%-ARRONDISSEMENT`]
)
)
.first(),
]);

Expand Down

0 comments on commit f198ad3

Please sign in to comment.