Fixes upload of legacy quizzes from arsnova.click v1

parent 79053e9c
......@@ -111,11 +111,18 @@ class QuizDAO extends AbstractDAO<Array<IQuizEntity>> {
});
}
public convertLegacyQuiz(legacyQuiz: any): void {
public convertLegacyQuiz(legacyQuiz: any): QuizEntity {
legacyQuiz = this.replaceTypeInformationOnLegacyQuiz(legacyQuiz);
if (legacyQuiz.hasOwnProperty('configuration')) {
// Detected old v1 arsnova.click quiz
// noinspection TypeScriptUnresolvedVariable
legacyQuiz.name = legacyQuiz.hashtag;
delete legacyQuiz.hashtag;
legacyQuiz.currentQuestionIndex = 0;
legacyQuiz.expiry = null;
legacyQuiz.currentStartTimestamp = -1;
legacyQuiz.readingConfirmationRequested = false;
legacyQuiz.sessionConfig = {
music: {
titleConfig: {
......@@ -149,6 +156,8 @@ class QuizDAO extends AbstractDAO<Array<IQuizEntity>> {
};
delete legacyQuiz.configuration;
}
return legacyQuiz;
}
public async addQuiz(quizDoc: IQuizSerialized): Promise<IQuizEntity> {
......
......@@ -148,7 +148,7 @@ export class QuizRouter extends AbstractRouter {
uploadedFiles.forEach(file => {
quizData.push({
fileName: file.originalname,
quiz: JSON.parse(file.buffer.toString('UTF-8')),
quiz: QuizDAO.convertLegacyQuiz(JSON.parse(file.buffer.toString('UTF-8'))),
});
});
......@@ -178,7 +178,10 @@ export class QuizRouter extends AbstractRouter {
return {
status: StatusProtocol.Success,
step: MessageProtocol.UploadFile,
payload: { duplicateQuizzes },
payload: {
duplicateQuizzes,
quizData: quizData.filter(insertedQuiz => !duplicateQuizzes.find(duplicateQuiz => duplicateQuiz.fileName === insertedQuiz.fileName)),
},
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment