validation refactoring
This commit is contained in:
1 parent
c3a41272a3
commit
a5d3c95145
7 files changed
+53
-74
No files matched your search
@@ -7,9 +7,6 @@ import {
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
updateChecksTTLBodyValidation,
|
||||
ackCheckBodyValidation,
|
||||
ackAllChecksParamValidation,
|
||||
ackAllChecksBodyValidation,
|
||||
} from "@/validation/checkValidation.js";
|
||||
|
||||
const SERVICE_NAME = "checkController";
|
||||
@@ -28,8 +25,8 @@ class CheckController {
|
||||
|
||||
getChecksByMonitor = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await getChecksParamValidation.validateAsync(req.params);
|
||||
await getChecksQueryValidation.validateAsync(req.query);
|
||||
getChecksParamValidation.parse(req.params);
|
||||
getChecksQueryValidation.parse(req.query);
|
||||
|
||||
const result = await this.checkService.getChecksByMonitor({
|
||||
monitorId: req?.params?.monitorId,
|
||||
@@ -49,7 +46,7 @@ class CheckController {
|
||||
|
||||
getChecksByTeam = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await getTeamChecksQueryValidation.validateAsync(req.query);
|
||||
getTeamChecksQueryValidation.parse(req.query);
|
||||
const checkData = await this.checkService.getChecksByTeam({
|
||||
teamId: req?.user?.teamId,
|
||||
query: req?.query,
|
||||
@@ -80,7 +77,7 @@ class CheckController {
|
||||
|
||||
deleteChecks = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await deleteChecksParamValidation.validateAsync(req.params);
|
||||
deleteChecksParamValidation.parse(req.params);
|
||||
|
||||
const deletedCount = await this.checkService.deleteChecks({
|
||||
monitorId: req.params.monitorId as string,
|
||||
@@ -99,7 +96,7 @@ class CheckController {
|
||||
|
||||
deleteChecksByTeamId = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await deleteChecksByTeamIdParamValidation.validateAsync(req.params);
|
||||
deleteChecksByTeamIdParamValidation.parse(req.params);
|
||||
|
||||
const deletedCount = await this.checkService.deleteChecksByTeamId({ teamId: req?.user?.teamId });
|
||||
|
||||
@@ -115,7 +112,7 @@ class CheckController {
|
||||
|
||||
updateChecksTTL = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await updateChecksTTLBodyValidation.validateAsync(req.body);
|
||||
updateChecksTTLBodyValidation.parse(req.body);
|
||||
|
||||
await this.checkService.updateChecksTTL({
|
||||
teamId: req?.user?.teamId,
|
||||
|
||||
@@ -18,8 +18,8 @@ class GeoCheckController {
|
||||
|
||||
getGeoChecksByMonitor = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await getChecksParamValidation.validateAsync(req.params);
|
||||
await getChecksQueryValidation.validateAsync(req.query);
|
||||
getChecksParamValidation.parse(req.params);
|
||||
getChecksQueryValidation.parse(req.query);
|
||||
|
||||
const result = await this.geoChecksService.getGeoChecksByMonitor({
|
||||
monitorId: req?.params?.monitorId as string,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { updateAppSettingsBodyValidation } from "@/validation/settingsValidation.js";
|
||||
import { sendTestEmailBodyValidation } from "@/validation/announcementValidation.js";
|
||||
import { sendTestEmailBodyValidation } from "@/validation/notificationValidation.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
|
||||
const SERVICE_NAME = "SettingsController";
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
//****************************************
|
||||
// Announcement Validations
|
||||
//****************************************
|
||||
|
||||
export const sendTestEmailBodyValidation = z.object({
|
||||
to: z.string().min(1, "To field is required"),
|
||||
systemEmailHost: z.string().optional(),
|
||||
systemEmailPort: z.number().optional(),
|
||||
systemEmailSecure: z.boolean().optional(),
|
||||
systemEmailPool: z.boolean().optional(),
|
||||
systemEmailAddress: z.string().optional(),
|
||||
systemEmailPassword: z.string().optional(),
|
||||
systemEmailUser: z.string().optional(),
|
||||
systemEmailConnectionHost: z.union([z.string(), z.literal("")]).optional(),
|
||||
systemEmailIgnoreTLS: z.boolean().optional(),
|
||||
systemEmailRequireTLS: z.boolean().optional(),
|
||||
systemEmailRejectUnauthorized: z.boolean().optional(),
|
||||
systemEmailTLSServername: z.union([z.string(), z.literal("")]).optional(),
|
||||
});
|
||||
@@ -1,56 +1,43 @@
|
||||
import joi from "joi";
|
||||
import { z } from "zod";
|
||||
import { GeoContinents } from "@/types/geoCheck.js";
|
||||
|
||||
//****************************************
|
||||
// Check Validations
|
||||
//****************************************
|
||||
|
||||
export const ackCheckBodyValidation = joi.object({
|
||||
ack: joi.boolean(),
|
||||
export const getChecksParamValidation = z.object({
|
||||
monitorId: z.string().min(1, "Monitor ID is required"),
|
||||
});
|
||||
|
||||
export const ackAllChecksParamValidation = joi.object({
|
||||
monitorId: joi.string().optional(),
|
||||
path: joi.string().valid("monitor", "team").required(),
|
||||
export const getChecksQueryValidation = z.object({
|
||||
type: z.enum(["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc"]).optional(),
|
||||
sortOrder: z.enum(["asc", "desc"]).optional(),
|
||||
limit: z.number().optional(),
|
||||
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(),
|
||||
filter: z.enum(["all", "up", "down", "resolve"]).optional(),
|
||||
ack: z.boolean().optional(),
|
||||
page: z.number().optional(),
|
||||
rowsPerPage: z.number().optional(),
|
||||
status: z.boolean().optional(),
|
||||
continent: z.union([z.enum(GeoContinents), z.array(z.enum(GeoContinents))]).optional(),
|
||||
});
|
||||
|
||||
export const ackAllChecksBodyValidation = joi.object({
|
||||
ack: joi.boolean(),
|
||||
export const getTeamChecksQueryValidation = z.object({
|
||||
sortOrder: z.enum(["asc", "desc"]).optional(),
|
||||
limit: z.number().optional(),
|
||||
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(),
|
||||
filter: z.enum(["all", "up", "down", "resolve"]).optional(),
|
||||
ack: z.boolean().optional(),
|
||||
page: z.number().optional(),
|
||||
rowsPerPage: z.number().optional(),
|
||||
});
|
||||
|
||||
export const getChecksParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
export const deleteChecksParamValidation = z.object({
|
||||
monitorId: z.string().min(1, "Monitor ID is required"),
|
||||
});
|
||||
|
||||
export const getChecksQueryValidation = joi.object({
|
||||
type: joi.string().valid("http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc"),
|
||||
sortOrder: joi.string().valid("asc", "desc"),
|
||||
limit: joi.number(),
|
||||
dateRange: joi.string().valid("recent", "hour", "day", "week", "month", "all"),
|
||||
filter: joi.string().valid("all", "up", "down", "resolve"),
|
||||
ack: joi.boolean(),
|
||||
page: joi.number(),
|
||||
rowsPerPage: joi.number(),
|
||||
status: joi.boolean(),
|
||||
continent: joi.alternatives().try(joi.string().valid(...GeoContinents), joi.array().items(joi.string().valid(...GeoContinents))),
|
||||
});
|
||||
export const deleteChecksByTeamIdParamValidation = z.object({});
|
||||
|
||||
export const getTeamChecksQueryValidation = joi.object({
|
||||
sortOrder: joi.string().valid("asc", "desc"),
|
||||
limit: joi.number(),
|
||||
dateRange: joi.string().valid("recent", "hour", "day", "week", "month", "all"),
|
||||
filter: joi.string().valid("all", "up", "down", "resolve"),
|
||||
ack: joi.boolean(),
|
||||
page: joi.number(),
|
||||
rowsPerPage: joi.number(),
|
||||
});
|
||||
|
||||
export const deleteChecksParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
export const deleteChecksByTeamIdParamValidation = joi.object({});
|
||||
|
||||
export const updateChecksTTLBodyValidation = joi.object({
|
||||
ttl: joi.number().required(),
|
||||
export const updateChecksTTLBodyValidation = z.object({
|
||||
ttl: z.number().min(1, "TTL is required"),
|
||||
});
|
||||
@@ -16,5 +16,4 @@ export * from "./maintenanceWindowValidation.js";
|
||||
export * from "./settingsValidation.js";
|
||||
export * from "./statusPageValidation.js";
|
||||
export * from "./notificationValidation.js";
|
||||
export * from "./announcementValidation.js";
|
||||
export * from "./userValidation.js";
|
||||
@@ -1,4 +1,5 @@
|
||||
import joi from "joi";
|
||||
import { z } from "zod";
|
||||
|
||||
//****************************************
|
||||
// Notification Validations
|
||||
@@ -76,3 +77,19 @@ export const createNotificationBodyValidation = joi.object({
|
||||
otherwise: joi.string().allow("").optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const sendTestEmailBodyValidation = z.object({
|
||||
to: z.string().min(1, "To field is required"),
|
||||
systemEmailHost: z.string().optional(),
|
||||
systemEmailPort: z.number().optional(),
|
||||
systemEmailSecure: z.boolean().optional(),
|
||||
systemEmailPool: z.boolean().optional(),
|
||||
systemEmailAddress: z.string().optional(),
|
||||
systemEmailPassword: z.string().optional(),
|
||||
systemEmailUser: z.string().optional(),
|
||||
systemEmailConnectionHost: z.union([z.string(), z.literal("")]).optional(),
|
||||
systemEmailIgnoreTLS: z.boolean().optional(),
|
||||
systemEmailRequireTLS: z.boolean().optional(),
|
||||
systemEmailRejectUnauthorized: z.boolean().optional(),
|
||||
systemEmailTLSServername: z.union([z.string(), z.literal("")]).optional(),
|
||||
});
|
||||
Reference in new issue
Block a user