Initial backend service
This commit is contained in:
46
src/graphql/voice-experiences.ts
Normal file
46
src/graphql/voice-experiences.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { enqueueVoiceExperience } from '../hatchet/enqueue-voice-experience.js';
|
||||
import { prisma } from '../prisma.js';
|
||||
|
||||
export type CreateVoiceExperienceInput = {
|
||||
googlePlaceId: string;
|
||||
googleName: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
durationSeconds: number;
|
||||
audioObjectKey: string;
|
||||
};
|
||||
|
||||
export async function createVoiceExperience(input: CreateVoiceExperienceInput) {
|
||||
if (input.durationSeconds < 60) {
|
||||
throw new Error('Voice experience must be at least 60 seconds.');
|
||||
}
|
||||
|
||||
const place = await prisma.place.upsert({
|
||||
where: { googlePlaceId: input.googlePlaceId },
|
||||
create: {
|
||||
googlePlaceId: input.googlePlaceId,
|
||||
name: input.googleName,
|
||||
latitude: input.latitude,
|
||||
longitude: input.longitude,
|
||||
},
|
||||
update: {
|
||||
name: input.googleName,
|
||||
latitude: input.latitude,
|
||||
longitude: input.longitude,
|
||||
},
|
||||
});
|
||||
|
||||
const experience = await prisma.voiceExperience.create({
|
||||
data: {
|
||||
placeId: place.id,
|
||||
durationSeconds: input.durationSeconds,
|
||||
audioObjectKey: input.audioObjectKey,
|
||||
status: 'UPLOADED',
|
||||
},
|
||||
include: { place: true },
|
||||
});
|
||||
|
||||
await enqueueVoiceExperience({ experienceId: experience.id });
|
||||
|
||||
return experience;
|
||||
}
|
||||
Reference in New Issue
Block a user