From 4b6e1aa69cba859d5ddcff6558a57a2423517422 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 5 Jan 2026 03:30:35 +0300 Subject: [PATCH] voice --- backend/prisma/seed.ts | 37 +++++++++++++++++++++++++++ backend/src/voice/voice.controller.ts | 2 +- backend/src/voice/voice.service.ts | 6 +++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/backend/prisma/seed.ts b/backend/prisma/seed.ts index 7742b56..a6cbe75 100644 --- a/backend/prisma/seed.ts +++ b/backend/prisma/seed.ts @@ -1,4 +1,6 @@ import { PrismaClient } from '@prisma/client'; +import * as fs from 'fs'; +import * as path from 'path'; const prisma = new PrismaClient(); @@ -177,6 +179,41 @@ async function main() { console.log('Family pack created:', familyPack); + // Read default questions from JSON file + // questions.json is in the project root, one level up from backend/ + const questionsJsonPath = path.resolve( + process.cwd(), + '../questions.json', + ); + const questionsJson = JSON.parse( + fs.readFileSync(questionsJsonPath, 'utf-8'), + ); + + // Transform questions: remove id field + const defaultQuestions = questionsJson.map((q: any) => ({ + text: q.text, + answers: q.answers, + })); + + // Create default question pack + const defaultPack = await prisma.questionPack.upsert({ + where: { id: 'default-pack-1' }, + update: {}, + create: { + id: 'default-pack-1', + name: 'Новогодние вопросы', + description: 'Новогодние вопросы', + category: 'Новый год', + isPublic: true, + createdBy: demoUser.id, + questions: defaultQuestions, + questionCount: defaultQuestions.length, + rating: 5.0, + }, + }); + + console.log('Default pack created:', defaultPack); + console.log('Seed completed successfully!'); } diff --git a/backend/src/voice/voice.controller.ts b/backend/src/voice/voice.controller.ts index cc6cf9e..fd356cc 100644 --- a/backend/src/voice/voice.controller.ts +++ b/backend/src/voice/voice.controller.ts @@ -8,7 +8,7 @@ import { HttpStatus, HttpException, } from '@nestjs/common'; -import { Response } from 'express'; +import type { Response } from 'express'; import { VoiceService } from './voice.service'; @Controller('voice') diff --git a/backend/src/voice/voice.service.ts b/backend/src/voice/voice.service.ts index 254dae7..f92b190 100644 --- a/backend/src/voice/voice.service.ts +++ b/backend/src/voice/voice.service.ts @@ -6,11 +6,13 @@ export class VoiceService { private readonly voiceServiceUrl: string; constructor(private configService: ConfigService) { - this.voiceServiceUrl = this.configService.get('VOICE_SERVICE_HOST'); + const voiceServiceHost = this.configService.get('VOICE_SERVICE_HOST'); - if (!this.voiceServiceUrl) { + if (!voiceServiceHost) { throw new Error('VOICE_SERVICE_HOST environment variable is not set'); } + + this.voiceServiceUrl = voiceServiceHost; } async generateTTS(text: string, voice: string = 'sarah'): Promise {