First commit
This commit is contained in:
0
src/services/userService.ts
Normal file
0
src/services/userService.ts
Normal file
55
src/services/visualAssetService.ts
Normal file
55
src/services/visualAssetService.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import axios from 'axios'
|
||||
import type { FrontVisualAsset, VisualAsset } from '@/types/types.ts'
|
||||
|
||||
export const upload = async (visualAssets: VisualAsset[]): Promise<void> => {
|
||||
try {
|
||||
for (const asset of visualAssets) {
|
||||
const formData = new FormData()
|
||||
console.log('asset file', asset.image)
|
||||
|
||||
formData.append('name', asset.name)
|
||||
formData.append('collection', asset.collection)
|
||||
formData.append('image', asset.image)
|
||||
await axios.post('/api/visualAssets', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error uploading visual assets:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchVisualAssets = async (): Promise<FrontVisualAsset[]> => {
|
||||
try {
|
||||
const response = await axios.get('/api/visualAssets')
|
||||
return response.data as FrontVisualAsset[]
|
||||
} catch (error) {
|
||||
console.error('Error fetching visual assets:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchVisualAssetsByCollection = async (
|
||||
collection: string,
|
||||
): Promise<FrontVisualAsset[]> => {
|
||||
try {
|
||||
const response = await axios.get(`/api/visualAssets/collection/${collection}`)
|
||||
return response.data as FrontVisualAsset[]
|
||||
} catch (error) {
|
||||
console.error('Error fetching visual assets:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchVisualAssetById = async (id: string): Promise<FrontVisualAsset> => {
|
||||
try {
|
||||
const response = await axios.get(`/api/visualAssets/${id}`)
|
||||
return response.data as FrontVisualAsset
|
||||
} catch (error) {
|
||||
console.error(`Error fetching visual asset with id ${id}:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user