Bugfixy
This commit is contained in:
+10
-3
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user