I’m using Meteor Methods for Upserts. The Methods reside in a client/server shared folder named ‘/methods’, so when i write a method, it exists on both the client and server.
/application/methods/methods.js
upsert_document: function (object) {
return collection_name.upsert({...})
}
I typically pass in an object from a Meteor call like so:
object = {
field1: 'value',
field2: 'value
}
Typically I do a check on the object:
check(configuration, {
field1: String,
field2: Number
});
But sometimes I might want to do conditional validation, for example,
if (field1 === 'valid') {
// field2 is now required
}
or just more complex validations
if (field1 === 'foo') {
// field1 is now required
} else if (field2 === 'bar') {
// field1 is not required
} else {
// field1 is required
}
And maybe default values:
if (field1 === 'valid') {
// set field2 = '50'
}
My questions are, is the Meteor Method client or server the right place for this validation? And what are the best practices for validation in this space?