fix: Move collection index validation logic to a context assert function (#2116)
* Abstract validation logic for readability * Add index validation in collections.move * Add tests
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
import { type Context } from "koa";
|
||||
import validator from "validator";
|
||||
import { validateColorHex } from "../../shared/utils/color";
|
||||
import { validateIndexCharacters } from "../../shared/utils/indexCharacters";
|
||||
import { ParamRequiredError, ValidationError } from "../errors";
|
||||
|
||||
export default function validation() {
|
||||
@ -60,6 +61,11 @@ export default function validation() {
|
||||
}
|
||||
};
|
||||
|
||||
ctx.assertIndexCharacters = (value, message) => {
|
||||
if (!validateIndexCharacters(value)) {
|
||||
throw new ValidationError(message);
|
||||
}
|
||||
};
|
||||
return next();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user