Sprava eventu
This commit is contained in:
@@ -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);
|
||||
},
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user