This commit is contained in:
Michal Kváček
2023-08-26 11:45:50 +02:00
parent ccc8ff22e2
commit dcc3230cbe
18 changed files with 132 additions and 42 deletions
+10 -3
View File
@@ -6,7 +6,8 @@ import {updateInItems} from "stores/helpers";
export const useFlightsStore = defineStore('Flights', {
state: () => ({
items: []
items: [],
isMutationRunning: false
}),
getters: {
@@ -19,18 +20,24 @@ export const useFlightsStore = defineStore('Flights', {
create(formData) {
delete formData['id'];
return apolloWrapper.mutate(CREATE_FLIGHT, {input: formData}).then(({data}) => {
this.items.push(data.createFlight);
const flightId = data.createFlight.id;
// pitomy ohack kvuli tomu, ze se mi nedari dostat z API rovnou informace o nove vytvorenem letadle
this.fetchDetail(flightId).then(flight => {
this.items.push(flight);
})
return data.createFlight;
})
},
update(id, formData) {
this.isMutationRunning = true;
return apolloWrapper.mutate(EDIT_FLIGHT, {id: id, input: formData}).then(({data}) => {
const flight = data.editFlight;
updateInItems(this.items, "id", flight);
return flight;
});
}).finally(() => this.isMutationRunning = false);
},
fetchDetail(id, username = null) {
if (typeof id !== "number") {