mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 06:56:35 +00:00
refactor(server): fold the in-container bridge edges
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import semver from 'semver';
|
||||
import { isAddonEnabled } from '../nest/addons/addons.bridge.js';
|
||||
import type { NoticeCondition, SystemNotice } from './types.js';
|
||||
|
||||
interface ConditionContext {
|
||||
user: { login_count: number; first_seen_version: string; role: string; noTrips: number };
|
||||
currentAppVersion: string;
|
||||
now: Date;
|
||||
/**
|
||||
* Addon-enablement check, threaded in by the caller (the Nest service passes
|
||||
* its injected AddonsService) so this plain module carries no bridge import.
|
||||
*/
|
||||
addonEnabled: (addonId: string) => boolean;
|
||||
}
|
||||
|
||||
// Custom predicate registry — extensible without modifying this file
|
||||
@@ -48,7 +52,7 @@ function evaluateOne(condition: NoticeCondition, ctx: ConditionContext): boolean
|
||||
return condition.roles.includes(ctx.user.role as 'admin' | 'user');
|
||||
|
||||
case 'addonEnabled':
|
||||
return isAddonEnabled(condition.addonId);
|
||||
return ctx.addonEnabled(condition.addonId);
|
||||
|
||||
case 'custom': {
|
||||
const fn = customPredicates.get(condition.id);
|
||||
|
||||
@@ -36,7 +36,10 @@ function severityWeight(s: string): number {
|
||||
return s === 'critical' ? 2 : s === 'warn' ? 1 : 0;
|
||||
}
|
||||
|
||||
export function getActiveNoticesFor(userId: number): SystemNoticeDTO[] {
|
||||
export function getActiveNoticesFor(
|
||||
userId: number,
|
||||
addonEnabled: (addonId: string) => boolean
|
||||
): SystemNoticeDTO[] {
|
||||
const user = db.prepare(
|
||||
'SELECT login_count, first_seen_version, role FROM users WHERE id = ?'
|
||||
).get(userId) as { login_count: number; first_seen_version: string; role: string } | undefined;
|
||||
@@ -56,7 +59,7 @@ export function getActiveNoticesFor(userId: number): SystemNoticeDTO[] {
|
||||
|
||||
const now = new Date();
|
||||
const currentAppVersion = getCurrentAppVersion();
|
||||
const ctx = { user: { ...user, noTrips: tripCount }, currentAppVersion, now };
|
||||
const ctx = { user: { ...user, noTrips: tripCount }, currentAppVersion, now, addonEnabled };
|
||||
const appVer = semver.coerce(currentAppVersion)?.version ?? '0.0.0';
|
||||
|
||||
const isStillDismissed = (n: SystemNotice): boolean => {
|
||||
|
||||
Reference in New Issue
Block a user