Module: utils/validate

Lightweight input validation helpers for API routes.

No external dependencies — keeps the backend lean. Each function returns null if valid, or an error message string if invalid.

Source:
Example
const err = validate.projectPayload(req.body);
if (err) return res.status(400).json({ error: err });

Methods

(static) sanitise(val, maxLenopt) → {string}

Trim and truncate a string. Returns empty string for non-string values.

Parameters:
Name Type Attributes Default Description
val *
maxLen number <optional>
500
Source:
Returns:
Type
string

(static) validateBulkAction(body) → {string|null}

Validate bulk test action payload.

Parameters:
Name Type Description
body Object

req.body

Source:
Returns:

Error message or null.

Type
string | null

(static) validateProjectPayload(body) → {string|null}

Validate project creation/update payload.

Parameters:
Name Type Description
body Object

req.body

Source:
Returns:

Error message or null.

Type
string | null

(static) validateTestPayload(body) → {string|null}

Validate manual test creation payload.

Parameters:
Name Type Description
body Object

req.body

Source:
Returns:

Error message or null.

Type
string | null

(static) validateTestUpdate(body) → {string|null}

Validate test update (PATCH) payload.

Parameters:
Name Type Description
body Object

req.body

Source:
Returns:

Error message or null.

Type
string | null

(static) validateUrl(url) → {string|null}

Validate a URL string — must be http or https.

Parameters:
Name Type Description
url string
Source:
Returns:

Error message or null.

Type
string | null