import type { H3Event } from 'h3' export interface NotesDocRow { id: number title: string | null content?: string | null created: string | null updated: string | null } export const NOTES_SUMMARY_FIELDS = 'title,created,updated' export function notesTable(event: H3Event): string { const { baserowNotesAppTableId } = useRuntimeConfig(event) if (!baserowNotesAppTableId) { throw createError({ statusCode: 500, statusMessage: 'NUXT_BASEROW_NOTES_APP_TABLE_ID ist nicht gesetzt' }) } return baserowNotesAppTableId } export function notesDocId(event: H3Event): number { const id = Number(getRouterParam(event, 'id')) if (!Number.isInteger(id) || id < 1) { throw createError({ statusCode: 400, statusMessage: 'Ungültige Notiz' }) } return id } /** `created` and `updated` are plain date fields, so the server keeps them up to date */ export function notesNow(): string { return new Date().toISOString() } export function toNotesDocSummary(row: NotesDocRow): NotesDocSummary { return { id: row.id, title: (row.title ?? '').trim(), created: row.created, updated: row.updated } } export function toNotesDoc(row: NotesDocRow): NotesDoc { return { ...toNotesDocSummary(row), content: row.content ?? '' } }