feature/IO-3052-Skia-Canvas-Handler: Cleanup

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-12-05 11:52:14 -08:00
parent 86f3179bc0
commit 50c99f7a1e
3 changed files with 31 additions and 41 deletions

View File

@@ -0,0 +1,25 @@
const { isObject } = require("lodash");
const validateCanvasInputMiddleware = (req, res, next) => {
const { values, keys, override } = req.body;
if (!Array.isArray(values) || !Array.isArray(keys)) {
return res.status(400).send("Invalid input: 'values' and 'keys' must be arrays.");
}
if (values.some((value) => typeof value !== "number")) {
return res.status(400).send("Invalid input: 'values' must be an array of numbers.");
}
if (keys.some((key) => typeof key !== "string")) {
return res.status(400).send("Invalid input: 'keys' must be an array of strings.");
}
if (override && !isObject(override)) {
return res.status(400).send("Override must be an object");
}
next(); // Proceed to the next middleware or route handler
};
module.exports = validateCanvasInputMiddleware;