neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

validator on top #606

Closed Steinweber closed 7 years ago

Steinweber commented 7 years ago

How to validate on top of a model? Like

const Contact = thinky.createModel("contact", {
    id: type.string().required(),
    gender: type.string().required(),
    company: type.string(),
    firstname: type.string().required(),
    lastname: type.string().required()
}).validator(args => {
    return !(args.gender === 'company' && args.company.length === 0);
});
neumino commented 7 years ago
const Contact = thinky.createModel("contact", type.object({
    id: type.string().required(),
    gender: type.string().required(),
    company: type.string(),
    firstname: type.string().required(),
    lastname: type.string().required()
}).validator(args => {
    return !(args.gender === 'company' && args.company.length === 0);
}));