From 1d7f3b15a4275f9cfe786cd60ea5b41a8ba022d9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 9 Jan 2026 15:21:56 -0800 Subject: [PATCH] js->ts --- server/src/config/controllers.js | 2 +- .../controllers/v1/statusPageController.js | 108 ----------------- .../controllers/v1/statusPageController.ts | 109 ++++++++++++++++++ 3 files changed, 110 insertions(+), 109 deletions(-) delete mode 100644 server/src/controllers/v1/statusPageController.js create mode 100644 server/src/controllers/v1/statusPageController.ts diff --git a/server/src/config/controllers.js b/server/src/config/controllers.js index 5f9cb14a1..7d29fbb71 100644 --- a/server/src/config/controllers.js +++ b/server/src/config/controllers.js @@ -45,7 +45,7 @@ export const initializeControllers = (services) => { }); controllers.queueController = new QueueController(services.jobQueue); controllers.logController = new LogController(commonDependencies); - controllers.statusPageController = new StatusPageController(commonDependencies); + controllers.statusPageController = new StatusPageController(services.db); controllers.notificationController = new NotificationController(services.notificationService, services.db); controllers.diagnosticController = new DiagnosticController(commonDependencies, { diagnosticService: services.diagnosticService, diff --git a/server/src/controllers/v1/statusPageController.js b/server/src/controllers/v1/statusPageController.js deleted file mode 100644 index de6a1ca7c..000000000 --- a/server/src/controllers/v1/statusPageController.js +++ /dev/null @@ -1,108 +0,0 @@ -import { createStatusPageBodyValidation, getStatusPageParamValidation, getStatusPageQueryValidation, imageValidation } from "../../validation/joi.js"; -import BaseController from "./baseController.js"; - -const SERVICE_NAME = "statusPageController"; - -class StatusPageController extends BaseController { - static SERVICE_NAME = SERVICE_NAME; - constructor(commonDependencies) { - super(commonDependencies); - } - - get serviceName() { - return StatusPageController.SERVICE_NAME; - } - - createStatusPage = this.asyncHandler( - async (req, res) => { - await createStatusPageBodyValidation.validateAsync(req.body); - await imageValidation.validateAsync(req.file); - - const { _id, teamId } = req.user; - const statusPage = await this.db.statusPageModule.createStatusPage({ - statusPageData: req.body, - image: req.file, - userId: _id, - teamId, - }); - return res.success({ - msg: this.stringService.statusPageCreate, - data: statusPage, - }); - }, - SERVICE_NAME, - "createStatusPage" - ); - - updateStatusPage = this.asyncHandler( - async (req, res) => { - await createStatusPageBodyValidation.validateAsync(req.body); - await imageValidation.validateAsync(req.file); - - const statusPage = await this.db.statusPageModule.updateStatusPage(req.body, req.file); - if (statusPage === null) { - throw this.errorService.createNotFoundError(this.stringService.statusPageNotFound); - } - return res.success({ - msg: this.stringService.statusPageUpdate, - data: statusPage, - }); - }, - SERVICE_NAME, - "updateStatusPage" - ); - - getStatusPage = this.asyncHandler( - async (req, res) => { - const statusPage = await this.db.statusPageModule.getStatusPage(); - return res.success({ - msg: this.stringService.statusPageByUrl, - data: statusPage, - }); - }, - SERVICE_NAME, - "getStatusPage" - ); - - getStatusPageByUrl = this.asyncHandler( - async (req, res) => { - await getStatusPageParamValidation.validateAsync(req.params); - await getStatusPageQueryValidation.validateAsync(req.query); - - const statusPage = await this.db.statusPageModule.getStatusPageByUrl(req.params.url); - return res.success({ - msg: this.stringService.statusPageByUrl, - data: statusPage, - }); - }, - SERVICE_NAME, - "getStatusPageByUrl" - ); - - getStatusPagesByTeamId = this.asyncHandler( - async (req, res) => { - const teamId = req.user.teamId; - const statusPages = await this.db.statusPageModule.getStatusPagesByTeamId(teamId); - - return res.success({ - msg: this.stringService.statusPageByTeamId, - data: statusPages, - }); - }, - SERVICE_NAME, - "getStatusPagesByTeamId" - ); - - deleteStatusPage = this.asyncHandler( - async (req, res) => { - await this.db.statusPageModule.deleteStatusPage(req.params.url); - return res.success({ - msg: this.stringService.statusPageDelete, - }); - }, - SERVICE_NAME, - "deleteStatusPage" - ); -} - -export default StatusPageController; diff --git a/server/src/controllers/v1/statusPageController.ts b/server/src/controllers/v1/statusPageController.ts new file mode 100644 index 000000000..79e0f5481 --- /dev/null +++ b/server/src/controllers/v1/statusPageController.ts @@ -0,0 +1,109 @@ +import { Request, Response, NextFunction } from "express"; + +import { createStatusPageBodyValidation, getStatusPageParamValidation, getStatusPageQueryValidation, imageValidation } from "@/validation/joi.js"; +import { AppError } from "@/utils/AppError.js"; + +const SERVICE_NAME = "statusPageController"; + +class StatusPageController { + static SERVICE_NAME = SERVICE_NAME; + private db: any; + constructor(db: any) { + this.db = db; + } + + get serviceName() { + return StatusPageController.SERVICE_NAME; + } + + createStatusPage = async (req: Request, res: Response, next: NextFunction) => { + try { + await createStatusPageBodyValidation.validateAsync(req.body); + await imageValidation.validateAsync(req.file); + + const { _id, teamId } = req.user; + const statusPage = await this.db.statusPageModule.createStatusPage({ + statusPageData: req.body, + image: req.file, + userId: _id, + teamId, + }); + return res.status(200).json({ + msg: "Status page created successfully", + data: statusPage, + }); + } catch (error) { + next(error); + } + }; + + updateStatusPage = async (req: Request, res: Response, next: NextFunction) => { + try { + await createStatusPageBodyValidation.validateAsync(req.body); + await imageValidation.validateAsync(req.file); + + const statusPage = await this.db.statusPageModule.updateStatusPage(req.body, req.file); + if (statusPage === null) { + throw new AppError({ message: "Status page not found", status: 404 }); + } + return res.status(200).json({ + msg: "Status page updated successfully", + data: statusPage, + }); + } catch (error) { + next(error); + } + }; + + getStatusPage = async (req: Request, res: Response, next: NextFunction) => { + try { + const statusPage = await this.db.statusPageModule.getStatusPage(); + return res.status(200).json({ + msg: "Status page retrieved successfully", + data: statusPage, + }); + } catch (error) { + next(error); + } + }; + + getStatusPageByUrl = async (req: Request, res: Response, next: NextFunction) => { + try { + await getStatusPageParamValidation.validateAsync(req.params); + await getStatusPageQueryValidation.validateAsync(req.query); + + const statusPage = await this.db.statusPageModule.getStatusPageByUrl(req.params.url); + return res.status(200).json({ + msg: "Status page retrieved successfully", + data: statusPage, + }); + } catch (error) { + next(error); + } + }; + getStatusPagesByTeamId = async (req: Request, res: Response, next: NextFunction) => { + try { + const teamId = req.user.teamId; + const statusPages = await this.db.statusPageModule.getStatusPagesByTeamId(teamId); + + return res.status(200).json({ + msg: "Status pages retrieved successfully", + data: statusPages, + }); + } catch (error) { + next(error); + } + }; + deleteStatusPage = async (req: Request, res: Response, next: NextFunction) => { + try { + await this.db.statusPageModule.deleteStatusPage(req.params.url); + return res.status(200).json({ + msg: "Status page deleted successfully", + }); + } catch (error) { + next(error); + } + }; +} + +export default StatusPageController;