diff --git a/server/src/controllers/authController.ts b/server/src/controllers/authController.ts index 6eb49bbdd..20303b4eb 100755 --- a/server/src/controllers/authController.ts +++ b/server/src/controllers/authController.ts @@ -23,7 +23,24 @@ import { IUserService } from "@/service/index.js"; const SERVICE_NAME = "authController"; -class AuthController { +export interface IAuthController { + registerUser(req: Request, res: Response, next: NextFunction): Promise; + createUser(req: Request, res: Response, next: NextFunction): Promise; + loginUser(req: Request, res: Response, next: NextFunction): Promise; + editUser(req: Request, res: Response, next: NextFunction): Promise; + checkSuperadminExists(req: Request, res: Response, next: NextFunction): Promise; + requestRecovery(req: Request, res: Response, next: NextFunction): Promise; + validateRecovery(req: Request, res: Response, next: NextFunction): Promise; + resetPassword(req: Request, res: Response, next: NextFunction): Promise; + deleteUser(req: Request, res: Response, next: NextFunction): Promise; + deleteUserById(req: Request, res: Response, next: NextFunction): Promise; + getAllUsers(req: Request, res: Response, next: NextFunction): Promise; + getUserById(req: Request, res: Response, next: NextFunction): Promise; + editUserById(req: Request, res: Response, next: NextFunction): Promise; + editUserPasswordById(req: Request, res: Response, next: NextFunction): Promise; +} + +class AuthController implements IAuthController { static SERVICE_NAME = SERVICE_NAME; private userService: IUserService; diff --git a/server/src/controllers/checkController.ts b/server/src/controllers/checkController.ts index 879ceaffe..dfe64e80a 100755 --- a/server/src/controllers/checkController.ts +++ b/server/src/controllers/checkController.ts @@ -12,7 +12,16 @@ import { requireTeamId } from "@/controllers/controllerUtils.js"; const SERVICE_NAME = "checkController"; -class CheckController { +export interface ICheckController { + serviceName: string; + getChecksByMonitor: (req: Request, res: Response, next: NextFunction) => Promise; + getChecksByTeam: (req: Request, res: Response, next: NextFunction) => Promise; + getChecksSummaryByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; + deleteChecks: (req: Request, res: Response, next: NextFunction) => Promise; + deleteChecksByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; +} + +class CheckController implements ICheckController { static SERVICE_NAME = SERVICE_NAME; private checkService: ICheckService; diff --git a/server/src/controllers/diagnosticController.ts b/server/src/controllers/diagnosticController.ts index 19326d3b3..ffe7c6f5f 100755 --- a/server/src/controllers/diagnosticController.ts +++ b/server/src/controllers/diagnosticController.ts @@ -2,7 +2,12 @@ import { IDiagnosticService } from "@/service/index.js"; import { Request, Response, NextFunction } from "express"; const SERVICE_NAME = "diagnosticController"; -class DiagnosticController { + +export interface IDiagnosticController { + getSystemStats: (req: Request, res: Response, next: NextFunction) => Promise; +} + +class DiagnosticController implements IDiagnosticController { static SERVICE_NAME = SERVICE_NAME; private diagnosticService: IDiagnosticService; diff --git a/server/src/controllers/geoCheckController.ts b/server/src/controllers/geoCheckController.ts index aef0d7e7c..8ac130459 100644 --- a/server/src/controllers/geoCheckController.ts +++ b/server/src/controllers/geoCheckController.ts @@ -6,7 +6,10 @@ import { AppError } from "@/utils/AppError.js"; const SERVICE_NAME = "geoCheckController"; -class GeoCheckController { +export interface IGeoCheckController { + getGeoChecksByMonitor: (req: Request, res: Response, next: NextFunction) => Promise; +} +class GeoCheckController implements IGeoCheckController { static SERVICE_NAME = SERVICE_NAME; private geoChecksService: IGeoChecksService; diff --git a/server/src/controllers/incidentController.ts b/server/src/controllers/incidentController.ts index 4e6242184..f12327541 100644 --- a/server/src/controllers/incidentController.ts +++ b/server/src/controllers/incidentController.ts @@ -5,7 +5,14 @@ import { IIncidentService } from "@/service/index.js"; import { getIncidentsByTeamQueryValidation, getIncidentSummaryQueryValidation } from "@/validation/incidentValidation.js"; const SERVICE_NAME = "IncidentController"; -class IncidentController { + +export interface IIncidentController { + getIncidentsByTeam: (req: Request, res: Response, next: NextFunction) => Promise; + getIncidentSummary: (req: Request, res: Response, next: NextFunction) => Promise; + getIncidentById: (req: Request, res: Response, next: NextFunction) => Promise; + resolveIncidentManually: (req: Request, res: Response, next: NextFunction) => Promise; +} +class IncidentController implements IIncidentController { private incidentService: IIncidentService; constructor(incidentService: IIncidentService) { this.incidentService = incidentService; diff --git a/server/src/controllers/inviteController.ts b/server/src/controllers/inviteController.ts index 84f6c30ae..700a7bc6a 100755 --- a/server/src/controllers/inviteController.ts +++ b/server/src/controllers/inviteController.ts @@ -4,7 +4,13 @@ import { requireFirstName, requireTeamId, requireUserRoles } from "@/controllers import { IInviteService } from "@/service/index.js"; const SERVICE_NAME = "inviteController"; -class InviteController { +export interface IInviteController { + getInviteToken: (req: Request, res: Response, next: NextFunction) => Promise; + sendInviteEmail: (req: Request, res: Response, next: NextFunction) => Promise; + verifyInviteToken: (req: Request, res: Response, next: NextFunction) => Promise; +} + +class InviteController implements IInviteController { static SERVICE_NAME = SERVICE_NAME; private inviteService: IInviteService; constructor(inviteService: IInviteService) { diff --git a/server/src/controllers/logController.ts b/server/src/controllers/logController.ts index e26bc2e5e..7d221c6c5 100644 --- a/server/src/controllers/logController.ts +++ b/server/src/controllers/logController.ts @@ -3,6 +3,10 @@ import { Request, Response, NextFunction } from "express"; const SERVICE_NAME = "LogController"; +export interface ILogController { + getLogs: (req: Request, res: Response, next: NextFunction) => Promise; +} + class LogController { static SERVICE_NAME = SERVICE_NAME; private logger: ILogger; diff --git a/server/src/controllers/maintenanceWindowController.ts b/server/src/controllers/maintenanceWindowController.ts index 300cb0b1b..441acfa80 100644 --- a/server/src/controllers/maintenanceWindowController.ts +++ b/server/src/controllers/maintenanceWindowController.ts @@ -11,7 +11,15 @@ import { import { requireTeamId } from "@/controllers/controllerUtils.js"; import { IMaintenanceWindowService } from "@/service/index.js"; -class MaintenanceWindowController { +export interface IMaintenanceWindowController { + createMaintenanceWindows: (req: Request, res: Response, next: NextFunction) => Promise; + getMaintenanceWindowById: (req: Request, res: Response, next: NextFunction) => Promise; + getMaintenanceWindowsByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; + getMaintenanceWindowsByMonitorId: (req: Request, res: Response, next: NextFunction) => Promise; + deleteMaintenanceWindow: (req: Request, res: Response, next: NextFunction) => Promise; + editMaintenanceWindow: (req: Request, res: Response, next: NextFunction) => Promise; +} +class MaintenanceWindowController implements IMaintenanceWindowController { private maintenanceWindowService: IMaintenanceWindowService; constructor(maintenanceWindowService: IMaintenanceWindowService) { this.maintenanceWindowService = maintenanceWindowService; diff --git a/server/src/controllers/monitorController.ts b/server/src/controllers/monitorController.ts index 9a2b7b774..b3b03ed57 100644 --- a/server/src/controllers/monitorController.ts +++ b/server/src/controllers/monitorController.ts @@ -16,11 +16,32 @@ import { importMonitorsBodyValidation, } from "@/validation/monitorValidation.js"; import sslChecker from "ssl-checker"; -import { fetchMonitorCertificate, requireTeamId, requireUserId } from "./controllerUtils.js"; +import { fetchMonitorCertificate, requireTeamId, requireUserId } from "@/controllers/controllerUtils.js"; import { IMonitorService } from "@/service/index.js"; const SERVICE_NAME = "monitorController"; -class MonitorController { + +export interface IMonitorController { + getMonitorCertificate: (req: Request, res: Response, next: NextFunction) => Promise; + getUptimeDetailsById: (req: Request, res: Response, next: NextFunction) => Promise; + getHardwareDetailsById: (req: Request, res: Response, next: NextFunction) => Promise; + getPageSpeedDetailsById: (req: Request, res: Response, next: NextFunction) => Promise; + getGeoChecksByMonitorId: (req: Request, res: Response, next: NextFunction) => Promise; + getMonitorById: (req: Request, res: Response, next: NextFunction) => Promise; + createMonitor: (req: Request, res: Response, next: NextFunction) => Promise; + importMonitorsFromJSON: (req: Request, res: Response, next: NextFunction) => Promise; + deleteMonitor: (req: Request, res: Response, next: NextFunction) => Promise; + deleteAllMonitors: (req: Request, res: Response, next: NextFunction) => Promise; + editMonitor: (req: Request, res: Response, next: NextFunction) => Promise; + pauseMonitor: (req: Request, res: Response, next: NextFunction) => Promise; + addDemoMonitors: (req: Request, res: Response, next: NextFunction) => Promise; + getMonitorsByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; + getMonitorsWithChecksByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; + exportMonitorsToJSON: (req: Request, res: Response, next: NextFunction) => Promise; + getAllGames: (req: Request, res: Response, next: NextFunction) => Promise; + getGroupsByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; +} +class MonitorController implements IMonitorController { static SERVICE_NAME = SERVICE_NAME; private monitorService: IMonitorService; diff --git a/server/src/controllers/notificationController.ts b/server/src/controllers/notificationController.ts index 9c39daee7..979e4afc9 100644 --- a/server/src/controllers/notificationController.ts +++ b/server/src/controllers/notificationController.ts @@ -15,7 +15,16 @@ import { requireTeamId, requireUserId } from "./controllerUtils.js"; const SERVICE_NAME = "NotificationController"; -class NotificationController { +export interface INotificationController { + testNotification: (req: Request, res: Response, next: NextFunction) => Promise; + createNotification: (req: Request, res: Response, next: NextFunction) => Promise; + getNotificationsByTeamId: (req: Request, res: Response, next: NextFunction) => Promise; + deleteNotification: (req: Request, res: Response, next: NextFunction) => Promise; + getNotificationById: (req: Request, res: Response, next: NextFunction) => Promise; + editNotification: (req: Request, res: Response, next: NextFunction) => Promise; + testAllNotifications: (req: Request, res: Response, next: NextFunction) => Promise; +} +class NotificationController implements INotificationController { private notificationsService: INotificationsService; private monitorsRepository: IMonitorsRepository; constructor(notificationsService: INotificationsService, monitorsRepository: IMonitorsRepository) { diff --git a/server/src/controllers/queueController.ts b/server/src/controllers/queueController.ts index 9ae2b494a..52762f42b 100755 --- a/server/src/controllers/queueController.ts +++ b/server/src/controllers/queueController.ts @@ -3,7 +3,14 @@ import { Request, Response, NextFunction } from "express"; const SERVICE_NAME = "JobQueueController"; -class JobQueueController { +export interface IJobQueueController { + getMetrics(req: Request, res: Response, next: NextFunction): Promise; + getJobs(req: Request, res: Response, next: NextFunction): Promise; + getAllMetrics(req: Request, res: Response, next: NextFunction): Promise; + flushQueue(req: Request, res: Response, next: NextFunction): Promise; +} + +class JobQueueController implements IJobQueueController { static SERVICE_NAME = SERVICE_NAME; private jobQueue: ISuperSimpleQueue; constructor(jobQueue: ISuperSimpleQueue) { diff --git a/server/src/controllers/settingsController.ts b/server/src/controllers/settingsController.ts index 0fd82a8ac..ca011889f 100644 --- a/server/src/controllers/settingsController.ts +++ b/server/src/controllers/settingsController.ts @@ -6,7 +6,14 @@ import { IEmailService, ISettingsService } from "@/service/index.js"; const SERVICE_NAME = "SettingsController"; -class SettingsController { +export interface ISettingsController { + serviceName: string; + getAppSettings(req: Request, res: Response, next: NextFunction): Promise; + updateAppSettings(req: Request, res: Response, next: NextFunction): Promise; + sendTestEmail(req: Request, res: Response, next: NextFunction): Promise; +} + +class SettingsController implements ISettingsController { static SERVICE_NAME = SERVICE_NAME; private settingsService: ISettingsService; private emailService: IEmailService; diff --git a/server/src/controllers/statusPageController.ts b/server/src/controllers/statusPageController.ts index 8593cd53f..0c73b6e3b 100644 --- a/server/src/controllers/statusPageController.ts +++ b/server/src/controllers/statusPageController.ts @@ -15,7 +15,16 @@ import { NormalizeData } from "@/utils/dataUtils.js"; const SERVICE_NAME = "statusPageController"; -class StatusPageController { +export interface IStatusPageController { + readonly serviceName: string; + createStatusPage(req: Request, res: Response, next: NextFunction): Promise; + updateStatusPage(req: Request, res: Response, next: NextFunction): Promise; + getStatusPageByUrl(req: Request, res: Response, next: NextFunction): Promise; + getStatusPagesByTeamId(req: Request, res: Response, next: NextFunction): Promise; + deleteStatusPage(req: Request, res: Response, next: NextFunction): Promise; +} + +class StatusPageController implements IStatusPageController { static SERVICE_NAME = SERVICE_NAME; private statusPageService: IStatusPageService; private monitorsRepository: IMonitorsRepository; @@ -66,7 +75,7 @@ class StatusPageController { if (statusPage === null) { throw new AppError({ message: "Status page not found", status: 404 }); } - return res.status(200).json({ + res.status(200).json({ success: true, msg: "Status page updated successfully", data: statusPage, diff --git a/server/src/routes/authRoute.ts b/server/src/routes/authRoute.ts index 2e5fa1069..fd951c6b1 100755 --- a/server/src/routes/authRoute.ts +++ b/server/src/routes/authRoute.ts @@ -1,14 +1,15 @@ import { Router, RequestHandler } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; import multer from "multer"; +import { IAuthController } from "@/controllers/authController.js"; const upload = multer(); class AuthRoutes { private router: Router; - private authController: any; + private authController: IAuthController; - constructor(authController: any, verifyJWT: RequestHandler) { + constructor(authController: IAuthController, verifyJWT: RequestHandler) { this.router = Router(); this.authController = authController; this.initRoutes(verifyJWT); diff --git a/server/src/routes/checkRoute.ts b/server/src/routes/checkRoute.ts index 71a0cd5f3..712bae969 100755 --- a/server/src/routes/checkRoute.ts +++ b/server/src/routes/checkRoute.ts @@ -1,12 +1,13 @@ import { Router } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; +import { ICheckController } from "@/controllers/checkController.js"; class CheckRoutes { private router: Router; - private checkController: any; + private checkController: ICheckController; - constructor(checkController: any) { + constructor(checkController: ICheckController) { this.router = Router(); this.checkController = checkController; this.initRoutes(); diff --git a/server/src/routes/diagnosticRoute.ts b/server/src/routes/diagnosticRoute.ts index b2cefe4aa..32b857e8d 100755 --- a/server/src/routes/diagnosticRoute.ts +++ b/server/src/routes/diagnosticRoute.ts @@ -1,11 +1,12 @@ import { RequestHandler, Router } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; +import { IDiagnosticController } from "@/controllers/diagnosticController.js"; class DiagnosticRoutes { private router: Router; - private diagnosticController: any; + private diagnosticController: IDiagnosticController; - constructor(diagnosticController: any, verifyJWT: RequestHandler) { + constructor(diagnosticController: IDiagnosticController, verifyJWT: RequestHandler) { this.router = Router(); this.diagnosticController = diagnosticController; this.initRoutes(verifyJWT); diff --git a/server/src/routes/geoCheckRoutes.ts b/server/src/routes/geoCheckRoutes.ts index 4c34df56e..1fc48d7b3 100644 --- a/server/src/routes/geoCheckRoutes.ts +++ b/server/src/routes/geoCheckRoutes.ts @@ -1,10 +1,11 @@ +import { IGeoCheckController } from "@/controllers/geoCheckController.js"; import { Router } from "express"; class GeoCheckRoutes { private router: Router; - private geoCheckController: any; + private geoCheckController: IGeoCheckController; - constructor(geoCheckController: any) { + constructor(geoCheckController: IGeoCheckController) { this.router = Router(); this.geoCheckController = geoCheckController; this.initRoutes(); diff --git a/server/src/routes/incidentRoute.ts b/server/src/routes/incidentRoute.ts index 83f1ff8f9..fdbb6f532 100644 --- a/server/src/routes/incidentRoute.ts +++ b/server/src/routes/incidentRoute.ts @@ -1,11 +1,12 @@ import { Router } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; +import { IIncidentController } from "@/controllers/incidentController.js"; class IncidentRoutes { private router: Router; - private incidentController: any; + private incidentController: IIncidentController; - constructor(incidentController: any) { + constructor(incidentController: IIncidentController) { this.router = Router(); this.incidentController = incidentController; this.initRoutes(); diff --git a/server/src/routes/inviteRoute.ts b/server/src/routes/inviteRoute.ts index b91f922df..4542bd21e 100755 --- a/server/src/routes/inviteRoute.ts +++ b/server/src/routes/inviteRoute.ts @@ -1,11 +1,12 @@ import { RequestHandler, Router } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; +import { IInviteController } from "@/controllers/inviteController.js"; class InviteRoutes { private router: Router; - private inviteController: any; + private inviteController: IInviteController; - constructor(inviteController: any, verifyJWT: RequestHandler) { + constructor(inviteController: IInviteController, verifyJWT: RequestHandler) { this.router = Router(); this.inviteController = inviteController; this.initRoutes(verifyJWT); diff --git a/server/src/routes/logRoutes.ts b/server/src/routes/logRoutes.ts index c35361fd0..ea03d690e 100755 --- a/server/src/routes/logRoutes.ts +++ b/server/src/routes/logRoutes.ts @@ -1,10 +1,11 @@ import { Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; +import { isAllowed } from "@/middleware/isAllowed.js"; +import { ILogController } from "@/controllers/logController.js"; class LogRoutes { private router: Router; - private logController: any; + private logController: ILogController; - constructor(logController: any) { + constructor(logController: ILogController) { this.router = Router(); this.logController = logController; this.initRoutes(); diff --git a/server/src/routes/maintenanceWindowRoute.ts b/server/src/routes/maintenanceWindowRoute.ts index 539f2413f..1c2c139c0 100755 --- a/server/src/routes/maintenanceWindowRoute.ts +++ b/server/src/routes/maintenanceWindowRoute.ts @@ -1,10 +1,11 @@ +import { IMaintenanceWindowController } from "@/controllers/maintenanceWindowController.js"; import { Router } from "express"; class MaintenanceWindowRoutes { private router: Router; - private mwController: any; + private mwController: IMaintenanceWindowController; - constructor(maintenanceWindowController: any) { + constructor(maintenanceWindowController: IMaintenanceWindowController) { this.router = Router(); this.mwController = maintenanceWindowController; this.initRoutes(); diff --git a/server/src/routes/monitorRoute.ts b/server/src/routes/monitorRoute.ts index 7cd87ee1e..2e994fd01 100755 --- a/server/src/routes/monitorRoute.ts +++ b/server/src/routes/monitorRoute.ts @@ -1,15 +1,11 @@ import { Router } from "express"; import { isAllowed } from "@/middleware/isAllowed.js"; -import multer from "multer"; -import { fetchMonitorCertificate } from "@/controllers/controllerUtils.js"; -const upload = multer({ - storage: multer.memoryStorage(), // Store file in memory as Buffer -}); +import { IMonitorController } from "@/controllers/monitorController.js"; class MonitorRoutes { private router: Router; - private monitorController: any; - constructor(monitorController: any) { + private monitorController: IMonitorController; + constructor(monitorController: IMonitorController) { this.router = Router(); this.monitorController = monitorController; this.initRoutes(); @@ -38,7 +34,7 @@ class MonitorRoutes { // Util routes this.router.get("/certificate/:monitorId", (req, res, next) => { - this.monitorController.getMonitorCertificate(req, res, next, fetchMonitorCertificate); + this.monitorController.getMonitorCertificate(req, res, next); }); // General monitor CRUD routes diff --git a/server/src/routes/notificationRoute.ts b/server/src/routes/notificationRoute.ts index a1802d3b9..4ec6ce3b6 100755 --- a/server/src/routes/notificationRoute.ts +++ b/server/src/routes/notificationRoute.ts @@ -1,9 +1,10 @@ +import { INotificationController } from "@/controllers/notificationController.js"; import { Router } from "express"; class NotificationRoutes { private router: Router; - private notificationController: any; + private notificationController: INotificationController; - constructor(notificationController: any) { + constructor(notificationController: INotificationController) { this.router = Router(); this.notificationController = notificationController; this.initializeRoutes(); diff --git a/server/src/routes/queueRoute.ts b/server/src/routes/queueRoute.ts index dd3b27999..d5d35147c 100755 --- a/server/src/routes/queueRoute.ts +++ b/server/src/routes/queueRoute.ts @@ -1,10 +1,11 @@ import { Router } from "express"; -import { isAllowed } from "../middleware/isAllowed.js"; +import { isAllowed } from "@/middleware/isAllowed.js"; +import { IJobQueueController } from "@/controllers/queueController.js"; class QueueRoutes { private router: Router; - private queueController: any; + private queueController: IJobQueueController; - constructor(queueController: any) { + constructor(queueController: IJobQueueController) { this.router = Router(); this.queueController = queueController; this.initRoutes(); diff --git a/server/src/routes/settingsRoute.ts b/server/src/routes/settingsRoute.ts index c03c17524..aec2319c2 100755 --- a/server/src/routes/settingsRoute.ts +++ b/server/src/routes/settingsRoute.ts @@ -1,11 +1,12 @@ import { Router } from "express"; import { isAllowed } from "../middleware/isAllowed.js"; +import { ISettingsController } from "@/controllers/settingsController.js"; class SettingsRoutes { private router: Router; - private settingsController: any; + private settingsController: ISettingsController; - constructor(settingsController: any) { + constructor(settingsController: ISettingsController) { this.router = Router(); this.settingsController = settingsController; this.initRoutes(); diff --git a/server/src/routes/statusPageRoute.ts b/server/src/routes/statusPageRoute.ts index a53aa04d9..871a67300 100755 --- a/server/src/routes/statusPageRoute.ts +++ b/server/src/routes/statusPageRoute.ts @@ -1,12 +1,13 @@ +import { IStatusPageController } from "@/controllers/statusPageController.js"; import { RequestHandler, Router } from "express"; import multer from "multer"; const upload = multer(); class StatusPageRoutes { private router: Router; - private statusPageController: any; + private statusPageController: IStatusPageController; - constructor(statusPageController: any, verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) { + constructor(statusPageController: IStatusPageController, verifyJWT: RequestHandler, verifyStatusPageAccess: RequestHandler) { this.router = Router(); this.statusPageController = statusPageController; this.initRoutes(verifyJWT, verifyStatusPageAccess);