From 3ab4fcb2776b7cb7bce0972c5ec26cf7a9db0479 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 9 Jan 2026 15:32:53 -0800 Subject: [PATCH] js->ts --- server/src/config/controllers.js | 5 +- ...ller.js => maintenanceWindowController.ts} | 128 +++++++++--------- server/src/controllers/v1/queueController.ts | 6 + .../src/controllers/v1/settingsController.ts | 3 + .../controllers/v1/statusPageController.ts | 6 + 5 files changed, 82 insertions(+), 66 deletions(-) rename server/src/controllers/v1/{maintenanceWindowController.js => maintenanceWindowController.ts} (52%) diff --git a/server/src/config/controllers.js b/server/src/config/controllers.js index 7d29fbb71..4c910763a 100644 --- a/server/src/config/controllers.js +++ b/server/src/config/controllers.js @@ -39,10 +39,7 @@ export const initializeControllers = (services) => { inviteService: services.inviteService, }); - controllers.maintenanceWindowController = new MaintenanceWindowController(commonDependencies, { - settingsService: services.settingsService, - maintenanceWindowService: services.maintenanceWindowService, - }); + controllers.maintenanceWindowController = new MaintenanceWindowController(services.maintenanceWindowService); controllers.queueController = new QueueController(services.jobQueue); controllers.logController = new LogController(commonDependencies); controllers.statusPageController = new StatusPageController(services.db); diff --git a/server/src/controllers/v1/maintenanceWindowController.js b/server/src/controllers/v1/maintenanceWindowController.ts similarity index 52% rename from server/src/controllers/v1/maintenanceWindowController.js rename to server/src/controllers/v1/maintenanceWindowController.ts index be373ace5..d850bdf82 100644 --- a/server/src/controllers/v1/maintenanceWindowController.js +++ b/server/src/controllers/v1/maintenanceWindowController.ts @@ -1,3 +1,4 @@ +import { AppError } from "@/utils/AppError.js"; import { createMaintenanceWindowBodyValidation, editMaintenanceWindowByIdParamValidation, @@ -6,16 +7,15 @@ import { getMaintenanceWindowsByMonitorIdParamValidation, getMaintenanceWindowsByTeamIdQueryValidation, deleteMaintenanceWindowByIdParamValidation, -} from "../../validation/joi.js"; -import BaseController from "./baseController.js"; +} from "@/validation/joi.js"; +import { Request, Response, NextFunction } from "express"; const SERVICE_NAME = "maintenanceWindowController"; -class MaintenanceWindowController extends BaseController { +class MaintenanceWindowController { static SERVICE_NAME = SERVICE_NAME; - constructor(commonDependencies, { settingsService, maintenanceWindowService }) { - super(commonDependencies); - this.settingsService = settingsService; + private maintenanceWindowService: any; + constructor(maintenanceWindowService: any) { this.maintenanceWindowService = maintenanceWindowService; } @@ -23,124 +23,128 @@ class MaintenanceWindowController extends BaseController { return MaintenanceWindowController.SERVICE_NAME; } - createMaintenanceWindows = this.asyncHandler( - async (req, res) => { + createMaintenanceWindows = async (req: Request, res: Response, next: NextFunction) => { + try { await createMaintenanceWindowBodyValidation.validateAsync(req.body); const teamId = req?.user?.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } await this.maintenanceWindowService.createMaintenanceWindow({ teamId, body: req.body }); - return res.success({ - msg: this.stringService.maintenanceWindowCreate, + return res.status(200).json({ + success: true, + msg: "Maintenance window created successfully", }); - }, - SERVICE_NAME, - "createMaintenanceWindows" - ); - - getMaintenanceWindowById = this.asyncHandler( - async (req, res) => { + } catch (error) { + next(error); + } + }; + getMaintenanceWindowById = async (req: Request, res: Response, next: NextFunction) => { + try { await getMaintenanceWindowByIdParamValidation.validateAsync(req.params); const teamId = req.user.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } const maintenanceWindow = await this.maintenanceWindowService.getMaintenanceWindowById({ id: req.params.id, teamId }); - return res.success({ - msg: this.stringService.maintenanceWindowGetById, + return res.status(200).json({ + success: true, + msg: "Maintenance window fetched successfully", data: maintenanceWindow, }); - }, - SERVICE_NAME, - "getMaintenanceWindowById" - ); + } catch (error) { + next(error); + } + }; - getMaintenanceWindowsByTeamId = this.asyncHandler( - async (req, res) => { + getMaintenanceWindowsByTeamId = async (req: Request, res: Response, next: NextFunction) => { + try { await getMaintenanceWindowsByTeamIdQueryValidation.validateAsync(req.query); const teamId = req?.user?.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } const maintenanceWindows = await this.maintenanceWindowService.getMaintenanceWindowsByTeamId({ teamId, query: req.query }); - return res.success({ - msg: this.stringService.maintenanceWindowGetByTeam, + return res.status(200).json({ + success: true, + msg: "Maintenance windows fetched successfully", data: maintenanceWindows, }); - }, - SERVICE_NAME, - "getMaintenanceWindowsByTeamId" - ); + } catch (error) { + next(error); + } + }; - getMaintenanceWindowsByMonitorId = this.asyncHandler( - async (req, res) => { + getMaintenanceWindowsByMonitorId = async (req: Request, res: Response, next: NextFunction) => { + try { await getMaintenanceWindowsByMonitorIdParamValidation.validateAsync(req.params); const teamId = req?.user?.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } const maintenanceWindows = await this.maintenanceWindowService.getMaintenanceWindowsByMonitorId({ monitorId: req.params.monitorId, teamId }); - return res.success({ - msg: this.stringService.maintenanceWindowGetByUser, + return res.status(200).json({ + success: true, + msg: "Maintenance windows fetched successfully", data: maintenanceWindows, }); - }, - SERVICE_NAME, - "getMaintenanceWindowsByMonitorId" - ); - - deleteMaintenanceWindow = this.asyncHandler( - async (req, res) => { + } catch (error) { + next(error); + } + }; + deleteMaintenanceWindow = async (req: Request, res: Response, next: NextFunction) => { + try { await deleteMaintenanceWindowByIdParamValidation.validateAsync(req.params); const teamId = req?.user?.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } await this.maintenanceWindowService.deleteMaintenanceWindow({ id: req.params.id, teamId }); - return res.success({ - msg: this.stringService.maintenanceWindowDelete, + return res.status(200).json({ + success: true, + msg: "Maintenance window deleted successfully", }); - }, - SERVICE_NAME, - "deleteMaintenanceWindow" - ); + } catch (error) { + next(error); + } + }; - editMaintenanceWindow = this.asyncHandler( - async (req, res) => { + editMaintenanceWindow = async (req: Request, res: Response, next: NextFunction) => { + try { await editMaintenanceWindowByIdParamValidation.validateAsync(req.params); await editMaintenanceByIdWindowBodyValidation.validateAsync(req.body); const teamId = req.user.teamId; if (!teamId) { - throw this.errorService.createBadRequestError("Team ID is required"); + throw new AppError({ message: "Team ID is required", status: 400 }); } const editedMaintenanceWindow = await this.maintenanceWindowService.editMaintenanceWindow({ id: req.params.id, body: req.body, teamId }); - return res.success({ - msg: this.stringService.maintenanceWindowEdit, + return res.status(200).json({ + success: true, + msg: "Maintenance window edited successfully", data: editedMaintenanceWindow, }); - }, - SERVICE_NAME, - "editMaintenanceWindow" - ); + } catch (error) { + next(error); + } + }; } export default MaintenanceWindowController; diff --git a/server/src/controllers/v1/queueController.ts b/server/src/controllers/v1/queueController.ts index cb39be826..9885bab87 100755 --- a/server/src/controllers/v1/queueController.ts +++ b/server/src/controllers/v1/queueController.ts @@ -17,6 +17,7 @@ class JobQueueController { try { const metrics = await this.jobQueue.getMetrics(); res.status(200).json({ + success: true, msg: "Queue metrics fetched successfully", data: metrics, }); @@ -29,6 +30,7 @@ class JobQueueController { try { const jobs = await this.jobQueue.getJobs(); return res.status(200).json({ + success: true, msg: "Queue jobs fetched successfully", data: jobs, }); @@ -42,6 +44,7 @@ class JobQueueController { const jobs = await this.jobQueue.getJobs(); const metrics = await this.jobQueue.getMetrics(); return res.status(200).json({ + success: true, msg: "Queue metrics fetched successfully", data: { jobs, metrics }, }); @@ -54,6 +57,7 @@ class JobQueueController { try { await this.jobQueue.addJob(Math.random().toString(36).substring(7)); return res.status(200).json({ + success: true, msg: "Job added to queue successfully", }); } catch (error) { @@ -65,6 +69,7 @@ class JobQueueController { try { const result = await this.jobQueue.flushQueues(); return res.status(200).json({ + success: true, msg: "Queue flushed successfully", data: result, }); @@ -77,6 +82,7 @@ class JobQueueController { try { const stuckQueues = await this.jobQueue.checkQueueHealth(); return res.status(200).json({ + success: true, msg: "Queue health checked successfully", data: stuckQueues, }); diff --git a/server/src/controllers/v1/settingsController.ts b/server/src/controllers/v1/settingsController.ts index 659e0200e..5d3f6ed0e 100644 --- a/server/src/controllers/v1/settingsController.ts +++ b/server/src/controllers/v1/settingsController.ts @@ -47,6 +47,7 @@ class SettingsController { const returnSettings = this.buildAppSettings(dbSettings); return res.status(200).json({ + success: true, msg: "App settings fetched successfully", data: returnSettings, }); @@ -61,6 +62,7 @@ class SettingsController { const updatedSettings = await this.db.settingsModule.updateAppSettings(req.body); const returnSettings = this.buildAppSettings(updatedSettings); return res.status(200).json({ + success: true, msg: "App settings updated successfully", data: returnSettings, }); @@ -110,6 +112,7 @@ class SettingsController { } return res.status(200).json({ + success: true, msg: "Test email sent successfully", data: { messageId }, }); diff --git a/server/src/controllers/v1/statusPageController.ts b/server/src/controllers/v1/statusPageController.ts index 79e0f5481..105beb230 100644 --- a/server/src/controllers/v1/statusPageController.ts +++ b/server/src/controllers/v1/statusPageController.ts @@ -29,6 +29,7 @@ class StatusPageController { teamId, }); return res.status(200).json({ + success: true, msg: "Status page created successfully", data: statusPage, }); @@ -47,6 +48,7 @@ class StatusPageController { throw new AppError({ message: "Status page not found", status: 404 }); } return res.status(200).json({ + success: true, msg: "Status page updated successfully", data: statusPage, }); @@ -59,6 +61,7 @@ class StatusPageController { try { const statusPage = await this.db.statusPageModule.getStatusPage(); return res.status(200).json({ + success: true, msg: "Status page retrieved successfully", data: statusPage, }); @@ -74,6 +77,7 @@ class StatusPageController { const statusPage = await this.db.statusPageModule.getStatusPageByUrl(req.params.url); return res.status(200).json({ + success: true, msg: "Status page retrieved successfully", data: statusPage, }); @@ -87,6 +91,7 @@ class StatusPageController { const statusPages = await this.db.statusPageModule.getStatusPagesByTeamId(teamId); return res.status(200).json({ + success: true, msg: "Status pages retrieved successfully", data: statusPages, }); @@ -98,6 +103,7 @@ class StatusPageController { try { await this.db.statusPageModule.deleteStatusPage(req.params.url); return res.status(200).json({ + success: true, msg: "Status page deleted successfully", }); } catch (error) {