All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #322 | Page horaire | ## Description de la PR [#322] Page horaire ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #4 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import type { Employee } from './dto/employee'
|
|
import { extractItems } from '~/utils/api'
|
|
|
|
export const listEmployees = async () => {
|
|
const api = useApi()
|
|
const data = await api.get<Employee[] | { 'hydra:member'?: Employee[] }>(
|
|
'/employees',
|
|
{},
|
|
{ toast: false }
|
|
)
|
|
return extractItems<Employee>(data)
|
|
}
|
|
|
|
export const listScopedEmployees = async () => {
|
|
const api = useApi()
|
|
const data = await api.get<Employee[] | { 'hydra:member'?: Employee[] }>(
|
|
'/employees/scoped',
|
|
{},
|
|
{ toast: false }
|
|
)
|
|
return extractItems<Employee>(data)
|
|
}
|
|
|
|
export const createEmployee = async (payload: {
|
|
firstName: string
|
|
lastName: string
|
|
siteId?: number | null
|
|
contractId: number
|
|
}) => {
|
|
const api = useApi()
|
|
return api.post<Employee>('/employees', {
|
|
firstName: payload.firstName,
|
|
lastName: payload.lastName,
|
|
site: payload.siteId ? `/api/sites/${payload.siteId}` : null,
|
|
contract: `/api/contracts/${payload.contractId}`
|
|
}, {
|
|
toastSuccessKey: 'success.employee.create',
|
|
toastErrorKey: 'errors.employee.create'
|
|
})
|
|
}
|
|
|
|
export const updateEmployee = async (
|
|
id: number,
|
|
payload: {
|
|
firstName: string
|
|
lastName: string
|
|
siteId?: number | null
|
|
contractId: number
|
|
displayOrder?: number
|
|
}
|
|
) => {
|
|
const api = useApi()
|
|
return api.patch<Employee>(`/employees/${id}`, {
|
|
firstName: payload.firstName,
|
|
lastName: payload.lastName,
|
|
site: payload.siteId ? `/api/sites/${payload.siteId}` : null,
|
|
contract: `/api/contracts/${payload.contractId}`,
|
|
displayOrder: payload.displayOrder
|
|
}, {
|
|
toastSuccessKey: 'success.employee.update',
|
|
toastErrorKey: 'errors.employee.update'
|
|
})
|
|
}
|
|
|
|
export const updateEmployeeOrder = async (
|
|
id: number,
|
|
displayOrder: number
|
|
) => {
|
|
const api = useApi()
|
|
return api.patch<Employee>(`/employees/${id}`, {
|
|
displayOrder
|
|
}, {
|
|
toast: false
|
|
})
|
|
}
|
|
|
|
export const deleteEmployee = async (id: number) => {
|
|
const api = useApi()
|
|
return api.delete(`/employees/${id}`, {}, {
|
|
toastSuccessKey: 'success.employee.delete',
|
|
toastErrorKey: 'errors.employee.delete'
|
|
})
|
|
}
|