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

Need more helpers with external() #2798

Closed
innovaweb-dev opened this issue Jun 26, 2022 · 1 comment
Closed

Need more helpers with external() #2798

innovaweb-dev opened this issue Jun 26, 2022 · 1 comment

Comments

@innovaweb-dev
Copy link

innovaweb-dev commented Jun 26, 2022

Context

  • node version: v14.19.0
  • module version: 17.6.0
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: none

How can we help?

I want to retrieve the rule name which trigger my external validation, this helper is not available with any.external. I need it like of any.custom() with helpers.state.path[0]

Joi.object({
    //...
    email: Joi.string().external(uniqueRecord)
})

const uniqueRecord = async (value: any, helpers: any): Promise<any> => {
    
    //const field = "here the value will be email"
    const tenant = helpers.prefs.context.tenant;
    const collection = helpers.prefs.context.collection;

    const query = await db.query(tenant, collection)
    const isUnique = await query.find({[field]: value}).count() === 0

    if(!isUnique){
        console.warn('uniqueRecord : not unique');
        return helpers.error('any.invalid')
    } else {
        console.log('uniqueRecord : unique');
        return undefined
    }
}

I tried to use description like on doc, but I can't retrieve it on my external function.
Thanks,

@innovaweb-dev
Copy link
Author

I have found my answer in PR #2773.
I hope it will be pushed coming soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant