Skip to content

Commit

Permalink
feat(be): closest station metro only filter
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Sep 22, 2024
1 parent b93137b commit 6c42554
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend-nest/src/modules/stop/stop.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class StopController implements OnModuleInit {
longitudeQuery: unknown,
@Query("count")
countQuery: unknown,
@Query("metroOnly")
metroOnlyQuery: unknown,
): Promise<StopWithDistanceSchema[]> {
const schema = z.object({
latitude: z.coerce.number(),
Expand All @@ -68,6 +70,7 @@ export class StopController implements OnModuleInit {
latitude,
longitude,
count,
metroOnly: Boolean(metroOnlyQuery),
});

return stopWithDistanceSchema.array().parse(stops);
Expand Down
3 changes: 3 additions & 0 deletions backend-nest/src/modules/stop/stop.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export class StopService {
latitude,
longitude,
count,
metroOnly,
}: {
latitude: number;
longitude: number;
count: number;
metroOnly: boolean;
}): Promise<StopWithDistanceSchema[]> {
const res = await this.prisma.$transaction(async (transaction) => {
const stopsWithDistance = await this.prisma.$queryRaw<
Expand All @@ -56,6 +58,7 @@ export class StopService {
ll_to_earth(${latitude}, ${longitude})
) AS "distance"
FROM "Stop"
${metroOnly ? Prisma.sql`WHERE "Stop"."isMetro" = true` : Prisma.empty}
ORDER BY "distance"
LIMIT ${count}
`;
Expand Down

0 comments on commit 6c42554

Please sign in to comment.