refactor: 提取 buildNavUrl 工具函数,统一 room API 错误处理

- 将 MatchResult.tsx 和 profile/page.tsx 中重复的导航 URL 构建逻辑提取到 src/lib/navigation.ts
- 7 个 room API 路由从 return NextResponse.json({ error }, { status }) 统一改为 throw ApiError,由 apiHandler 统一捕获
This commit is contained in:
2026-02-26 19:31:00 +08:00
parent c9e20d4c95
commit 9641acbcbd
10 changed files with 21 additions and 58 deletions
+9
View File
@@ -0,0 +1,9 @@
import type { Restaurant } from "@/types";
export function buildNavUrl(restaurant: Restaurant): string {
if (restaurant.location) {
const [lng, lat] = restaurant.location.split(",");
return `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(restaurant.name)}&callnative=1`;
}
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(restaurant.name)}`;
}