/* Ticket zu einer Adresse wie /tickets/: erst die Nummer (woid), dann die Dokument-ID. Kennt kein Appwrite, die Seite reicht die Abfragen herein. */ const NOT_FOUND_CODES = [400, 404] export async function lookupWorkorder(ref, { findByWoid, getById }) { const key = String(ref ?? '').trim() if (!key) return { status: 'notfound' } const byWoid = await findByWoid(key) if (byWoid) return { status: 'ok', ticket: byWoid } try { const byId = await getById(key) return byId ? { status: 'ok', ticket: byId } : { status: 'notfound' } } catch (error) { // Appwrite: 404 = keine solche ID, 400 = keine gueltige ID if (NOT_FOUND_CODES.includes(Number(error?.code))) return { status: 'notfound' } throw error } }