Merge pull request #3998 from bluewave-labs/chore/cleanup-controller-utils
chore: remove dead code
This commit is contained in:
1 file changed
+1
-64
@@ -1,5 +1,5 @@
|
|||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { Monitor, MonitorTypes, type MonitorType } from "@/domain/monitors/monitor.type.js";
|
import { Monitor } from "@/domain/monitors/monitor.type.js";
|
||||||
import { UserRole } from "@/domain/users/user.type.js";
|
import { UserRole } from "@/domain/users/user.type.js";
|
||||||
import sslChecker, { SSLDetails } from "ssl-checker";
|
import sslChecker, { SSLDetails } from "ssl-checker";
|
||||||
import * as whoiser from "whoiser";
|
import * as whoiser from "whoiser";
|
||||||
@@ -124,23 +124,6 @@ export const fetchMonitorDomain = async (
|
|||||||
return domainExpiry;
|
return domainExpiry;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const requireString = (value: unknown, fieldName: string): string => {
|
|
||||||
if (typeof value === "string" && value.trim().length > 0) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
throw new AppError({ message: `${fieldName} is required`, status: 400 });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const optionalString = (value: unknown, fieldName: string): string | undefined => {
|
|
||||||
if (value === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
throw new AppError({ message: `${fieldName} must be a string`, status: 400 });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const extractString = (value: unknown): string | undefined => {
|
export const extractString = (value: unknown): string | undefined => {
|
||||||
const candidate = Array.isArray(value) ? value[0] : value;
|
const candidate = Array.isArray(value) ? value[0] : value;
|
||||||
if (typeof candidate !== "string" || candidate.length === 0) {
|
if (typeof candidate !== "string" || candidate.length === 0) {
|
||||||
@@ -149,52 +132,6 @@ export const extractString = (value: unknown): string | undefined => {
|
|||||||
return candidate;
|
return candidate;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const optionalNumber = (value: unknown, fieldName: string): number | undefined => {
|
|
||||||
if (value === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (typeof value === "number" && Number.isFinite(value)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
if (typeof value === "string" && value.trim() !== "") {
|
|
||||||
const parsed = Number(value);
|
|
||||||
if (!Number.isNaN(parsed)) {
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new AppError({ message: `${fieldName} must be a number`, status: 400 });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const parseMonitorTypeFilter = (value: unknown): MonitorType | MonitorType[] | undefined => {
|
|
||||||
const parseSingle = (input: unknown): MonitorType => {
|
|
||||||
if (typeof input !== "string") {
|
|
||||||
throw new AppError({ message: "Monitor type must be a string", status: 400 });
|
|
||||||
}
|
|
||||||
if (!MonitorTypes.includes(input as MonitorType)) {
|
|
||||||
throw new AppError({ message: `Invalid monitor type: ${input}`, status: 400 });
|
|
||||||
}
|
|
||||||
return input as MonitorType;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (value === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return value.map((entry) => parseSingle(entry));
|
|
||||||
}
|
|
||||||
return parseSingle(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const parseSortOrder = (value: unknown): "asc" | "desc" | undefined => {
|
|
||||||
if (value === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (value === "asc" || value === "desc") {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
throw new AppError({ message: "order must be either 'asc' or 'desc'", status: 400 });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const requireTeamId = (teamId?: string): string => {
|
export const requireTeamId = (teamId?: string): string => {
|
||||||
if (!teamId) {
|
if (!teamId) {
|
||||||
throw new AppError({ message: "Team ID is required", status: 400 });
|
throw new AppError({ message: "Team ID is required", status: 400 });
|
||||||
|
|||||||
Reference in new issue
Block a user