-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add venue import from Google Maps #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1f32215
e69189f
3edf055
1405602
cbb1278
d50b8ee
cb0938b
d26c7d5
db06295
d0bee86
efc102c
ff95814
a1ec31d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import { getCountryCode } from '~/utils/country' | ||
| import { getSlug } from '~/utils/slug' | ||
| import { prisma } from '~/server/prisma' | ||
| import fetch from 'node-fetch' | ||
|
|
||
| const addressPart = (result: any, type: string) => { | ||
| if (!result || !result.address_components) { | ||
|
|
@@ -45,7 +44,7 @@ const getAddress = (places: any) => { | |
|
|
||
| const getAddressFromPlaceId = async (placeId: string) => { | ||
| if (!placeId) { | ||
| return {} | ||
| return null | ||
| } | ||
|
|
||
| const apiKey = useRuntimeConfig().public.googleMapsApiKey | ||
|
|
@@ -60,51 +59,63 @@ const getAddressFromPlaceId = async (placeId: string) => { | |
| return getAddress(data.results) | ||
| } | ||
|
|
||
| export async function addCity(city: any) { | ||
| const address = await getAddressFromPlaceId(city.id) | ||
|
|
||
| const existingCity = await prisma.city.findUnique({ | ||
| where: { id: city.id }, | ||
| export async function findOrCreateCity(placeId: string) { | ||
| const existing = await prisma.city.findUnique({ | ||
| where: { id: placeId }, | ||
| }) | ||
| if (existing) return existing | ||
|
|
||
| if (!!existingCity) { | ||
| return existingCity | ||
| } | ||
| const address = await getAddressFromPlaceId(placeId) | ||
|
Comment on lines
+62
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainUpdate call sites to new API (findOrCreateCity). Ensure no stale addCity(...) usages remain (e.g., server/trpc/routers/cities.ts snippet). 🏁 Script executed: #!/bin/bash
# Find legacy addCity call sites and confirm new usage
rg -n '\baddCity\s*\(' -g '!**/dist/**' -g '!**/.nuxt/**' || true
rg -n '\bfindOrCreateCity\s*\(' -g '!**/dist/**' -g '!**/.nuxt/**' || trueLength of output: 297 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Show ripgrep debug to understand why files were skipped previously
rg --debug 'addCity\s*\(' || true
rg --debug 'findOrCreateCity\s*\(' || true
# Search repository for legacy and new API call sites, don't respect .gitignore to avoid skipping files,
# but explicitly exclude common generated directories to reduce noise.
rg -n -C2 --hidden --no-ignore -S --follow -g '!node_modules/**' -g '!**/dist/**' -g '!**/.nuxt/**' '(\baddCity\s*\(|\bfindOrCreateCity\s*\()' || trueLength of output: 13374 Update call sites to the new findOrCreateCity API — remove legacy addCity usages
🤖 Prompt for AI Agents |
||
|
|
||
| const { locality, region, country } = address | ||
| if (!address || !address.locality || !address.country) { | ||
| throw new Error("Couldn't determine city from Google data") | ||
| } | ||
| const { locality, region, country, lat, lng } = address | ||
|
|
||
| let slug = getSlug(locality) | ||
|
|
||
| let existingLocality = await prisma.city.findFirst({ | ||
| const existingLocality = await prisma.city.findFirst({ | ||
| where: { slug }, | ||
| }) | ||
|
|
||
| if (!!existingLocality) { | ||
| slug = getSlug([region, locality].join('-')) | ||
| if (existingLocality) { | ||
| slug = getSlug(`${region} ${locality}`) | ||
| } | ||
|
|
||
| let existingRegion = await prisma.city.findFirst({ | ||
| const existingRegion = await prisma.city.findFirst({ | ||
| where: { slug }, | ||
| }) | ||
|
|
||
| if (!!existingRegion) { | ||
| throw new Error(`city: region-locality slug already exists: ${slug}`) | ||
| if (existingRegion) { | ||
| throw new Error( | ||
| `City slug conflict: A city with slug "${slug}" already exists.` | ||
| ) | ||
| } | ||
|
|
||
| const result = { | ||
| id: city.id, | ||
| const countryCode = await getCountryCode(country) | ||
|
|
||
| const createData = { | ||
| id: placeId, | ||
| name: locality, | ||
| region, | ||
| slug, | ||
| countryCode: await getCountryCode(country), | ||
| description: '', | ||
| lat: address.lat, | ||
| lng: address.lng, | ||
| region: region || '', | ||
| slug: slug, | ||
| countryCode, | ||
| lat: address.lat ?? 0, | ||
| lng: address.lng ?? 0, | ||
| } | ||
| const updateData = { | ||
| name: locality, | ||
| region: region || '', | ||
| countryCode, | ||
| lat: address.lat ?? 0, | ||
| lng: address.lng ?? 0, | ||
| } | ||
|
|
||
| const newCity = await prisma.city.create({ | ||
| data: result, | ||
| }) | ||
|
|
||
| return newCity | ||
| try { | ||
| const city = await prisma.city.upsert({ | ||
| where: { id: placeId }, | ||
| create: createData, | ||
| update: updateData, | ||
| }) | ||
| return city | ||
| } catch (error) { | ||
| throw error | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Schema guardrails: ensure uniqueness.
Double‑check unique indexes for Profile.username and Profile.placeId exist; otherwise the retry logic can’t rely on P2002.
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 26869
Schema guardrails: add a unique constraint for Profile.placeId or stop relying on P2002
prisma/schema.prisma — Profile.username is declared as
String @unique(line ~127); Profile.placeId isString?with no@unique(line ~139). If your retry logic depends on Prisma P2002, add a unique constraint on placeId (field@uniqueor@@unique([placeId])) and run a migration, or change the create/retry flow to handle concurrent duplicates.🤖 Prompt for AI Agents