Sprava eventu a organizaci

This commit is contained in:
Michal Kváček
2023-09-20 13:26:13 +02:00
parent 6fbaef4a1e
commit 8c3c5ee48d
42 changed files with 624 additions and 56 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import {COPILOT_DETAIL, COPILOTS_LIST} from "src/graphql/queries/copilots";
import {CREATE_COPILOT, EDIT_COPILOT} from "src/graphql/mutations/copilot";
import {updateInItems} from "stores/helpers";
export const useCopilotsStore = defineStore('SecondPilots', {
export const useCopilotsStore = defineStore('Copilots', {
state: () => ({
items: [],
isMutationRunning: false,
+1 -1
View File
@@ -4,7 +4,7 @@ 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', {
export const useEventsStore = defineStore('Events', {
state: () => ({
items: [],
isMutationRunning: false,
+56
View File
@@ -0,0 +1,56 @@
import {defineStore} from 'pinia'
import {apolloWrapper} from "src/graphql/apollo";
import {ADD_USER_TO_ORGANIZATION, CREATE_ORGANIZATION, EDIT_ORGANIZATION, REMOVE_USER_FROM_ORGANIZATION} from "src/graphql/mutations/organization";
import {ORGANIZATION_DETAIL, ORGANIZATIONS_LIST} from "src/graphql/queries/organization";
import {updateInItems} from "stores/helpers";
export const useOrganizationsStore = defineStore('Organizations', {
state: () => ({
items: [],
isMutationRunning: false,
}),
actions: {
fetchDetail(organizationId) {
return apolloWrapper.query(ORGANIZATION_DETAIL, {id: organizationId}).then(({data}) => data.organization);
},
fetch() {
return apolloWrapper.query(ORGANIZATIONS_LIST).then(result => {
this.items = result.data.organizations;
return result.data.organizations;
});
},
create(formData) {
delete formData['id'];
this.isMutationRunning = true;
return apolloWrapper.mutate(CREATE_ORGANIZATION, {input: formData}).then(({data}) => {
const organization = data.createOrganization;
this.items.push(organization);
return organization;
}).finally(() => this.isMutationRunning = false);
},
addUserToOrganization(organizationId) {
this.isMutationRunning = true;
return apolloWrapper.mutate(ADD_USER_TO_ORGANIZATION, {organizationId}).then(({data}) => {
return data.addToOrganization;
}).finally(() => this.isMutationRunning = false);
},
removeUserFromOrganization(organizationId) {
this.isMutationRunning = true;
return apolloWrapper.mutate(REMOVE_USER_FROM_ORGANIZATION, {organizationId}).then(({data}) => {
return data.removeFromOrganization;
}).finally(() => this.isMutationRunning = false);
},
update(id, formData) {
return apolloWrapper.mutate(EDIT_ORGANIZATION, {id: id, input: formData}).then(({data}) => {
const organization = data.editOrganization;
updateInItems(this.items, "id", organization);
return organization;
}).finally(() => this.isMutationRunning = false);
},
}
})
+1 -1
View File
@@ -2,7 +2,7 @@ import {defineStore} from "pinia";
import {apolloWrapper} from "src/graphql/apollo";
import {DELETE_PHOTO, EDIT_PHOTO, UPLOAD_PHOTO} from "src/graphql/mutations/photo";
export const usePhotosStore = defineStore('photos', {
export const usePhotosStore = defineStore('Photos', {
state: () => ({
isMutationRunning: false,
}),