CG-Feedback-Monitor/server/db/queries/appSettings.ts
2026-07-06 19:08:24 +02:00

27 lines
1.1 KiB
TypeScript

import { getRowById, insertRowWithId, updateRow } from '../crud'
import type { AppSettings } from '../../../src/db/types'
/** 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
}