Simple Schema is accepting and inserting null
into required fields. Shouldn’t it error? Can someone please point out what I’m doing wrong here.
I’m using these packages.
- mdg:validated-method
- mdg:validation-error
- simpl-schema
Simple Schema
export const ProfileCandidate = new Mongo.Collection('profileCandidate');
const profileCandidate = new SimpleSchema({
name: Object,
'name.first': String,
'name.last': String,
}
});
Method Call
var data = {
'name.first': this.state.firstName,
'name.last': this.state.lastName,
};
insertProfileCandidate.call(data, (err, res) => {
if(err) {
console.log("err: ", err);
}
});
ValidateMethod
export const insertProfileCandidate = new ValidatedMethod({
name: 'profileCandidate.insert',
validate: new SimpleSchema({
'name.first': { type: String, min: 1 },
'name.last': { type: String, min: 1 },
}).validator({ clean: true }),
run(data) {
ProfileCandidate.insert({
name: {
first: data['name.first'],
last: data['name.last'],
}
}, (error, result) => {
if (error) throw new Meteor.Error('400', error.invalidKeys);
});
}
});