How to use the orm.validators function in orm

To help you get started, we’ve selected a few orm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github es / OnlineJudge / app / models / user.js View on Github external
db.load("./article", function (err) {
        if (err) return callback(err);
        var UserSchema = db.define("user", {
            name: String,
            email: String,
            username: String,
            provider: String,
            password: String
        },{ 
            validations: {
                name: orm.validators.notEmptyString('Name cannot be blank'),
                email: orm.validators.notEmptyString('Email cannot be blank'),
                username: [orm.validators.notEmptyString('Username cannot be blank'), orm.validators.unique("Username must be unique")],
                password: orm.validators.notEmptyString('Password cannot be blank')

            },

            autoFetch: true,
            hooks: {
                /**
                 * Pre-save hook
                 */
                beforeSave: function(next) {
                    if (!this.isNew) return next();

                    if (!validatePresenceOf(this.password))
                        next(new Error('Invalid password'));
                    else
                        next();
github es / OnlineJudge / app / models / user.js View on Github external
db.load("./article", function (err) {
        if (err) return callback(err);
        var UserSchema = db.define("user", {
            name: String,
            email: String,
            username: String,
            provider: String,
            password: String
        },{ 
            validations: {
                name: orm.validators.notEmptyString('Name cannot be blank'),
                email: orm.validators.notEmptyString('Email cannot be blank'),
                username: [orm.validators.notEmptyString('Username cannot be blank'), orm.validators.unique("Username must be unique")],
                password: orm.validators.notEmptyString('Password cannot be blank')

            },

            autoFetch: true,
            hooks: {
                /**
                 * Pre-save hook
                 */
                beforeSave: function(next) {
                    if (!this.isNew) return next();

                    if (!validatePresenceOf(this.password))
                        next(new Error('Invalid password'));

orm

NodeJS Object-relational mapping

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis