feat: review model to retrieve all the questions with a single query

- update initial data
- add description field to the axe
This commit is contained in:
2022-11-02 11:16:17 +01:00
parent 075a508bb5
commit 3c4928ae61
20 changed files with 269 additions and 155 deletions

View File

@@ -7,6 +7,7 @@
<quiz-part
:key="currentAxe.identifier" :axe-number="currentAxe.identifier" :total-axes="axes.length"
:title="currentAxe.title"
:description="currentAxe.description"
:color="currentAxe.color"
:icon="'balise_' + currentAxe.identifier + '.svg'"
:questions="questions.get(currentAxe.identifier)"
@@ -43,7 +44,7 @@
import {AxiosResponse} from "axios";
import {Component, Vue} from "nuxt-property-decorator";
import {RepositoryFactory} from "~/repositories/RepositoryFactory";
import {Axe} from "~/repositories/models/axe.model";
import {AxeWithQuestions} from "~/repositories/models/axe.model";
import {RestResponse} from "~/repositories/models/rest-response.model";
import {Question} from "~/repositories/models/question.model";
import {Quiz} from "~/repositories/models/quiz.model";
@@ -53,10 +54,9 @@ import {quizStore} from "~/utils/store-accessor";
export default class Login extends Vue {
readonly axeRepository = RepositoryFactory.get("axe");
readonly questionRepository = RepositoryFactory.get("question");
private axes: Axe[] = [];
private currentAxe?: Axe;
private axes: AxeWithQuestions[] = [];
private currentAxe?: AxeWithQuestions | undefined;
private currentAxeIdentifier = 1;
private questions: Map<number, Question[]> = new Map<number, []>();
private loading = true;
@@ -67,28 +67,17 @@ export default class Login extends Vue {
this.loading = true;
this.axeRepository
.findAll()
.then((response: AxiosResponse<RestResponse<Axe>>) => {
.then((response: AxiosResponse<RestResponse<AxeWithQuestions>>) => {
this.axes = response.data._embedded.axes;
const promises: any[] = [];
this.axes.forEach(axe => {
promises.push(
this.questionRepository
.findAllByAxeId(axe.identifier)
.then((response: AxiosResponse<RestResponse<Question>>) => {
return {
axeId: axe.identifier,
questions: response.data._embedded.questions
};
}));
});
Promise.all(promises).then((axeQuestions) => {
axeQuestions.forEach(axeQuestion => {
this.questions.set(axeQuestion.axeId, axeQuestion.questions)
});
quizStore.initialize(this.questions);
this.initializeState();
this.loading = false;
this.questions.set(axe.identifier, axe.questions);
});
this.initializeState();
quizStore.initialize(this.questions);
})
.finally(() => {
this.loading = false;
});
}