Checking the scheme on the Meteor method using autoform

I am using autoform, collection2. I want to use the method call type for insert / update, since I want to add additional fields before saving to the database on the server. SimpleSchema will verify the data on the client, but how can I make the data verified on a server-side diagram? My method of adding new data is as follows:

Meteor.methods({ companyAdd: function (companyAttr) { // add additional fields to document var currentDate = new Date(); var company = _.extend(companyAttr, { createdBy: user._id, createdAt: currentDate }); var newCompanyId = Companies.insert(company); return {_id: newCompanyId}; } } 
+5
source share
1 answer

I found in the simpleschema documentation if someone else needs a solution later: you can just check the circuit:

 Meteor.methods({ companyAdd: function (companyAttr) { //here we check the data sent to method against the defined schema check(companyAttr, Companies.simpleSchema()); var currentDate = new Date(); var company = _.extend(companyAttr, { createdBy: user._id, createdAt: currentDate }); var newCompanyId = Companies.insert(company); return {_id: newCompanyId}; } } 
+5
source

Source: https://habr.com/ru/post/1215055/


All Articles