feat: add app_config table with runtime log level control and POS structured logging
All checks were successful
CI / ci (pull_request) Successful in 20s
CI / e2e (pull_request) Successful in 56s

- New app_config key-value table for system settings, with in-memory cache (mirrors ModuleService pattern)
- GET/PATCH /v1/config endpoints for reading and updating config (settings.view/settings.edit permissions)
- Runtime log level: PATCH /v1/config/log_level applies immediately, persists across restarts
- Startup loads log level from DB in onReady hook (env var is default, DB overrides)
- Add structured request.log.info() to POS routes: transaction create/complete/void, drawer open/close, discount create/update/delete

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ryan
2026-04-04 18:56:21 +00:00
parent 51e7902ee2
commit 772d5578ad
11 changed files with 154 additions and 0 deletions

View File

@@ -30,8 +30,10 @@ import { storeRoutes } from './routes/v1/store.js'
import { vaultRoutes } from './routes/v1/vault.js'
import { webdavRoutes } from './routes/webdav/index.js'
import { moduleRoutes } from './routes/v1/modules.js'
import { configRoutes } from './routes/v1/config.js'
import { RbacService } from './services/rbac.service.js'
import { ModuleService } from './services/module.service.js'
import { AppConfigService } from './services/config.service.js'
export async function buildApp() {
const app = Fastify({
@@ -106,6 +108,7 @@ export async function buildApp() {
await app.register(rbacRoutes, { prefix: '/v1' })
await app.register(storeRoutes, { prefix: '/v1' })
await app.register(moduleRoutes, { prefix: '/v1' })
await app.register(configRoutes, { prefix: '/v1' })
await app.register(lookupRoutes, { prefix: '/v1' })
// Module-gated routes
@@ -146,6 +149,16 @@ export async function buildApp() {
} catch (err) {
app.log.error({ err }, 'Failed to load module cache')
}
try {
await AppConfigService.refreshCache(app.db)
const dbLogLevel = await AppConfigService.get(app.db, 'log_level')
if (dbLogLevel) {
app.log.level = dbLogLevel
app.log.info({ level: dbLogLevel }, 'Log level loaded from config')
}
} catch (err) {
app.log.error({ err }, 'Failed to load app config')
}
})
return app