js->ts
This commit is contained in:
1 parent
1d7f3b15a4
commit
3ab4fcb277
5 files changed
+82
-66
No files matched your search
@@ -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);
|
||||
|
||||
+66
-62
@@ -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;
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user