Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmachin committed Jan 17, 2024
1 parent 07d8b6c commit b4af7d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 14 additions & 4 deletions src/validator/auth.ts → src/data-schemas/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof userCreationSchema>;

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<typeof loginSchema>;

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);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"tests/*": ["tests/*"],
"types/*": ["types/*"],
"utils/*": ["utils/*"],
"validator/*": ["validator/*"],
"data-schemas/*": ["data-schemas/*"],
"root/*": ["../*"]
}
}
Expand Down
2 changes: 1 addition & 1 deletion tsoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"tests/*": ["tests/*"],
"types/*": ["types/*"],
"utils/*": ["utils/*"],
"validator/*": ["validator/*"],
"data-schemas/*": ["data-schemas/*"],
"root/*": ["../*"]
}
}
Expand Down

0 comments on commit b4af7d7

Please sign in to comment.