fix validation
This commit is contained in:
1 parent
bfd3eee94d
commit
d8ec8d7775
2 files changed
+37
-34
No files matched your search
@@ -81,7 +81,7 @@ export interface IMonitorService {
|
|||||||
|
|
||||||
// other
|
// other
|
||||||
exportMonitorsToJSON(args: { teamId: string }): Promise<Monitor[]>;
|
exportMonitorsToJSON(args: { teamId: string }): Promise<Monitor[]>;
|
||||||
importMonitorsFromJSON(args: { teamId: string; userId: string; monitors: Monitor[] }): Promise<{ imported: number; errors: string[] }>;
|
importMonitorsFromJSON(args: { teamId: string; userId: string; monitors: Partial<Monitor>[] }): Promise<{ imported: number; errors: string[] }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MonitorService implements IMonitorService {
|
export class MonitorService implements IMonitorService {
|
||||||
@@ -526,22 +526,26 @@ export class MonitorService implements IMonitorService {
|
|||||||
return monitors;
|
return monitors;
|
||||||
};
|
};
|
||||||
|
|
||||||
importMonitorsFromJSON = async ({ teamId, monitors }: { teamId: string; monitors: Monitor[] }): Promise<{ imported: number; errors: string[] }> => {
|
importMonitorsFromJSON = async ({
|
||||||
|
teamId,
|
||||||
|
monitors,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
monitors: Partial<Monitor>[];
|
||||||
|
}): Promise<{ imported: number; errors: string[] }> => {
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
const cleanedMonitors = monitors.map((monitor) => {
|
const cleanedMonitors = monitors.map((monitor) => {
|
||||||
const cleanData = {
|
const cleanData = { ...monitor };
|
||||||
...monitor,
|
delete cleanData.id;
|
||||||
_id: monitor.id,
|
delete cleanData.createdAt;
|
||||||
_createdAt: monitor.createdAt,
|
delete cleanData.updatedAt;
|
||||||
_updatedAt: monitor.updatedAt,
|
delete cleanData.recentChecks;
|
||||||
recentChecks: monitor.recentChecks,
|
|
||||||
};
|
|
||||||
cleanData.teamId = teamId;
|
cleanData.teamId = teamId;
|
||||||
return cleanData;
|
return cleanData;
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdMonitors = await this.createMonitors(cleanedMonitors);
|
const createdMonitors = await this.createMonitors(cleanedMonitors as Monitor[]);
|
||||||
|
|
||||||
if (!createdMonitors || createdMonitors.length === 0) {
|
if (!createdMonitors || createdMonitors.length === 0) {
|
||||||
throw new AppError({
|
throw new AppError({
|
||||||
|
|||||||
@@ -128,39 +128,38 @@ const importedMonitorSchema = z.object({
|
|||||||
teamId: z.string().optional(),
|
teamId: z.string().optional(),
|
||||||
name: z.string().min(1, "Name is required"),
|
name: z.string().min(1, "Name is required"),
|
||||||
description: z.union([z.string(), z.literal("")]).optional(),
|
description: z.union([z.string(), z.literal("")]).optional(),
|
||||||
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).optional(),
|
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).default("initializing"),
|
||||||
statusWindow: z.array(z.boolean()).optional(),
|
statusWindow: z.array(z.boolean()).default([]),
|
||||||
statusWindowSize: z.number().optional(),
|
statusWindowSize: z.number().min(1).max(20).default(5),
|
||||||
statusWindowThreshold: z.number().optional(),
|
statusWindowThreshold: z.number().min(1).max(100).default(60),
|
||||||
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
||||||
ignoreTlsErrors: z.boolean().optional(),
|
ignoreTlsErrors: z.boolean().default(false),
|
||||||
useAdvancedMatching: z.boolean().optional(),
|
useAdvancedMatching: z.boolean().default(false),
|
||||||
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
||||||
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
||||||
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
||||||
url: z.string().min(1, "URL is required"),
|
url: z.string().min(1, "URL is required"),
|
||||||
port: z.number().optional(),
|
port: z.number().optional(),
|
||||||
isActive: z.boolean().optional(),
|
isActive: z.boolean().default(true),
|
||||||
interval: z.number().optional(),
|
interval: z.number().default(60000),
|
||||||
uptimePercentage: z.number().optional(),
|
uptimePercentage: z.number().optional(),
|
||||||
notifications: z.array(z.string()).optional(),
|
notifications: z.array(z.string()).default([]),
|
||||||
secret: z.string().optional(),
|
secret: z.string().optional(),
|
||||||
cpuAlertThreshold: z.number().optional(),
|
cpuAlertThreshold: z.number().default(100),
|
||||||
cpuAlertCounter: z.number().optional(),
|
cpuAlertCounter: z.number().default(5),
|
||||||
memoryAlertThreshold: z.number().optional(),
|
memoryAlertThreshold: z.number().default(100),
|
||||||
memoryAlertCounter: z.number().optional(),
|
memoryAlertCounter: z.number().default(5),
|
||||||
diskAlertThreshold: z.number().optional(),
|
diskAlertThreshold: z.number().default(100),
|
||||||
diskAlertCounter: z.number().optional(),
|
diskAlertCounter: z.number().default(5),
|
||||||
tempAlertThreshold: z.number().optional(),
|
tempAlertThreshold: z.number().default(100),
|
||||||
tempAlertCounter: z.number().optional(),
|
tempAlertCounter: z.number().default(5),
|
||||||
selectedDisks: z.array(z.string()).optional(),
|
selectedDisks: z.array(z.string()).default([]),
|
||||||
gameId: z.union([z.string(), z.literal("")]).optional(),
|
gameId: z.union([z.string(), z.literal("")]).optional(),
|
||||||
grpcServiceName: z.union([z.string(), z.literal("")]).optional(),
|
grpcServiceName: z.union([z.string(), z.literal("")]).default(""),
|
||||||
group: z.union([z.string(), z.null()]).optional(),
|
group: z.union([z.string().max(50).trim(), z.null()]).default(null),
|
||||||
geoCheckEnabled: z.boolean().optional(),
|
geoCheckEnabled: z.boolean().default(false),
|
||||||
geoCheckLocations: z.array(z.enum(GeoContinents)).optional(),
|
geoCheckLocations: z.array(z.enum(GeoContinents)).default([]),
|
||||||
geoCheckInterval: z.number().optional(),
|
geoCheckInterval: z.number().min(300000).default(300000),
|
||||||
recentChecks: z.array(z.unknown()).optional(),
|
|
||||||
createdAt: z.string().optional(),
|
createdAt: z.string().optional(),
|
||||||
updatedAt: z.string().optional(),
|
updatedAt: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user