Sprava eventu

This commit is contained in:
Michal Kváček
2023-09-19 06:33:17 +02:00
parent 0c91ff7838
commit 6fbaef4a1e
25 changed files with 533 additions and 30 deletions
+41
View File
@@ -0,0 +1,41 @@
import {defineStore} from 'pinia'
import {apolloWrapper} from "src/graphql/apollo";
import {CREATE_EVENT, EDIT_EVENT} from "src/graphql/mutations/event";
import {updateInItems} from "stores/helpers";
import {EVENT_DETAIL, EVENTS_LIST} from "src/graphql/queries/event";
export const useEventsStore = defineStore('SecondPilots', {
state: () => ({
items: [],
isMutationRunning: false,
}),
actions: {
fetchDetail(eventId) {
return apolloWrapper.query(EVENT_DETAIL, {id: eventId}).then(({data}) => data.event);
},
fetch() {
return apolloWrapper.query(EVENTS_LIST).then(result => {
this.items = result.data.events;
return result.data.events;
});
},
create(formData) {
delete formData['id'];
this.isMutationRunning = true;
return apolloWrapper.mutate(CREATE_EVENT, {input: formData}).then(({data}) => {
const event = data.createEvent;
this.items.push(event);
return event;
}).finally(() => this.isMutationRunning = false);
},
update(id, formData) {
return apolloWrapper.mutate(EDIT_EVENT, {id: id, input: formData}).then(({data}) => {
const event = data.editEvent;
updateInItems(this.items, "id", event);
return event;
}).finally(() => this.isMutationRunning = false);
},
}
})