This commit is contained in:
Dmitry 2026-01-06 23:33:44 +03:00
parent c69a77b997
commit b0b49d1456
2 changed files with 31 additions and 4 deletions

View file

@ -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[];
}

View file

@ -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,