Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #8 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import type { Observation } from './dto/observation'
|
|
import { extractItems } from '~/utils/api'
|
|
|
|
export const listObservations = async (employeeId: number) => {
|
|
const api = useApi()
|
|
const data = await api.get<Observation[] | { 'hydra:member'?: Observation[] }>(
|
|
'/observations',
|
|
{ employee: `/api/employees/${employeeId}` },
|
|
{ toast: false }
|
|
)
|
|
return extractItems<Observation>(data)
|
|
}
|
|
|
|
export const createObservation = async (data: {
|
|
employeeId: number
|
|
month: string
|
|
content: string
|
|
}) => {
|
|
const api = useApi()
|
|
return api.post<Observation>('/observations', {
|
|
employee: `/api/employees/${data.employeeId}`,
|
|
month: data.month,
|
|
content: data.content
|
|
}, {
|
|
toastSuccessKey: 'success.observation.create',
|
|
toastErrorKey: 'errors.observation.create'
|
|
})
|
|
}
|
|
|
|
export const updateObservation = async (id: number, data: {
|
|
month: string
|
|
content: string
|
|
}) => {
|
|
const api = useApi()
|
|
return api.patch<Observation>(`/observations/${id}`, {
|
|
month: data.month,
|
|
content: data.content
|
|
}, {
|
|
toastSuccessKey: 'success.observation.update',
|
|
toastErrorKey: 'errors.observation.update'
|
|
})
|
|
}
|
|
|
|
export const deleteObservation = async (id: number) => {
|
|
const api = useApi()
|
|
return api.delete(`/observations/${id}`, {}, {
|
|
toastSuccessKey: 'success.observation.delete',
|
|
toastErrorKey: 'errors.observation.delete'
|
|
})
|
|
}
|