import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; import SimpleSchema from 'simpl-schema'; let ContactUsMessages = new Mongo.Collection('ContactUsMessages'); ContactUsMessages.attachSchema(new SimpleSchema({ name: { type: String, label: "Name", optional: false, trim: false, }, email: { type: String, label: "Email", optional: false, trim: false }, message: { type: String, label: "Message", optional: false, trim: false }, createdAt: { type: Date, label: "Created On", optional: true } })); if(Meteor.isServer) Meteor.publish('contactUsMessages', function() { return ContactUsMessages.find({}); }); if(Meteor.isServer) { Meteor.methods({ submitContactForm: function(name, email, message) { check(name, String); check(email, String); check(message, String); if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) { ContactUsMessages.insert({name, email, message, createdAt: new Date()}); } else throw new Meteor.Error(403, "Not authorized."); } }); } export default ContactUsMessages;