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', { state: () => ({ isMutationRunning: false, }), actions: { upload(flightId, formData) { if (!flightId) { console.error("No flightId specified for photo upload! Aborting"); return; } formData.flightId = flightId; if (!formData.name) { formData.name = ""; } if (!formData.description) { formData.description = ""; } this.isMutationRunning = true; return apolloWrapper.mutate(UPLOAD_PHOTO, {input: formData}).then(({data}) => { return data.uploadPhoto; }).finally(() => this.isMutationRunning = false); }, update(id, formData) { this.isMutationRunning = true; return apolloWrapper.mutate(EDIT_PHOTO, {id, input: formData}).then(({data}) => { return data.editPhoto; }).finally(() => this.isMutationRunning = false); }, delete(photoId) { return apolloWrapper.mutate(DELETE_PHOTO, {id: photoId}).then(({data}) => { return data.deletePhoto; }); } } });