wip: data masih dead pixel upload sukses
This commit is contained in:
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { xfetch } from '~/composables/useXfetch'
|
||||
import { uploadCode, type UploadCodeKey } from '~/lib/constants'
|
||||
|
||||
const mainUrl = '/api/v1/patient'
|
||||
|
||||
@@ -77,3 +78,30 @@ export async function removePatient(id: number) {
|
||||
throw new Error('Failed to delete patient')
|
||||
}
|
||||
}
|
||||
|
||||
export async function uploadAttachment(file: File, userId: number, key: UploadCodeKey) {
|
||||
try {
|
||||
const resolvedKey = uploadCode[key]
|
||||
if (!resolvedKey) {
|
||||
throw new Error(`Invalid upload code key: ${key}`)
|
||||
}
|
||||
|
||||
// siapkan form-data body
|
||||
const formData = new FormData()
|
||||
formData.append('code', resolvedKey)
|
||||
formData.append('content', file)
|
||||
|
||||
// kirim via xfetch
|
||||
const resp = await xfetch(`${mainUrl}/${userId}/upload`, 'POST', formData)
|
||||
|
||||
// struktur hasil sama seperti patchPatient
|
||||
const result: any = {}
|
||||
result.success = resp.success
|
||||
result.body = (resp.body as Record<string, any>) || {}
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Error uploading attachment:', error)
|
||||
throw new Error('Failed to upload attachment')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user