room
This commit is contained in:
parent
d0da0012a3
commit
bdf14981c9
3 changed files with 14 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ generator client {
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export class RoomPackService {
|
||||||
? 'Copied from source pack'
|
? 'Copied from source pack'
|
||||||
: 'Custom room questions';
|
: 'Custom room questions';
|
||||||
|
|
||||||
let questions = [];
|
let questions: any = [];
|
||||||
let questionCount = 0;
|
let questionCount = 0;
|
||||||
|
|
||||||
// If source pack provided, copy questions
|
// If source pack provided, copy questions
|
||||||
|
|
@ -24,7 +24,7 @@ export class RoomPackService {
|
||||||
select: { questions: true, questionCount: true },
|
select: { questions: true, questionCount: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sourcePack) {
|
if (sourcePack && sourcePack.questions) {
|
||||||
questions = sourcePack.questions;
|
questions = sourcePack.questions;
|
||||||
questionCount = sourcePack.questionCount;
|
questionCount = sourcePack.questionCount;
|
||||||
}
|
}
|
||||||
|
|
@ -78,18 +78,23 @@ export class RoomPackService {
|
||||||
select: { questions: true },
|
select: { questions: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!sourcePack || !Array.isArray(sourcePack.questions)) {
|
if (!roomPack) {
|
||||||
|
throw new Error('Room pack not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourcePack || !sourcePack.questions || !Array.isArray(sourcePack.questions)) {
|
||||||
throw new Error('Source pack not found or invalid');
|
throw new Error('Source pack not found or invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get existing questions
|
// Get existing questions
|
||||||
const existingQuestions = Array.isArray(roomPack.questions)
|
const existingQuestions = Array.isArray(roomPack.questions)
|
||||||
? roomPack.questions
|
? (roomPack.questions as any[])
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
// Import selected questions (create copies)
|
// Import selected questions (create copies)
|
||||||
|
const sourceQuestions = sourcePack.questions as any[];
|
||||||
const questionsToImport = questionIndices
|
const questionsToImport = questionIndices
|
||||||
.map(idx => sourcePack.questions[idx])
|
.map(idx => sourceQuestions[idx])
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map(q => ({ ...q })); // Deep copy
|
.map(q => ({ ...q })); // Deep copy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,9 @@ export class RoomsService {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.roomEventsService.emitRoomPackUpdated(room.code, room);
|
if (room) {
|
||||||
|
this.roomEventsService.emitRoomPackUpdated(room.code, room);
|
||||||
|
}
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue