From b0b49d14561d36e03a7e2f07a47a01848920e36e Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 6 Jan 2026 23:33:44 +0300 Subject: [PATCH] stuff --- .../src/admin/packs/dto/create-pack.dto.ts | 25 +++++++++++++++++-- backend/src/rooms/rooms.service.ts | 10 ++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/backend/src/admin/packs/dto/create-pack.dto.ts b/backend/src/admin/packs/dto/create-pack.dto.ts index f62f0d7..f8ef166 100644 --- a/backend/src/admin/packs/dto/create-pack.dto.ts +++ b/backend/src/admin/packs/dto/create-pack.dto.ts @@ -1,4 +1,23 @@ -import { IsString, IsBoolean, IsArray, IsOptional } from 'class-validator'; +import { IsString, IsBoolean, IsArray, IsOptional, ValidateNested, IsNumber } from 'class-validator'; +import { Type } from 'class-transformer'; + +class AnswerDto { + @IsString() + text: string; + + @IsNumber() + points: number; +} + +class QuestionDto { + @IsString() + question: string; + + @IsArray() + @ValidateNested({ each: true }) + @Type(() => AnswerDto) + answers: AnswerDto[]; +} export class CreatePackDto { @IsString() @@ -15,5 +34,7 @@ export class CreatePackDto { isPublic?: boolean; @IsArray() - questions: Array<{ question: string; answer: string }>; + @ValidateNested({ each: true }) + @Type(() => QuestionDto) + questions: QuestionDto[]; } diff --git a/backend/src/rooms/rooms.service.ts b/backend/src/rooms/rooms.service.ts index 1c01928..953c373 100644 --- a/backend/src/rooms/rooms.service.ts +++ b/backend/src/rooms/rooms.service.ts @@ -12,13 +12,19 @@ export class RoomsService { const code = nanoid(); const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000); // 24 hours + // Remove undefined values from settings and ensure questionPackId is handled correctly + const cleanSettings = settings ? { ...settings } : {}; + if ('questionPackId' in cleanSettings) { + delete cleanSettings.questionPackId; + } + const room = await this.prisma.room.create({ data: { code, hostId, - questionPackId: questionPackId || null, expiresAt, - ...settings, + ...cleanSettings, + questionPackId: questionPackId || null, }, include: { host: true,