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:
@@ -26,6 +26,7 @@ import {Quiz, ResponseWithQuestion, Score} from "~/repositories/models/quiz.mode
|
||||
import QuizAxeDetails from "~/components/QuizAxeDetails.vue";
|
||||
import {Axe} from "~/repositories/models/axe.model";
|
||||
import {RestResponse} from "~/repositories/models/rest-response.model";
|
||||
|
||||
@Component({
|
||||
components: {QuizAxeDetails}
|
||||
})
|
||||
@@ -36,7 +37,6 @@ export default class Result extends Vue {
|
||||
|
||||
private axes: Axe[] = [];
|
||||
private quiz: Quiz | null = null;
|
||||
private scores: Score[] = [];
|
||||
private responses: ResponseWithQuestion[] = [];
|
||||
private loading = false;
|
||||
|
||||
@@ -50,28 +50,15 @@ export default class Result extends Vue {
|
||||
this.quizRepository.findById(quizId)
|
||||
.then((response: AxiosResponse<Quiz>) => {
|
||||
this.quiz = response.data;
|
||||
this.responses = response.data._embedded.responses;
|
||||
return response;
|
||||
})
|
||||
.then(() => {
|
||||
return this.quizRepository.findScores(quizId)
|
||||
.then((response: AxiosResponse<Score[]>) => {
|
||||
this.scores = response.data;
|
||||
return response;
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
return this.quizRepository.findResponses(quizId)
|
||||
.then((response: AxiosResponse<RestResponse<ResponseWithQuestion>>) => {
|
||||
this.responses = response.data._embedded.responses;
|
||||
return response;
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
return this.axeRepository.findAll()
|
||||
.then((response: AxiosResponse<RestResponse<Axe>>) => {
|
||||
this.axes = response.data._embedded.axes;
|
||||
return response;
|
||||
});
|
||||
this.axes = response.data._embedded.axes;
|
||||
return response;
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
@@ -82,8 +69,12 @@ export default class Result extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
getScore(axe: Axe) {
|
||||
return this.scores.find(value => value.axeIdentifier === axe.identifier);
|
||||
getScore(axe: Axe): Score {
|
||||
const responses = this.getResponses(axe);
|
||||
return {
|
||||
axeIdentifier: axe.identifier,
|
||||
scoreAvg: responses.reduce((total, response) => total + response.score, 0) / responses.length
|
||||
};
|
||||
}
|
||||
|
||||
getResponses(axe: Axe) {
|
||||
|
Reference in New Issue
Block a user