feat : refacto de la partie calendrier + ajout de validation sur les formulaires + ajout des jours fériés
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
import type { Absence } from './dto/absence'
|
||||
import { extractItems } from '~/utils/api'
|
||||
|
||||
export const listAbsences = async () => {
|
||||
type ListAbsencesFilters = {
|
||||
from?: string
|
||||
to?: string
|
||||
siteIds?: number[]
|
||||
}
|
||||
|
||||
export const listAbsences = async (filters: ListAbsencesFilters = {}) => {
|
||||
const api = useApi()
|
||||
const query: Record<string, string | string[]> = {}
|
||||
if (filters.from) {
|
||||
query['endDate[after]'] = filters.from
|
||||
}
|
||||
if (filters.to) {
|
||||
query['startDate[before]'] = filters.to
|
||||
}
|
||||
if (filters.siteIds && filters.siteIds.length > 0) {
|
||||
query['employee.site[]'] = filters.siteIds.map((id) => `/api/sites/${id}`)
|
||||
}
|
||||
const data = await api.get<Absence[] | { 'hydra:member'?: Absence[] }>(
|
||||
'/absences',
|
||||
{},
|
||||
query,
|
||||
{ toast: false }
|
||||
)
|
||||
return extractItems<Absence>(data)
|
||||
|
||||
@@ -4,5 +4,5 @@ export type Employee = {
|
||||
id: number
|
||||
firstName: string
|
||||
lastName: string
|
||||
site?: Site | null
|
||||
site: Site
|
||||
}
|
||||
|
||||
18
frontend/services/public-holidays.ts
Normal file
18
frontend/services/public-holidays.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export type PublicHolidaysResponse =
|
||||
| { days?: Record<string, string> }
|
||||
| Record<string, string>
|
||||
|
||||
export const listPublicHolidays = async (zone: string, year: number) => {
|
||||
const api = useApi()
|
||||
const data = await api.get<PublicHolidaysResponse>(
|
||||
`/public-holidays/${zone}/${year}`,
|
||||
{},
|
||||
{ toast: false }
|
||||
)
|
||||
|
||||
if (data && typeof data === 'object' && 'days' in data) {
|
||||
return (data.days ?? {}) as Record<string, string>
|
||||
}
|
||||
|
||||
return (data ?? {}) as Record<string, string>
|
||||
}
|
||||
Reference in New Issue
Block a user