Files
Ferme/frontend/utils/datatable-formatters.ts

42 lines
1.3 KiB
TypeScript

export const formatBovinShipments = (value: unknown): string => {
if (!Array.isArray(value) || value.length === 0) return '-'
return value.map((item: any) => {
const label = item?.shipmentType?.label ?? item?.shipmentType?.code ??
'Type inconnu'
const qty = item?.nbBovinSend ?? '-'
return `${label} (${qty})`
}).join(', ')
}
export const formatWeights = (value: unknown): string => {
if (!Array.isArray(value) || value.length === 0) return '-'
return value
.map((item: any) => {
const type = item?.type === 'tare'
? 'Poids à vide'
: item?.type === 'gross'
? 'Poids à plein'
: (item?.type ?? 'Poids')
const weight = item?.weight ?? '-'
return `${type}: ${weight}`
})
.join(', ')
}
export const formatPelletBuildings = (value: unknown): string => {
if (!Array.isArray(value) || value.length === 0) return '-'
return value
.map((item: any) => {
const pelletLabel =
item?.pelletType?.label ?? item?.pelletType?.code ?? 'Granule inconnu'
const buildingLabel =
item?.building?.label ?? item?.building?.code ?? 'Bâtiment inconnu'
return `${pelletLabel} : ${buildingLabel}`
})
.join('\n')
}