diff --git a/src/graphql/voice-experiences.ts b/src/graphql/voice-experiences.ts index d5608ba..3552168 100644 --- a/src/graphql/voice-experiences.ts +++ b/src/graphql/voice-experiences.ts @@ -2,6 +2,7 @@ import { enqueueVoiceExperience } from '../hatchet/enqueue-voice-experience.js'; import { prisma } from '../prisma.js'; const minimumVoiceExperienceSeconds = 30; +const forbiddenGeneratedPlaceIdPrefix = 'manual-'; export type CreateVoiceExperienceInput = { googlePlaceId: string; @@ -19,17 +20,28 @@ export async function createVoiceExperience( if (input.durationSeconds < minimumVoiceExperienceSeconds) { throw new Error('Voice experience must be at least 30 seconds.'); } + const googlePlaceId = input.googlePlaceId.trim(); + const googleName = input.googleName.trim(); + if (googlePlaceId === '') { + throw new Error('Google place id is required.'); + } + if (googlePlaceId.startsWith(forbiddenGeneratedPlaceIdPrefix)) { + throw new Error('Voice experience must be linked to a Google place.'); + } + if (googleName === '') { + throw new Error('Google place name is required.'); + } const place = await prisma.place.upsert({ - where: { googlePlaceId: input.googlePlaceId }, + where: { googlePlaceId }, create: { - googlePlaceId: input.googlePlaceId, - name: input.googleName, + googlePlaceId, + name: googleName, latitude: input.latitude, longitude: input.longitude, }, update: { - name: input.googleName, + name: googleName, latitude: input.latitude, longitude: input.longitude, },