CG-Feedback-Monitor/server/db/queries/appSettings.ts
Lars 234f87d408 V2-Dev-Stand: Skala 1-10, Benefits/Concerns, DEV-Isolation und Gitea-Doku.
Bündelt die Neuentwicklung in AssigmentMonitorV2 (eigene Ports/DB), die Umstellung auf numerische Bewertungen, Meeting-Checklisten, KI-Tagging und die geplante Feedback-Kaskade — als Basis für Versionsverwaltung in Gitea.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 17:35:05 +02:00

143 lines
6.1 KiB
TypeScript

import { getRowById, insertRowWithId, updateRow } from '../crud'
import type { AppSettings, RatingColorBand } from '../../../src/db/types'
import { AI_CONFIG, DEFAULT_RATING_COLOR_BANDS, normalizeRatingColorBands } from '../../../src/config/constants'
/** Muss mit DEFAULT_RATING_TREND_WEIGHT_STEP in src/config/constants.ts synchron gehalten werden. */
const DEFAULT_RATING_TREND_WEIGHT_STEP = 0.5
export function getRatingTrendWeightStep(): number {
const settings = getRowById<AppSettings>('appSettings', 1)
return settings?.ratingTrendWeightStep ?? DEFAULT_RATING_TREND_WEIGHT_STEP
}
export function getOrSeedRatingTrendWeightStep(): number {
let settings = getRowById<AppSettings>('appSettings', 1)
if (!settings) {
insertRowWithId('appSettings', 1, { ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP })
settings = getRowById<AppSettings>('appSettings', 1)
}
return settings?.ratingTrendWeightStep ?? DEFAULT_RATING_TREND_WEIGHT_STEP
}
export function saveRatingTrendWeightStep(weightStep: number): number {
const existing = getRowById('appSettings', 1)
if (existing) updateRow('appSettings', 1, { ratingTrendWeightStep: weightStep })
else insertRowWithId('appSettings', 1, { ratingTrendWeightStep: weightStep })
return 1
}
export function getOrSeedRatingColorBands(): RatingColorBand[] {
let settings = getRowById<AppSettings>('appSettings', 1)
if (!settings) {
insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
ratingColorBands: DEFAULT_RATING_COLOR_BANDS.map(b => ({ ...b })),
})
return DEFAULT_RATING_COLOR_BANDS.map(b => ({ ...b }))
}
if (!settings.ratingColorBands?.length) {
const seeded = DEFAULT_RATING_COLOR_BANDS.map(b => ({ ...b }))
updateRow('appSettings', 1, { ratingColorBands: seeded })
return seeded
}
return normalizeRatingColorBands(settings.ratingColorBands)
}
export function saveRatingColorBands(bands: RatingColorBand[]): number {
const normalized = normalizeRatingColorBands(bands)
const existing = getRowById('appSettings', 1)
if (existing) updateRow('appSettings', 1, { ratingColorBands: normalized })
else insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
ratingColorBands: normalized,
})
return 1
}
/**
* Der Standard-Prompt für neue Dimensionen/"Zurücksetzen" lebt jetzt in der DB statt im Code
* (`AI_CONFIG.defaultDimensionPromptTemplate` dient nur noch als einmaliger Erstbefüllungs-Wert
* beim allerersten Zugriff auf einer Installation, siehe Config → KI-Prompts).
*/
export function getDefaultDimensionPromptTemplate(): string {
const settings = getRowById<AppSettings>('appSettings', 1)
return settings?.defaultDimensionPromptTemplate ?? AI_CONFIG.defaultDimensionPromptTemplate
}
export function getOrSeedDefaultDimensionPromptTemplate(): string {
const settings = getRowById<AppSettings>('appSettings', 1)
if (!settings) {
insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
defaultDimensionPromptTemplate: AI_CONFIG.defaultDimensionPromptTemplate,
})
return AI_CONFIG.defaultDimensionPromptTemplate
}
if (!settings.defaultDimensionPromptTemplate) {
updateRow('appSettings', 1, { defaultDimensionPromptTemplate: AI_CONFIG.defaultDimensionPromptTemplate })
return AI_CONFIG.defaultDimensionPromptTemplate
}
return settings.defaultDimensionPromptTemplate
}
export function saveDefaultDimensionPromptTemplate(template: string): number {
const existing = getRowById('appSettings', 1)
if (existing) updateRow('appSettings', 1, { defaultDimensionPromptTemplate: template })
else insertRowWithId('appSettings', 1, { ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP, defaultDimensionPromptTemplate: template })
return 1
}
/**
* Prompt-Template für „🏷 Vorschläge analysieren" (selbstlernendes Kriterien-Tagging) — ein
* einziges, protokollweites Template statt eines pro Assignment-Typ, siehe CLAUDE.md. Gleiches
* Erstbefüllungs-/Persistenz-Muster wie `getOrSeedDefaultDimensionPromptTemplate`.
*/
export function getOrSeedCriterionTaggingPromptTemplate(): string {
let settings = getRowById<AppSettings>('appSettings', 1)
if (!settings) {
insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
criterionTaggingPromptTemplate: AI_CONFIG.defaultCriterionTaggingPromptTemplate,
})
return AI_CONFIG.defaultCriterionTaggingPromptTemplate
}
if (!settings.criterionTaggingPromptTemplate) {
updateRow('appSettings', 1, { criterionTaggingPromptTemplate: AI_CONFIG.defaultCriterionTaggingPromptTemplate })
return AI_CONFIG.defaultCriterionTaggingPromptTemplate
}
return settings.criterionTaggingPromptTemplate
}
export function saveCriterionTaggingPromptTemplate(template: string): number {
const existing = getRowById('appSettings', 1)
if (existing) updateRow('appSettings', 1, { criterionTaggingPromptTemplate: template })
else insertRowWithId('appSettings', 1, { ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP, criterionTaggingPromptTemplate: template })
return 1
}
export function getOrSeedDefaultCategoryPromptTemplate(): string {
let settings = getRowById<AppSettings>('appSettings', 1)
if (!settings) {
insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
defaultCategoryPromptTemplate: AI_CONFIG.defaultCategoryPromptTemplate,
})
return AI_CONFIG.defaultCategoryPromptTemplate
}
if (!settings.defaultCategoryPromptTemplate) {
updateRow('appSettings', 1, { defaultCategoryPromptTemplate: AI_CONFIG.defaultCategoryPromptTemplate })
return AI_CONFIG.defaultCategoryPromptTemplate
}
return settings.defaultCategoryPromptTemplate
}
export function saveDefaultCategoryPromptTemplate(template: string): number {
const existing = getRowById('appSettings', 1)
if (existing) updateRow('appSettings', 1, { defaultCategoryPromptTemplate: template })
else insertRowWithId('appSettings', 1, {
ratingTrendWeightStep: DEFAULT_RATING_TREND_WEIGHT_STEP,
defaultCategoryPromptTemplate: template,
})
return 1
}