Reject generated place ids for voice reviews
All checks were successful
Build and deploy Backend / build (push) Successful in 28s
All checks were successful
Build and deploy Backend / build (push) Successful in 28s
This commit is contained in:
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user