import { z } from "zod"; import { InputParseError } from "../../entities/errors"; import { signUpUseCase } from "../../application/use-cases/sign-up.use-case"; const inputSchema = z .object({ username: z.string().min(3).max(31), password: z.string().min(6).max(255), confirmPassword: z.string().min(6).max(255), }) .superRefine(({ password, confirmPassword }, ctx) => { if (confirmPassword !== password) { ctx.addIssue({ code: "custom", message: "The passwords did not match", path: ["password"], }); ctx.addIssue({ code: "custom", message: "The passwords did not match", path: ["confirmPassword"], }); } }); export async function signUpController( input: Partial>, ): Promise> { const parsed = inputSchema.safeParse(input); if (!parsed.success) { throw new InputParseError("Invalid sign-up input", { cause: parsed.error }); } return await signUpUseCase(parsed.data); }