fix : wip

This commit is contained in:
2026-02-18 17:59:57 +01:00
parent 4256702add
commit c2e118dc33
47 changed files with 2689 additions and 345 deletions

View File

@@ -0,0 +1,13 @@
import type { Contract } from './dto/contract'
import { extractItems } from '~/utils/api'
export const listContracts = async () => {
const api = useApi()
const data = await api.get<Contract[] | { 'hydra:member'?: Contract[] }>(
'/contracts',
{},
{ toast: false }
)
return extractItems<Contract>(data)
}

View File

@@ -0,0 +1,7 @@
export type Contract = {
id: number
name: string
trackingMode: 'TIME' | 'PRESENCE'
weeklyHours?: number | null
isActive?: boolean
}

View File

@@ -1,9 +1,11 @@
import type { Site } from './site'
import type { Contract } from './contract'
export type Employee = {
id: number
firstName: string
lastName: string
site: Site
contract?: Contract | null
displayOrder?: number
}

View File

@@ -0,0 +1,59 @@
import type { Employee } from './employee'
export type WorkHour = {
id: number
employee: Employee
workDate: string
morningFrom?: string | null
morningTo?: string | null
afternoonFrom?: string | null
afternoonTo?: string | null
eveningFrom?: string | null
eveningTo?: string | null
isPresentMorning?: boolean
isPresentAfternoon?: boolean
isValid?: boolean
}
export type WorkHourEntryPayload = {
employeeId: number
morningFrom?: string | null
morningTo?: string | null
afternoonFrom?: string | null
afternoonTo?: string | null
eveningFrom?: string | null
eveningTo?: string | null
isPresentMorning?: boolean
isPresentAfternoon?: boolean
}
export type WeeklyWorkHourDailySummary = {
date: string
dayMinutes: number
nightMinutes: number
totalMinutes: number
present?: number | null
}
export type WeeklyWorkHourRowSummary = {
employeeId: number
firstName: string
lastName: string
siteName?: string | null
contractName?: string | null
trackingMode?: 'TIME' | 'PRESENCE' | null
daily: WeeklyWorkHourDailySummary[]
weeklyDayMinutes: number
weeklyNightMinutes: number
weeklyTotalMinutes: number
weeklyPresenceCount?: number
weeklyOvertime25Minutes?: number
weeklyOvertime50Minutes?: number
}
export type WeeklyWorkHourSummary = {
weekStart: string
weekEnd: string
days: string[]
rows: WeeklyWorkHourRowSummary[]
}

View File

@@ -11,16 +11,28 @@ export const listEmployees = async () => {
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
site: payload.siteId ? `/api/sites/${payload.siteId}` : null,
contract: `/api/contracts/${payload.contractId}`
}, {
toastSuccessKey: 'success.employee.create',
toastErrorKey: 'errors.employee.create'
@@ -33,6 +45,7 @@ export const updateEmployee = async (
firstName: string
lastName: string
siteId?: number | null
contractId: number
displayOrder?: number
}
) => {
@@ -41,6 +54,7 @@ export const updateEmployee = async (
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',

View File

@@ -0,0 +1,61 @@
import type {
WorkHour,
WorkHourEntryPayload,
WeeklyWorkHourSummary
} from './dto/work-hour'
import { extractItems } from '~/utils/api'
export const listWorkHoursByDate = async (workDate: string) => {
const api = useApi()
const data = await api.get<WorkHour[] | { 'hydra:member'?: WorkHour[] }>(
'/work_hours',
{
'workDate[after]': workDate,
'workDate[before]': workDate
},
{ toast: false }
)
return extractItems<WorkHour>(data)
}
export const bulkUpsertWorkHours = async (payload: {
workDate: string
entries: WorkHourEntryPayload[]
}) => {
const api = useApi()
return api.post<{
processed: number
created: number
updated: number
deleted: number
}>(
'/work-hours/bulk-upsert',
payload,
{
toastSuccessMessage: 'Horaires enregistrés.',
toastErrorMessage: "Impossible d'enregistrer les horaires."
}
)
}
export const updateWorkHourValidation = async (id: number, isValid: boolean) => {
const api = useApi()
return api.patch<WorkHour>(
`/work_hours/${id}`,
{ isValid },
{
toastSuccessMessage: isValid ? 'Ligne validée.' : 'Validation retirée.',
toastErrorMessage: 'Impossible de mettre à jour la validation.'
}
)
}
export const getWeeklyWorkHourSummary = async (weekStart: string) => {
const api = useApi()
return api.get<WeeklyWorkHourSummary>(
'/work-hours/weekly-summary',
{ weekStart },
{ toast: false }
)
}