fix: Improved model validation for Collection (#3749)
* fix: Added improved model validation for Collection attributes * sp * fix: Enforce title length in UI
This commit is contained in:
17
server/models/validators/IsHexColor.ts
Normal file
17
server/models/validators/IsHexColor.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { isHexColor } from "class-validator";
|
||||
import { addAttributeOptions } from "sequelize-typescript";
|
||||
|
||||
/**
|
||||
* A decorator that validates that a string is a valid hex color code.
|
||||
*/
|
||||
export default function IsHexColor(target: any, propertyName: string) {
|
||||
return addAttributeOptions(target, propertyName, {
|
||||
validate: {
|
||||
validDomain(value: string) {
|
||||
if (!isHexColor(value)) {
|
||||
throw new Error("Must be a valid hex color code");
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import { addAttributeOptions } from "sequelize-typescript";
|
||||
*/
|
||||
export default function Length({
|
||||
msg,
|
||||
min,
|
||||
min = 0,
|
||||
max,
|
||||
}: {
|
||||
msg?: string;
|
||||
min: number;
|
||||
min?: number;
|
||||
max: number;
|
||||
}): (target: any, propertyName: string) => void {
|
||||
return (target: any, propertyName: string) =>
|
||||
|
||||
Reference in New Issue
Block a user