Time Changes
Some checks failed
Build and Push Docker Images / verify-docs-sync (push) Failing after 9s
Build and Push Docker Images / build-backend (push) Has been skipped
Build and Push Docker Images / build-frontend (push) Has been skipped
Build and Push Docker Images / build-docs (push) Has been skipped

This commit is contained in:
2026-04-27 09:17:36 +02:00
parent bb61caed6d
commit a021d3d15c
7 changed files with 113 additions and 27 deletions

View File

@@ -12,7 +12,7 @@ const props = defineProps({
const emit = defineEmits(['update:modelValue', 'saved'])
// 💡 createEntry importieren
const { update, createEntry } = useStaffTime()
const { list, update, createEntry } = useStaffTime()
const { $dayjs } = useNuxtApp()
const toast = useToast()
@@ -85,7 +85,7 @@ async function onSubmit(event: FormSubmitEvent<any>) {
if (state.end_date && state.end_time) {
endIso = $dayjs(`${state.end_date} ${state.end_time}`).toISOString()
if ($dayjs(endIso).isBefore($dayjs(startIso))) {
if (!$dayjs(endIso).isAfter($dayjs(startIso))) {
throw new Error("Endzeitpunkt muss nach dem Startzeitpunkt liegen.")
}
}
@@ -100,6 +100,33 @@ async function onSubmit(event: FormSubmitEvent<any>) {
})
toast.add({ title: 'Eintrag aktualisiert', color: 'green' })
} else {
if (endIso) {
const existingEntries = await list({
user_id: props.defaultUserId
})
const newStart = $dayjs(startIso).valueOf()
const newEnd = $dayjs(endIso).valueOf()
const blockingStates = new Set(['draft', 'factual', 'submitted', 'approved'])
const conflictingEntry = existingEntries.find(existingEntry => {
if (!blockingStates.has(existingEntry.state) || !existingEntry.stopped_at) return false
const existingStart = $dayjs(existingEntry.started_at).valueOf()
const existingEnd = $dayjs(existingEntry.stopped_at).valueOf()
if (!Number.isFinite(existingStart) || !Number.isFinite(existingEnd)) return false
return newStart < existingEnd && existingStart < newEnd
})
if (conflictingEntry) {
const conflictStart = $dayjs(conflictingEntry.started_at).format('DD.MM.YYYY HH:mm')
const conflictEnd = $dayjs(conflictingEntry.stopped_at).format('DD.MM.YYYY HH:mm')
throw new Error(`Überschneidung mit ${conflictStart} bis ${conflictEnd} (${conflictingEntry.state}).`)
}
}
// 🟢 CREATE (Neu Erstellen)
// 💡 HIER WAR DER FEHLER: Wir nutzen jetzt createEntry mit den Daten aus dem Formular
await createEntry({