Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested schema error #248

Closed
Pos-cmd opened this issue Mar 16, 2024 · 1 comment
Closed

Nested schema error #248

Pos-cmd opened this issue Mar 16, 2024 · 1 comment
Labels

Comments

@Pos-cmd
Copy link

Pos-cmd commented Mar 16, 2024

  • node version - 18
  • celebrate version - 15.0.3
  • joi version (via npm ls --depth=0 | grep joi) -17

My joi schema looks like this:

export const fetchUsersValidation = { [Segments.QUERY]: Joi.object<QueryOptions>().keys({ sort: Joi.array().items(Joi.string().allow(null)).valid('firstname', 'lastname', 'createdAt', '-firstname', '-lastname', '-createdAt'), // Allow null values for optional sorting filters: Joi.object().valid({ type: Joi.number().valid(UserType), // Validate allowed types role: Joi.number() // Validate allowed roles }), pagination: Joi.object({ page: Joi.number().integer().positive().default(1), // Ensure positive integer, default to 1 pageSize: Joi.number().integer().min(1).max(100).default(15) // Set limits and default }) }) };

Here is an example value that is not working as expected:

{{base_url}}/api/users/?filters[type]=1

The issue I am having with celebrate is:
"message": ""filters" must be [[object Object]]; ",
*I create the error handler like this:
app.use((err: any, _req: Request, res: Response, _next: NextFunction) => { if (isCelebrateError(err)) { let message = ''; for (const value of err.details.values()) { message += value.message + '; '; } logger.error('🔥 error %o', message); res.status(httpStatus.BAD_REQUEST).json(resultError(message)); } })
but i have error for the nested joi schema. I think i do it in the wrong way.
*

Copy link

stale bot commented May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 16, 2024
@stale stale bot closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant