From b4af7d73f13677b8f7578290fc3423755c9e7497 Mon Sep 17 00:00:00 2001 From: Gabriel Machin Date: Wed, 17 Jan 2024 14:46:12 -0300 Subject: [PATCH] Fix comments --- src/controllers/auth.ts | 2 +- src/{validator => data-schemas}/auth.ts | 18 ++++++++++++++---- tsconfig.json | 2 +- tsoa.json | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) rename src/{validator => data-schemas}/auth.ts (68%) diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index 935041d..e3f3eef 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -8,7 +8,7 @@ import { AuthenticatedRequest, LoginParams, } from 'types'; -import { validateLoginSchema, validateUserSchema } from 'validator/auth'; +import { validateLoginSchema, validateUserSchema } from 'data-schemas/auth'; @Route('v1/auth') export class AuthControllerV1 extends Controller { diff --git a/src/validator/auth.ts b/src/data-schemas/auth.ts similarity index 68% rename from src/validator/auth.ts rename to src/data-schemas/auth.ts index 2f0521a..38eafd9 100644 --- a/src/validator/auth.ts +++ b/src/data-schemas/auth.ts @@ -5,20 +5,30 @@ import { ApiError } from 'utils/apiError'; import { errors } from 'config/errors'; import { formatZodError } from 'utils/validator'; -const userSchema = z.object({ +const passwordLength = 10; + +const userCreationSchema = z.object({ email: z.string().email({ message: 'Invalid email' }), name: z.string(), - password: z.string().min(1, { message: "Can't be an empty password" }), + password: z + .string() + .min(passwordLength, { message: "Can't be an empty password" }), }); +export type UserCreationSchema = z.infer; + const loginSchema = z.object({ email: z.string().email({ message: 'Invalid email' }), - password: z.string().min(1, { message: "Can't be an empty password" }), + password: z + .string() + .min(passwordLength, { message: "Can't be an empty password" }), }); +export type UserLoginSchema = z.infer; + export const validateUserSchema = (user: CreateUserParams) => { try { - userSchema.parse(user); + userCreationSchema.parse(user); } catch (err) { const formattedZodError = formatZodError(err as ZodError); throw new ApiError(errors.VALIDATION_ERROR, true, formattedZodError); diff --git a/tsconfig.json b/tsconfig.json index c8109c6..d22728f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,7 @@ "tests/*": ["tests/*"], "types/*": ["types/*"], "utils/*": ["utils/*"], - "validator/*": ["validator/*"], + "data-schemas/*": ["data-schemas/*"], "root/*": ["../*"] } } diff --git a/tsoa.json b/tsoa.json index b6c26c6..5377a80 100644 --- a/tsoa.json +++ b/tsoa.json @@ -28,7 +28,7 @@ "tests/*": ["tests/*"], "types/*": ["types/*"], "utils/*": ["utils/*"], - "validator/*": ["validator/*"], + "data-schemas/*": ["data-schemas/*"], "root/*": ["../*"] } }