Exercise store, mark exercise 0.2 as solved on ticket buy

This commit is contained in:
2024-10-23 13:57:37 +02:00
parent 093eba9af6
commit c5c5a2da8b
5 changed files with 49 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
import { fetchAllExerciseGroups, updateExercise } from "@/data/api/exerciseApi";
import { ExerciseGroupApiModel } from "@/data/models/exercises/exerciseGroupApiModel";
import { defineStore } from "pinia";
import { ref } from "vue";
export const useExerciseStore = defineStore("exerciseStore", {
state: () => ({
exerciseGroups: ref<Array<ExerciseGroupApiModel>>([]),
/** Request to server sent, waiting for data response */
fetchInProgress: ref(false)
}),
actions: {
getAllExercises() {
this.fetchInProgress = true
fetchAllExerciseGroups()
.then(result => {
this.exerciseGroups = result.data
this.fetchInProgress = false
})
},
solveExercise(exerciseGroupNr: number, exerciseNr: number) {
this.fetchInProgress = true
updateExercise(exerciseGroupNr, exerciseNr, true)
.then(result => {
this.getAllExercises()
})
}
}
})