Skip to content

Need more helpers with external() #2798

@innovaweb-dev

Description

@innovaweb-dev

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions