Created
December 23, 2017 00:17
-
-
Save thomastraum/56a6224e35a06fbd0702e6b7bf076fc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Meteor } from 'meteor/meteor'; | |
import { Mongo } from 'meteor/mongo'; | |
import { check } from 'meteor/check'; | |
import SimpleSchema from 'simpl-schema'; | |
// import Collections2 from 'collection2'; | |
export const Things = new Mongo.Collection('things'); | |
const schema = new SimpleSchema({ | |
owner: {type: String, regEx: SimpleSchema.RegEx.Id, optional: false}, | |
name:{type:String}, | |
url:{type:String,regEx:SimpleSchema.RegEx.Url,optional:false}, | |
text:{type:Number, optional:false}, | |
createdAt:{type:Date}, | |
analyzed:{type:Boolean,defaultValue:false}, | |
username:{type:String, optional:false} | |
}); | |
Things.attachSchema = schema; | |
Meteor.methods({ | |
'things.insert'(thing) { | |
// check(thing.text, String); | |
// check(thing.url, String); | |
// Make sure the user is logged in before inserting a thing | |
if (! Meteor.userId()) { | |
throw new Meteor.Error('not-authorized'); | |
} | |
Things.insert({ | |
text: thing.text, | |
url: thing.url, | |
createdAt: new Date(), | |
owner: Meteor.userId(), | |
username: Meteor.user().username, | |
}); | |
}, | |
'things.remove'(thingId) { | |
check(thingId, String); | |
Things.remove(thingId); | |
}, | |
'things.setChecked'(thingId, setChecked) { | |
check(thingId, String); | |
check(setChecked, Boolean); | |
Things.update(thingId, { $set: { checked: setChecked } }); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment