-
-
Save bendrucker/9417825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create = { | |
handler: function(request, reply) { | |
return new Address().save({ | |
name: request.payload.name, | |
address_line1: request.payload.address_line1 | |
}) | |
.call('fetch') | |
.then(reply) | |
.catch(reply); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Address = Db.Model.extend({ | |
tableName: 'addresses', | |
validate: function() { | |
var basicValidation, payload, schema; | |
payload = this.clone(); | |
schema = { | |
name: Joi.string().max(50).required(), | |
address_line1: Joi.string().required() | |
}; | |
basicValidation = Joi.validate(payload.toJSON(), schema, { | |
stripUnknown: true | |
}); | |
if(basicValidation) { | |
throw new Error(basicValidation.message); | |
} else { | |
return; | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.Model.prototype.initialize = function() { | |
this.on('saving', this.validate, this); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possibly unhandled Error: the value of name is not allowed to be undefined | |
at Db.Model.extend.validate (/Users/peternagel/workspace/lob/lob-api/build/app/models/addressesModel.js:66:13) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the updated snippets - I added it to our code but we're still having the same issue. The validation error is being caught in the .catch on the controller but I'm still logging out a possibly unhandled error.