Editor NodeJS unique validator.

Editor NodeJS unique validator.

naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

Hi,

Good day.

I've only found examples dealing with other SDKs and not NodeJS. Also checked the examples in the NodeJS server package.

What I have tried so far:

    .fields(
        new Field('Ingredients.Ingredient').validator(Validate.notEmpty())
        .validator(Validate.unique())
    )

and:

    .fields(
        new Field('Ingredients.Ingredient').validator(Validate.notEmpty())
        .validator(Validate.dbUnique())
    )

No luck. I get the following errors:

(node:44680) UnhandledPromiseRejectionWarning: TypeError: Validate.unique is not a function

and:

(node:44653) UnhandledPromiseRejectionWarning: TypeError: host.db(...) is not a function

Could you please assist me with an example? Thanks.

Regards.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Apologies - a few bugs here...

    Firstly, the documentation should refer to dbUnique() for the NodeJS libraries. There is no Validate.unique() method there.

    Secondly, there is a bug in how the database is checked. I've committed a fix and it will ship in 1.8 which isn't that far away (next week).

    Until then, you can make those changes locally, or grab the latest source from github.

    Regards,
    Allan

  • naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

    Once again, thanks allan. Will get the fix. Regards.

  • naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1
    edited September 2018

    Line 603:

    return !res.length
    

    should be:

    return res.length
    

    Regards.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Yup - I spotted that one too! Its in the commit above.

    Thanks!
    Allan

This discussion has been closed.