feat(status-page): add theme and themeMode fields (backend)
## Changes - Add `theme` (refined | modern | bold | editorial, default "refined") and `themeMode` (auto | light | dark, default "auto") fields to the StatusPage Mongoose model and the shared `StatusPage` type. - Extend the create/update Zod validator to accept both fields optionally. - Map both fields in the repository's `toEntity` so GET responses include them. - Document both fields in the create and update endpoints in `openapi.json`. - Add `STATUS_PAGE_THEMES_ENABLED` env var (default `true`) wired through `SettingsService` for ops-level rollback. When disabled, the controller strips theme fields on write and forces defaults on read. ## Notes - No migration needed; Mongoose applies defaults for legacy documents. - Controller short-circuits to zero-cost when the feature flag is on. - `DEFAULT_STATUS_PAGE_THEME` / `DEFAULT_STATUS_PAGE_THEME_MODE` constants exported so the frontend PR can consume the same values.
This commit is contained in:
1 parent
6ed0818bad
commit
ad964446de
11 files changed
+408
-8
No files matched your search
@@ -12,6 +12,7 @@ import { IStatusPageService } from "@/service/business/statusPageService.js";
|
||||
import { IMonitorsRepository } from "@/repositories/index.js";
|
||||
import { ISettingsService } from "@/service/system/settingsService.js";
|
||||
import { NormalizeData } from "@/utils/dataUtils.js";
|
||||
import { DEFAULT_STATUS_PAGE_THEME, DEFAULT_STATUS_PAGE_THEME_MODE, type StatusPage } from "@/types/statusPage.js";
|
||||
|
||||
const SERVICE_NAME = "statusPageController";
|
||||
|
||||
@@ -39,6 +40,19 @@ class StatusPageController implements IStatusPageController {
|
||||
return StatusPageController.SERVICE_NAME;
|
||||
}
|
||||
|
||||
private withoutThemeFields = (body: Record<string, unknown>): Record<string, unknown> => {
|
||||
const rest = { ...body };
|
||||
delete rest.theme;
|
||||
delete rest.themeMode;
|
||||
return rest;
|
||||
};
|
||||
|
||||
private applyDefaultTheme = (statusPage: StatusPage): StatusPage => ({
|
||||
...statusPage,
|
||||
theme: DEFAULT_STATUS_PAGE_THEME,
|
||||
themeMode: DEFAULT_STATUS_PAGE_THEME_MODE,
|
||||
});
|
||||
|
||||
createStatusPage = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
createStatusPageBodyValidation.parse(req.body);
|
||||
@@ -46,14 +60,16 @@ class StatusPageController implements IStatusPageController {
|
||||
imageValidation.parse(req.file);
|
||||
}
|
||||
|
||||
const themesEnabled = this.settingsService.areStatusPageThemesEnabled();
|
||||
const body = themesEnabled ? req.body : this.withoutThemeFields(req.body);
|
||||
const teamId = requireTeamId(req?.user?.teamId);
|
||||
const userId = requireUserId(req?.user?.id);
|
||||
const statusPage = await this.statusPageService.createStatusPage(userId, teamId, req.file, req.body);
|
||||
const statusPage = await this.statusPageService.createStatusPage(userId, teamId, req.file, body);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Status page created successfully",
|
||||
data: statusPage,
|
||||
data: themesEnabled ? statusPage : this.applyDefaultTheme(statusPage),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -66,19 +82,22 @@ class StatusPageController implements IStatusPageController {
|
||||
if (req.file) {
|
||||
imageValidation.parse(req.file);
|
||||
}
|
||||
|
||||
const themesEnabled = this.settingsService.areStatusPageThemesEnabled();
|
||||
const body = themesEnabled ? req.body : this.withoutThemeFields(req.body);
|
||||
const teamId = requireTeamId(req?.user?.teamId);
|
||||
const statusPageId = req.params.id as string;
|
||||
if (!statusPageId) {
|
||||
throw new AppError({ message: "Status page ID is required", status: 400 });
|
||||
}
|
||||
const statusPage = await this.statusPageService.updateStatusPage(statusPageId, teamId, req.file, req.body);
|
||||
const statusPage = await this.statusPageService.updateStatusPage(statusPageId, teamId, req.file, body);
|
||||
if (statusPage === null) {
|
||||
throw new AppError({ message: "Status page not found", status: 404 });
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Status page updated successfully",
|
||||
data: statusPage,
|
||||
data: themesEnabled ? statusPage : this.applyDefaultTheme(statusPage),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -124,10 +143,14 @@ class StatusPageController implements IStatusPageController {
|
||||
}
|
||||
return { ...monitor, checks: normalizedChecks };
|
||||
});
|
||||
const themesEnabled = this.settingsService.areStatusPageThemesEnabled();
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Status page retrieved successfully",
|
||||
data: { statusPage, monitors: normalizedMonitors },
|
||||
data: {
|
||||
statusPage: themesEnabled ? statusPage : this.applyDefaultTheme(statusPage),
|
||||
monitors: normalizedMonitors,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -138,10 +161,11 @@ class StatusPageController implements IStatusPageController {
|
||||
const teamId = requireTeamId(req.user?.teamId);
|
||||
const statusPages = await this.statusPageService.getStatusPagesByTeamId(teamId);
|
||||
|
||||
const themesEnabled = this.settingsService.areStatusPageThemesEnabled();
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Status pages retrieved successfully",
|
||||
data: statusPages,
|
||||
data: themesEnabled ? statusPages : statusPages.map((sp) => this.applyDefaultTheme(sp)),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
Reference in new issue
Block a user