I'm writing this gist in response to a comment on forums.meteor.com
I guess it's working... I wonder what is actually happening on the server side of things :X
Heh, oh well.
Thanks for the pointers aadams
I'm writing this gist in response to a comment on forums.meteor.com
I guess it's working... I wonder what is actually happening on the server side of things :X
Heh, oh well.
Thanks for the pointers aadams
| ... Other imports, etc... | |
| import { addSuggestion } from '../../../api/suggestions/suggestions_methods' | |
| ... skipping code ... | |
| addSuggestion.call(newSuggestion, (error, result) => { | |
| if (error) { | |
| // Something really bad has happened... | |
| console.log(error) | |
| } else { | |
| // Success, clear the suggestion box | |
| this.setState(this.setDefaultState()) | |
| console.log(result) | |
| } | |
| }) |
| import { Meteor } from 'meteor/meteor' | |
| import { ValidatedMethod } from 'meteor/mdg:validated-method'; | |
| import { Session } from 'meteor/session' | |
| import { Suggestions } from './suggestions' | |
| import _ from 'lodash' | |
| import moment from 'moment' | |
| export const addSuggestion = new ValidatedMethod({ | |
| name: 'suggestion.add', | |
| validate() { }, // Install `meteor add audit-argument-checks` | |
| run(incommingSuggestion) { | |
| let currentUser = Meteor.user() | |
| if (!currentUser) { | |
| Session.set('showLoginModal', true) | |
| throw new Meteor.Error("not-logged-in", "An account is required to submit a new idea.", "addSuggestion method") | |
| } else { | |
| let suggestion = _.extend(incommingSuggestion, { | |
| userId: currentUser._id, | |
| score: 0, | |
| timestamp: moment().toDate(), | |
| }) | |
| return Suggestions.insert(suggestion) | |
| } | |
| } | |
| }) |