style: run prettier
All checks were successful
TrafficCue Server CI / check (push) Successful in 37s
TrafficCue Server CD / build (push) Successful in 1m34s

This commit is contained in:
2025-09-19 21:54:48 +02:00
parent 03c2e8995b
commit a2f30118ef
2 changed files with 30 additions and 18 deletions

View File

@ -1,4 +1,10 @@
import { BaseEntity, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; import {
BaseEntity,
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import type { User } from "./User"; import type { User } from "./User";
@Entity() @Entity()
@ -7,12 +13,12 @@ export class Hazard extends BaseEntity {
id: string; id: string;
@Column({ @Column({
type: "float" type: "float",
}) })
latitude: number; latitude: number;
@Column({ @Column({
type: "float" type: "float",
}) })
longitude: number; longitude: number;

View File

@ -166,15 +166,16 @@ if (process.env.REVIEWS_ENABLED) {
}); });
} }
const VALID_HAZARD_TYPES = [ const VALID_HAZARD_TYPES = ["bumpy-road"];
"bumpy-road"
];
if (process.env.HAZARDS_ENABLED) { if (process.env.HAZARDS_ENABLED) {
app.get("/api/hazards", async (c) => { app.get("/api/hazards", async (c) => {
const { lat, lon, radius } = c.req.query(); const { lat, lon, radius } = c.req.query();
if (!lat || !lon || !radius) { if (!lat || !lon || !radius) {
return c.json({ error: "Latitude, longitude, and radius are required" }, 400); return c.json(
{ error: "Latitude, longitude, and radius are required" },
400,
);
} }
// Remove unnecessary precision from lat/lon // Remove unnecessary precision from lat/lon
const nlat = Number(parseFloat(lat).toFixed(4)); const nlat = Number(parseFloat(lat).toFixed(4));
@ -186,10 +187,18 @@ if (process.env.HAZARDS_ENABLED) {
if (nradius > 1000) { if (nradius > 1000) {
return c.json({ error: "Radius too large, max is 1000 km" }, 400); return c.json({ error: "Radius too large, max is 1000 km" }, 400);
} }
console.log(`Fetching hazards for lat: ${lat}, lon: ${lon}, radius: ${radius} km`); console.log(
`Fetching hazards for lat: ${lat}, lon: ${lon}, radius: ${radius} km`,
);
const hazards = await Hazard.createQueryBuilder("hazard") // Crazy math to get a rough bounding box for the radius in km const hazards = await Hazard.createQueryBuilder("hazard") // Crazy math to get a rough bounding box for the radius in km
.where("hazard.latitude BETWEEN :minLat AND :maxLat", { minLat: nlat - nradius / 110.574, maxLat: nlat + nradius / 110.574 }) .where("hazard.latitude BETWEEN :minLat AND :maxLat", {
.andWhere("hazard.longitude BETWEEN :minLon AND :maxLon", { minLon: nlon - nradius / (111.320 * Math.cos(nlat * (Math.PI / 180))), maxLon: nlon + nradius / (111.320 * Math.cos(nlat * (Math.PI / 180))) }) minLat: nlat - nradius / 110.574,
maxLat: nlat + nradius / 110.574,
})
.andWhere("hazard.longitude BETWEEN :minLon AND :maxLon", {
minLon: nlon - nradius / (111.32 * Math.cos(nlat * (Math.PI / 180))),
maxLon: nlon + nradius / (111.32 * Math.cos(nlat * (Math.PI / 180))),
})
.getMany(); .getMany();
return c.json(hazards); return c.json(hazards);
}); });
@ -203,10 +212,7 @@ if (process.env.HAZARDS_ENABLED) {
); );
} }
if (!VALID_HAZARD_TYPES.includes(type)) { if (!VALID_HAZARD_TYPES.includes(type)) {
return c.json( return c.json({ error: "Invalid hazard type" }, 400);
{ error: "Invalid hazard type" },
400,
);
} }
const authHeader = c.req.header("Authorization"); const authHeader = c.req.header("Authorization");