Tickets: Startdatum als TT.MM.JJJJ, Frist gleich (R5)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-09-30 18:30:53 +00:00
1 parent c93cb93a36
commit df0c7a05e8
2 files changed
+54 -3

No files matched your search

+24 -2
View File
@@ -1,4 +1,5 @@
import { config } from '../config.js'
import { berlinDateTime } from './berlinTime.js'
import {
createDocument,
deleteDocument,
@@ -111,7 +112,7 @@ export async function createFeatureTicket({ customerId, project, featureKey, sit
* Legt ein Ticket fuer ein Projekt an (Zuordnen-Flow, erst beim Abschliessen).
* Unbekannter Kunde => Fehler mit status 400.
*/
export async function createTicketForProject({ customerId, topic, type, requestedBy, startDate, details }) {
export async function createTicketForProject({ customerId, topic, type, requestedBy, startDate, details }, { now = new Date() } = {}) {
const customer = customerId
? await getDocument(config.collections.customers, customerId).catch(() => null)
: null
@@ -121,6 +122,26 @@ export async function createTicketForProject({ customerId, topic, type, requeste
throw err
}
// WOMS speichert Ticket-Daten als 'TT.MM.JJJJ'; leer = heute (Berlin).
let date
if (!startDate) {
date = berlinDateTime(now).date
} else {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(startDate))
const valid =
m &&
(() => {
const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]))
return d.getUTCFullYear() === +m[1] && d.getUTCMonth() === +m[2] - 1 && d.getUTCDate() === +m[3]
})()
if (!valid) {
const err = new Error('Das Startdatum ist ungültig (erwartet: JJJJ-MM-TT).')
err.status = 400
throw err
}
date = `${m[3]}.${m[2]}.${m[1]}`
}
const woid = await generateNextWoid()
const ticket = await createDocument(
config.collections.workorders,
@@ -135,7 +156,8 @@ export async function createTicketForProject({ customerId, topic, type, requeste
customerName: customer.name || '',
customerLocation: customer.location || '',
requestedBy: requestedBy || '',
startDate: startDate || '',
startDate: date,
deadline: date,
details: details || '',
woid,
createdAt: new Date().toISOString(),