stuff
This commit is contained in:
parent
c69a77b997
commit
b0b49d1456
2 changed files with 31 additions and 4 deletions
|
|
@ -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[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue