use element update route

This commit is contained in:
Yisroel Baum 2026-06-02 16:33:18 +03:00
parent 9cb968afd8
commit 1d9e2cff0a
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 26 additions and 15 deletions

View file

@ -44,6 +44,7 @@ interface ErrorResponse {
}
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string
const ELEMENT_UPDATE_URL = `${API_BASE_URL}/api/element/update`
export const useElementsStore = defineStore('elements', () => {
const element = ref<Element | null>(null)
@ -109,13 +110,11 @@ export const useElementsStore = defineStore('elements', () => {
isSaving.value = true
try {
const encodedElementId = encodeURIComponent(elementId)
const elementUrl = `${API_BASE_URL}/api/elements/${encodedElementId}`
const response = await fetch(elementUrl, {
const response = await fetch(ELEMENT_UPDATE_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(input),
body: JSON.stringify({ elementId, ...input }),
})
return await handleElementResponse(response, failureMessage)
@ -132,11 +131,10 @@ export const useElementsStore = defineStore('elements', () => {
isUploadingIconImage.value = true
try {
const encodedElementId = encodeURIComponent(elementId)
const elementUrl = `${API_BASE_URL}/api/elements/${encodedElementId}`
const formData = new FormData()
formData.append('elementId', elementId)
formData.append('iconImage', file)
const response = await fetch(elementUrl, {
const response = await fetch(ELEMENT_UPDATE_URL, {
method: 'POST',
headers: { Accept: 'application/json' },
credentials: 'include',
@ -157,11 +155,10 @@ export const useElementsStore = defineStore('elements', () => {
isUploadingPdf.value = true
try {
const encodedElementId = encodeURIComponent(elementId)
const elementUrl = `${API_BASE_URL}/api/elements/${encodedElementId}`
const formData = new FormData()
formData.append('elementId', elementId)
formData.append('pdf', file)
const response = await fetch(elementUrl, {
const response = await fetch(ELEMENT_UPDATE_URL, {
method: 'POST',
headers: { Accept: 'application/json' },
credentials: 'include',