Skip to content

Commit

Permalink
Update rest-user-server example to properly work with current nohm
Browse files Browse the repository at this point in the history
  • Loading branch information
maritz committed Nov 27, 2011
1 parent 1751077 commit 43d892f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
22 changes: 14 additions & 8 deletions examples/rest-user-server/UserModel.js
Expand Up @@ -24,27 +24,34 @@ var password_minlength = 6; // we use this multiple times and store it here to o
/**
* Model definition of a simple user
*/
var userModel = module.exports = nohm.model('User', {
module.exports = nohm.model('User', {
idGenerator: 'increment',
properties: {
name: {
type: 'string',
unique: true,
validations: [
'notEmpty',
['minLength', 4]
['length', {
length: 4
}]
]
},
email: {
type: 'string',
validations: [
['email', true] // this means only values that pass the email regexp are accepted. BUT it is also optional, thus a falsy value is accepted as well.
['email', {
optional: true
}] // this means only values that pass the email regexp are accepted. BUT it is also optional, thus a falsy value is accepted as well.
]
},
someRegex: {
type: 'string',
validations: [
['regexp', /^asd$/, true]
['regexp', {
regex: /^asd$/,
optional: true
}]
]
},
password: {
Expand All @@ -67,7 +74,9 @@ var userModel = module.exports = nohm.model('User', {
},
validations: [
'notEmpty',
['minLength', password_minlength]
['length', {
min: password_minlength
}]
]
},
salt: {
Expand Down Expand Up @@ -112,8 +121,6 @@ var userModel = module.exports = nohm.model('User', {
*/
fill: function (data, fields, fieldCheck) {
var props = {},
passwordInField,
passwordChanged = false,
self = this,
doFieldCheck = typeof(fieldCheck) === 'function';

Expand Down Expand Up @@ -162,7 +169,6 @@ var userModel = module.exports = nohm.model('User', {
* This makes it easier to check user input.
*/
checkProperties: function (data, fields, callback) {
var self = this;
callback = typeof(fields) === 'function' ? fields : callback;

this.fill(data, fields);
Expand Down
8 changes: 2 additions & 6 deletions examples/rest-user-server/custom_validations.js
@@ -1,7 +1,3 @@
exports.usernameIsAnton= function (value, params) {
if (value === 'Arnold') { // hehe
return true;
} else {
return false;
}
exports.usernameIsAnton= function (value, options) {
callback(value === 'Arnold');
};
3 changes: 1 addition & 2 deletions examples/rest-user-server/rest-server.js
Expand Up @@ -42,8 +42,7 @@ server.get('/User/create', function (req, res, next) {
password: req.param('password'),
email: req.param('email')
};

var user = new UserModel();
var user = Nohm.factory('User');
user.store(data, function (err) {
if (err === 'invalid') {
next(user.errors);
Expand Down

0 comments on commit 43d892f

Please sign in to comment.