Skip to content

Commit

Permalink
Fix: raw query 시 위/경도 numeric casting (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokj624 authored Nov 29, 2023
1 parent c8c2645 commit bde52ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/maps/maps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export class MapsService {
lat: number,
long: number,
): Promise<ResponseSmokingAreasData> {
const latitude = lat.toFixed(6);
const longitude = long.toFixed(6);

const areas: ResponseSmokingAreas[] = await this.prisma
.$queryRaw`SELECT id, latitude, longitude FROM ( SELECT id, latitude, longitude, (6371 * acos(cos(radians( ${lat} ) ) * cos(radians(latitude)) * cos(radians(longitude) - radians(${long})) + sin(radians(${lat})) * sin( radians(latitude)))) AS distance FROM "Map" ) DATA WHERE DATA.distance < 2`;
.$queryRaw`SELECT id, latitude, longitude FROM ( SELECT id, latitude, longitude, (6371 * acos(cos(radians( ${latitude}::numeric ) ) * cos(radians(latitude)) * cos(radians(longitude) - radians(${longitude}::numeric)) + sin(radians(${latitude}::numeric)) * sin( radians(latitude)))) AS distance FROM "Map" ) DATA WHERE DATA.distance < 2`;

const data: ResponseSmokingAreasData = {
total: areas.length,
Expand Down

0 comments on commit bde52ac

Please sign in to comment.