From 5874efff3ce67603971bbf6c979e8ca2f32dc007 Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Mon, 27 Apr 2026 19:02:44 -0400 Subject: [PATCH] refactor(status-page): apply review feedback on theme-fields backend - StatusPage Mongoose model: import DEFAULT_STATUS_PAGE_THEME / DEFAULT_STATUS_PAGE_THEME_MODE from types/statusPage so the four sources of the default literal stay locked together - openapi.json: add explicit "default" alongside the enum on StatusPageTheme and StatusPageThemeMode component schemas; documentation already mentioned the defaults but the JSON didn't carry them - statusPageController: add JSDoc-style comments above withoutThemeFields and applyDefaultTheme spelling out the asymmetric strip-on-write / force-on-read semantics so the next reviewer doesn't have to re-derive the design --- server/openapi.json | 2 ++ server/src/controllers/statusPageController.ts | 7 +++++++ server/src/db/models/StatusPage.ts | 12 +++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/openapi.json b/server/openapi.json index e3ff57cc7..de0103a38 100644 --- a/server/openapi.json +++ b/server/openapi.json @@ -3354,11 +3354,13 @@ "StatusPageTheme": { "type": "string", "enum": ["refined", "modern", "bold", "editorial"], + "default": "refined", "description": "Visual theme for the public status page. Defaults to 'refined'." }, "StatusPageThemeMode": { "type": "string", "enum": ["auto", "light", "dark"], + "default": "auto", "description": "Forces a light/dark mode on the public page. 'auto' follows the visitor's OS preference. Defaults to 'auto'." }, "SuccessResponse": { diff --git a/server/src/controllers/statusPageController.ts b/server/src/controllers/statusPageController.ts index 2e338f787..20fadbab6 100644 --- a/server/src/controllers/statusPageController.ts +++ b/server/src/controllers/statusPageController.ts @@ -40,6 +40,9 @@ class StatusPageController implements IStatusPageController { return StatusPageController.SERVICE_NAME; } + // Used when STATUS_PAGE_THEMES_ENABLED is false: drop incoming theme fields + // before persisting so an admin client can't accidentally store a value the + // public page won't honour. private withoutThemeFields = (body: Record): Record => { const rest = { ...body }; delete rest.theme; @@ -47,6 +50,10 @@ class StatusPageController implements IStatusPageController { return rest; }; + // Used when STATUS_PAGE_THEMES_ENABLED is false: overwrite the stored + // theme/themeMode with their defaults on read so callers see consistent + // values regardless of what's in the DB. Whatever a user previously chose + // is preserved in Mongo and resurfaces if the flag is flipped back on. private applyDefaultTheme = (statusPage: StatusPage): StatusPage => ({ ...statusPage, theme: DEFAULT_STATUS_PAGE_THEME, diff --git a/server/src/db/models/StatusPage.ts b/server/src/db/models/StatusPage.ts index 0a1b5830c..0b6451492 100644 --- a/server/src/db/models/StatusPage.ts +++ b/server/src/db/models/StatusPage.ts @@ -1,6 +1,12 @@ import { Schema, model, type Types } from "mongoose"; import type { StatusPage, StatusPageLogoDocument } from "@/types/statusPage.js"; -import { StatusPageTypes, StatusPageThemes, StatusPageThemeModes } from "@/types/statusPage.js"; +import { + DEFAULT_STATUS_PAGE_THEME, + DEFAULT_STATUS_PAGE_THEME_MODE, + StatusPageThemeModes, + StatusPageThemes, + StatusPageTypes, +} from "@/types/statusPage.js"; type StatusPageDocumentBase = Omit< StatusPage, @@ -111,12 +117,12 @@ const StatusPageSchema = new Schema( theme: { type: String, enum: StatusPageThemes, - default: "refined", + default: DEFAULT_STATUS_PAGE_THEME, }, themeMode: { type: String, enum: StatusPageThemeModes, - default: "auto", + default: DEFAULT_STATUS_PAGE_THEME_MODE, }, }, { timestamps: true }