feat : ajout d'une gestion d'erreur au global côté front avec la lib toaster et I18n pour centraliser les messages d'erreur
This commit is contained in:
@@ -1,28 +1,39 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { ReceptionData } from '~/services/dto/reception-data'
|
||||
import type { WeightData } from '~/services/dto/weight-data'
|
||||
import {useApi} from '~/composables/useApi'
|
||||
import type {ReceptionData} from '~/services/dto/reception-data'
|
||||
import type {WeightData} from '~/services/dto/weight-data'
|
||||
|
||||
export async function getReceptionList() {
|
||||
const api = useApi()
|
||||
return api.get<ReceptionData>(`receptions`)
|
||||
return api.get<ReceptionData>(`receptions`, {}, {
|
||||
toastErrorKey: 'errors.reception.list'
|
||||
})
|
||||
}
|
||||
|
||||
export async function getReception(id: number) {
|
||||
const api = useApi()
|
||||
return api.get<ReceptionData>(`receptions/${id}`)
|
||||
return api.get<ReceptionData>(`receptions/${id}`, {}, {
|
||||
toastErrorKey: 'errors.reception.fetch'
|
||||
})
|
||||
}
|
||||
|
||||
export async function createReception(payload: Partial<ReceptionData> = {}) {
|
||||
const api = useApi()
|
||||
return api.post<ReceptionData>('receptions', payload)
|
||||
return api.post<ReceptionData>('receptions', payload, {
|
||||
toastErrorKey: 'errors.reception.create'
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateReception(id: number, payload: Partial<ReceptionData>) {
|
||||
const api = useApi()
|
||||
return api.patch<ReceptionData>(`receptions/${id}`, payload)
|
||||
return api.patch<ReceptionData>(`receptions/${id}`, payload, {
|
||||
toastErrorKey: 'errors.reception.update',
|
||||
toastSuccessKey: 'success.reception.update'
|
||||
})
|
||||
}
|
||||
|
||||
export async function getWeight(): Promise<WeightData> {
|
||||
const api = useApi()
|
||||
return api.get<WeightData>('receptions/weigh')
|
||||
return api.get<WeightData>('receptions/weigh', {}, {
|
||||
toastErrorKey: 'errors.reception.weigh'
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user