import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; import SimpleSchema from 'simpl-schema'; let Pages = new Mongo.Collection('Pages'); Pages.attachSchema(new SimpleSchema({ name: { type: String, label: "Name", optional: false, trim: true, index: 1, unique: true }, html: { type: String, label: "HTML", optional: false, trim: false }, updatedAt: { type: Date, label: "Updated On", optional: true } })); if(Meteor.isServer) Meteor.publish('pages', function() { return Pages.find({}); }); if(Meteor.isServer) { Meteor.methods({ updatePage: function(name, html) { check(name, String); check(html, String); if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) { Pages.upsert({name}, {$set: {name, html, updatedAt: new Date()}}); } else throw new Meteor.Error(403, "Not authorized."); } }); } export default Pages;