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';
|
import { prisma } from '../prisma.js';
|
||||||
|
|
||||||
const minimumVoiceExperienceSeconds = 30;
|
const minimumVoiceExperienceSeconds = 30;
|
||||||
|
const forbiddenGeneratedPlaceIdPrefix = 'manual-';
|
||||||
|
|
||||||
export type CreateVoiceExperienceInput = {
|
export type CreateVoiceExperienceInput = {
|
||||||
googlePlaceId: string;
|
googlePlaceId: string;
|
||||||
@@ -19,17 +20,28 @@ export async function createVoiceExperience(
|
|||||||
if (input.durationSeconds < minimumVoiceExperienceSeconds) {
|
if (input.durationSeconds < minimumVoiceExperienceSeconds) {
|
||||||
throw new Error('Voice experience must be at least 30 seconds.');
|
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({
|
const place = await prisma.place.upsert({
|
||||||
where: { googlePlaceId: input.googlePlaceId },
|
where: { googlePlaceId },
|
||||||
create: {
|
create: {
|
||||||
googlePlaceId: input.googlePlaceId,
|
googlePlaceId,
|
||||||
name: input.googleName,
|
name: googleName,
|
||||||
latitude: input.latitude,
|
latitude: input.latitude,
|
||||||
longitude: input.longitude,
|
longitude: input.longitude,
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
name: input.googleName,
|
name: googleName,
|
||||||
latitude: input.latitude,
|
latitude: input.latitude,
|
||||||
longitude: input.longitude,
|
longitude: input.longitude,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user