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
+8 -5
View File
@@ -6,7 +6,8 @@ import {deleteFromItems, updateInItems} from "stores/helpers";
export const useAircraftsStore = defineStore('Aircrafts', {
state: () => ({
items: []
items: [],
isMutationRunning: false
}),
getters: {
@@ -15,18 +16,19 @@ export const useAircraftsStore = defineStore('Aircrafts', {
actions: {
fetchDetail(id) {
console.log(id);
return apolloWrapper
.query(AIRCRAFT_DETAIL, {id})
.then((result) => result.data.aircraft);
},
create(formData) {
delete formData['id'];
this.isMutationRunning = true;
return apolloWrapper.mutate(CREATE_AIRCRAFT, {input: formData}).then(({data}) => {
this.items.push(data.createAircraft);
// this.items.push(data.createAircraft);
return data.createAircraft;
})
}).finally(() => this.isMutationRunning = false);
},
delete(id) {
return apolloWrapper.mutate(DELETE_AIRCRAFT, {id}).then(({data}) => {
@@ -36,11 +38,12 @@ export const useAircraftsStore = defineStore('Aircrafts', {
});
},
update(id, formData) {
this.isMutationRunning = true;
return apolloWrapper.mutate(EDIT_AIRCRAFT, {id: id, input: formData}).then(({data}) => {
const aircraft = data.editAircraft;
updateInItems(this.items, 'id', aircraft);
return aircraft;
});
}).finally(() => this.isMutationRunning = false);
},
fetch() {
return apolloWrapper
+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") {
+6 -3
View File
@@ -8,15 +8,18 @@ export const useUserStore = defineStore('LoggedUser', {
state: () => ({
user: {},
isRefreshing: false,
isMutationRunning: false,
}),
actions: {
update(id, formData) {
apolloWrapper.mutate(EDIT_USER, {id, input: formData}).then((response) => {
update(formData) {
this.isMutationRunning = true;
apolloWrapper.mutate(EDIT_USER, {input: formData}).then((response) => {
const user = response.data?.editLoggedUser;
this.user = user;
return user;
});
}).finally(() => this.isMutationRunning = false);
},
fetchLoggedUserDetail() {