feat : ajout des frais kms + alignment du style de l'application
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
This commit is contained in:
9
frontend/services/dto/mileage-allowance.ts
Normal file
9
frontend/services/dto/mileage-allowance.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type MileageAllowance = {
|
||||
id: number
|
||||
month: string
|
||||
kilometers: number
|
||||
comment: string | null
|
||||
receiptPath: string | null
|
||||
receiptName: string | null
|
||||
createdAt: string
|
||||
}
|
||||
69
frontend/services/mileage-allowances.ts
Normal file
69
frontend/services/mileage-allowances.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { $fetch } from 'ofetch'
|
||||
import type { MileageAllowance } from './dto/mileage-allowance'
|
||||
import { extractItems } from '~/utils/api'
|
||||
|
||||
export const listMileageAllowances = async (employeeId: number) => {
|
||||
const api = useApi()
|
||||
const data = await api.get<MileageAllowance[] | { 'hydra:member'?: MileageAllowance[] }>(
|
||||
'/mileage_allowances',
|
||||
{ employee: `/api/employees/${employeeId}` },
|
||||
{ toast: false }
|
||||
)
|
||||
return extractItems<MileageAllowance>(data)
|
||||
}
|
||||
|
||||
export const createMileageAllowance = async (data: {
|
||||
employeeId: number
|
||||
month: string
|
||||
kilometers: number
|
||||
comment?: string
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.post<MileageAllowance>('/mileage_allowances', {
|
||||
employee: `/api/employees/${data.employeeId}`,
|
||||
month: data.month,
|
||||
kilometers: data.kilometers,
|
||||
comment: data.comment
|
||||
}, {
|
||||
toastSuccessKey: 'success.mileage.create',
|
||||
toastErrorKey: 'errors.mileage.create'
|
||||
})
|
||||
}
|
||||
|
||||
export const updateMileageAllowance = async (id: number, data: {
|
||||
month: string
|
||||
kilometers: number
|
||||
comment?: string
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.patch<MileageAllowance>(`/mileage_allowances/${id}`, {
|
||||
month: data.month,
|
||||
kilometers: data.kilometers,
|
||||
comment: data.comment
|
||||
}, {
|
||||
toastSuccessKey: 'success.mileage.update',
|
||||
toastErrorKey: 'errors.mileage.update'
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteMileageAllowance = async (id: number) => {
|
||||
const api = useApi()
|
||||
return api.delete(`/mileage_allowances/${id}`, {}, {
|
||||
toastSuccessKey: 'success.mileage.delete',
|
||||
toastErrorKey: 'errors.mileage.delete'
|
||||
})
|
||||
}
|
||||
|
||||
export const uploadReceipt = async (baseURL: string, id: number, file: File) => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return $fetch(`${baseURL}/mileage_allowances/${id}/receipt`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'include'
|
||||
})
|
||||
}
|
||||
|
||||
export const getReceiptUrl = (baseURL: string, id: number): string => {
|
||||
return `${baseURL}/mileage_allowances/${id}/receipt`
|
||||
}
|
||||
Reference in New Issue
Block a user