49 lines
2.4 KiB
JavaScript
49 lines
2.4 KiB
JavaScript
import { TICKET_DETAILS_MAX, kuerze, minimaleTicketDetails } from '../featureRegistry.js'
|
|
import { einbauanleitung } from './einbauanleitung.js'
|
|
import { ladeStand } from './kontext.js'
|
|
|
|
/**
|
|
* Details des Einrichtungs-Tickets fuer den Terminplaner (config.features.termine.ticket.details, TP2 Task D4).
|
|
* ctx = { feature, doc, project, customer } wie ihn markPaid uebergibt: feature = Registereintrag (der Generator braucht ihn nicht),
|
|
* doc = portalFeatures-Dokument (siteKey, $id, customerId, projectId, unlockedByPurchase kommen von dort), project = websiteProjects-Dokument,
|
|
* customer = Kunde oder null (best effort).
|
|
*
|
|
* Inhalt: einbauanleitung(...).kurz, gebaut aus dem gespeicherten Stand der Einstellungen (ladeStand). Die Funktion wirft nie: bezahlt ist bezahlt,
|
|
* das Ticket entsteht immer. Scheitert das Lesen oder der Generator, stehen die Kopfzeilen, der Hinweis, dass die Anleitung nicht erzeugt werden
|
|
* konnte, und der Verweis auf das WOMS im Ticket (notfallDetails). Das Log nennt keine Daten des Betriebs.
|
|
*/
|
|
export async function termineTicketDetails(ctx) {
|
|
try {
|
|
const { doc, project, customer } = ctx
|
|
const stand = await ladeStand(doc.$id)
|
|
const { kurz } = einbauanleitung({
|
|
feature: doc,
|
|
project,
|
|
einstellung: stand?.einstellung ?? null,
|
|
fragebogen: stand?.fragebogen ?? null,
|
|
version: stand?.version ?? 0,
|
|
updatedAt: stand?.updatedAt ?? null,
|
|
kunde: { name: customer?.name || doc.customerId || '' },
|
|
now: new Date(),
|
|
})
|
|
if (typeof kurz !== 'string' || kurz.trim() === '') throw new Error('Kurzfassung leer')
|
|
return kurz
|
|
} catch (err) {
|
|
console.error(`[termine-ticket] Kurzfassung der Einbauanleitung nicht erzeugbar, Notfall-Details: ${err?.message}`)
|
|
return notfallDetails(ctx)
|
|
}
|
|
}
|
|
|
|
const ANLEITUNG_FEHLT = 'Anleitung konnte nicht erzeugt werden, im WOMS öffnen (Verweis oben).'
|
|
const KONTINGENT = 'Nicht auf das Stundenkontingent anrechnen.'
|
|
|
|
/** Kopfzeilen und Verweis (minimaleTicketDetails, Funktion wie im Kopf der Kurzfassung) plus Hinweis; wirft nie, auch nicht bei einem unbrauchbaren ctx. */
|
|
function notfallDetails(ctx) {
|
|
try {
|
|
const kopf = minimaleTicketDetails({ ...ctx, feature: { key: 'Terminplaner' } })
|
|
return kuerze(`${kopf}\n${ANLEITUNG_FEHLT}\n${KONTINGENT}`.toWellFormed(), TICKET_DETAILS_MAX)
|
|
} catch {
|
|
return `Funktion: Terminplaner\nAnleitung konnte nicht erzeugt werden, im WOMS öffnen (Kunden → Funktionen).\n${KONTINGENT}`
|
|
}
|
|
}
|