Files
TREK/server/tests/helpers/factories/settings.ts
T
Maurice b9231ffb53 feat(mcp): manage the trip's shared links over MCP (#3076)
list_collab_links, create_collab_link, update_collab_link and
delete_collab_link run the Links panel's REST routes as tools: the shared
body contracts, trip access, collab_edit on writes and the collab🔗*
broadcasts, behind the links sub-feature flag. Unit, e2e and broadcast
parity cases cover them; the wiki lists the tools.
2026-11-13 10:17:15 +01:00

44 lines
2.0 KiB
TypeScript

import { Addons } from '../../../src/db/entities/Addons.entity';
import { AppSettings } from '../../../src/db/entities/AppSettings.entity';
import { Settings } from '../../../src/db/entities/Settings.entity';
import type { FactoryOrm } from './context';
import { findRow, upsertRow } from './rows';
/** Writes an instance-wide setting (`app_settings`), replacing any earlier value. */
export async function setAppSetting(orm: FactoryOrm, key: string, value: string): Promise<void> {
await upsertRow(orm, AppSettings, { key, value });
}
/** The instance-wide setting's value, or null when it is unset. */
export async function readAppSetting(orm: FactoryOrm, key: string): Promise<string | null> {
return (await findRow(orm, AppSettings, { key }))?.value ?? null;
}
/** Writes one of the user's own settings (`settings`, unique per user and key), replacing any earlier value. */
export async function setUserSetting(orm: FactoryOrm, userId: number, key: string, value: string): Promise<void> {
await upsertRow(orm, Settings, { user: userId, key, value });
}
/** The user's setting, or null when it is unset. */
export async function readUserSetting(orm: FactoryOrm, userId: number, key: string): Promise<string | null> {
return (await findRow(orm, Settings, { user: userId, key }))?.value ?? null;
}
/**
* Flips an addon the way the admin panel does. An addon the instance does not
* know yet is created as a global one named after its id; an existing one
* keeps its name, type and order and only changes `enabled`.
*/
export async function setAddonEnabled(orm: FactoryOrm, addonId: string, enabled: boolean): Promise<void> {
await upsertRow(orm, Addons, { id: addonId, name: addonId, type: 'global', enabled }, ['enabled']);
}
/** Collab's chat, notes, polls, links and next-up panels are opt-out app settings, not addon rows. */
export async function setCollabFeature(
orm: FactoryOrm,
feature: 'chat' | 'notes' | 'polls' | 'links' | 'whatsnext',
enabled: boolean,
): Promise<void> {
await setAppSetting(orm, `collab_${feature}_enabled`, enabled ? 'true' : 'false');
}