refactoring: TypeScript migration, security fixes,

This commit is contained in:
Maurice
2026-03-27 18:40:18 +01:00
parent 510475a46f
commit 8396a75223
150 changed files with 8116 additions and 8467 deletions
+31
View File
@@ -0,0 +1,31 @@
import type { AssignmentsMap } from '../types'
export function formatDate(dateStr: string | null | undefined, locale: string): string | null {
if (!dateStr) return null
return new Date(dateStr + 'T00:00:00').toLocaleDateString(locale, {
weekday: 'short', day: 'numeric', month: 'short',
})
}
export function formatTime(timeStr: string | null | undefined, locale: string, timeFormat: string): string {
if (!timeStr) return ''
try {
const parts = timeStr.split(':')
const h = Number(parts[0]) || 0
const m = Number(parts[1]) || 0
if (isNaN(h)) return timeStr
if (timeFormat === '12h') {
const period = h >= 12 ? 'PM' : 'AM'
const h12 = h === 0 ? 12 : h > 12 ? h - 12 : h
return `${h12}:${String(m).padStart(2, '0')} ${period}`
}
const str = `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`
return locale?.startsWith('de') ? `${str} Uhr` : str
} catch { return timeStr }
}
export function dayTotalCost(dayId: number, assignments: AssignmentsMap, currency: string): string | null {
const da = assignments[String(dayId)] || []
const total = da.reduce((s, a) => s + (parseFloat(a.place?.price || '') || 0), 0)
return total > 0 ? `${total.toFixed(0)} ${currency}` : null
}
+12
View File
@@ -0,0 +1,12 @@
interface ItemWithId {
id: number
[key: string]: unknown
}
export function swapItems(items: ItemWithId[], index: number, direction: 'up' | 'down'): number[] | null {
const target = direction === 'up' ? index - 1 : index + 1
if (target < 0 || target >= items.length) return null
const ids = items.map((a) => a.id)
;[ids[index], ids[target]] = [ids[target], ids[index]]
return ids
}