remove comments

This commit is contained in:
Alex Holliday committed 2026-03-02 19:26:20 +00:00
1 parent 16cf23baf1
commit 75a7e144cd
1 file changed
-16
-16
View File
@@ -1,15 +1,9 @@
import { z } from "zod"; import { z } from "zod";
import { type UserRole } from "@/types/user.js"; import { type UserRole } from "@/types/user.js";
/**
* Password pattern: requires at least one lowercase, uppercase, number, and special character
*/
export const passwordPattern = export const passwordPattern =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!?@#$%^&*()\-_=+[\]{};:'",.~`|\\/])[A-Za-z0-9!?@#$%^&*()\-_=+[\]{};:'",.~`|\\/]+$/; /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!?@#$%^&*()\-_=+[\]{};:'",.~`|\\/])[A-Za-z0-9!?@#$%^&*()\-_=+[\]{};:'",.~`|\\/]+$/;
/**
* Reusable name validation schema
*/
export const nameValidation = z export const nameValidation = z
.string() .string()
.trim() .trim()
@@ -19,9 +13,6 @@ export const nameValidation = z
"Names must contain at least 1 letter and may only include letters, currency symbols, spaces, apostrophes, hyphens (-), periods (.), and parentheses ()." "Names must contain at least 1 letter and may only include letters, currency symbols, spaces, apostrophes, hyphens (-), periods (.), and parentheses ()."
); );
/**
* Reusable email validation with lowercase enforcement
*/
export const lowercaseEmailValidation = z export const lowercaseEmailValidation = z
.email() .email()
.transform((val) => val.toLowerCase()) .transform((val) => val.toLowerCase())
@@ -29,19 +20,12 @@ export const lowercaseEmailValidation = z
message: "Email must be in lowercase", message: "Email must be in lowercase",
}); });
/**
* Helper to properly coerce boolean from strings (handles "true"/"false" strings)
* Needed for query parameters and form data where Express sends strings
*/
export const booleanCoercion = z.preprocess((val) => { export const booleanCoercion = z.preprocess((val) => {
if (val === "true" || val === true) return true; if (val === "true" || val === true) return true;
if (val === "false" || val === false) return false; if (val === "false" || val === false) return false;
return val; // Let Zod validation handle invalid values return val; // Let Zod validation handle invalid values
}, z.boolean()); }, z.boolean());
/**
* Custom validator for role-based authorization
*/
export const roleValidator = (allowedRoles: UserRole[]) => { export const roleValidator = (allowedRoles: UserRole[]) => {
return z.array(z.custom<UserRole>()).refine((userRoles) => allowedRoles.some((role) => userRoles.includes(role)), { return z.array(z.custom<UserRole>()).refine((userRoles) => allowedRoles.some((role) => userRoles.includes(role)), {
message: `You do not have the required authorization. Required roles: ${allowedRoles.join(", ")}`, message: `You do not have the required authorization. Required roles: ${allowedRoles.join(", ")}`,