Created
November 23, 2016 21:37
-
-
Save wesmaldonado/1a976769d2f61638a4f08c59c514450f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { Mongo } from 'meteor/mongo'; | |
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | |
import { Factory } from 'meteor/factory'; | |
import { Todos } from '../todos/todos.js'; | |
class SpotBidProfileCollection extends Mongo.Collection { | |
insert(list, callback) { | |
return super.insert(list, callback); | |
} | |
remove(selector, callback) { | |
SpotBidProfiles.remove({ listId: selector }); | |
return super.remove(selector, callback); | |
} | |
} | |
export const SpotBidProfiles = new SpotBidProfileCollection('spotbid_profiles'); | |
// Deny all client-side updates since we will be using methods to manage this collection | |
SpotBidProfiles.deny({ | |
insert() { return true; }, | |
update() { return true; }, | |
remove() { return true; }, | |
}); | |
SpotBidProfiles.schema = new SimpleSchema( | |
userId: { type: String, regEx: SimpleSchema.RegEx.Id, optional: true }, | |
display_name: { type: String }, | |
instance_type: { type: String }, | |
instances_requested: { type: Number } | |
}); | |
SpotBidProfiles.attachSchema(SpotBidProfiles.schema); | |
// This represents the keys from Lists objects that should be published | |
// to the client. If we add secret properties to List objects, don't list | |
// them here to keep them private to the server. | |
SpotBidProfiles.publicFields = { | |
display_name: 1, | |
instance_type: 1, | |
instances_requesed: 1 | |
}; | |
Factory.define('spot_bid_profiles', SpotBidProfiles, {}); | |
SpotBidProfiles.helpers({ | |
// A profile is considered to be private if it has a userId set | |
isPrivate() { | |
return !!this.userId; | |
}, | |
editableBy(userId) { | |
if (!this.userId) { | |
return true; | |
} | |
return this.userId === userId; | |
}, | |
spotbid_profiles() { | |
return SpotBidProfiles.find({ __id: this._id }, { sort: { createdAt: -1 } }); | |
}, | |
}); | |
Meteor.publish('spot_bid_profiles.all', function SpotBidProfilesAll() { | |
if (!this.userId) { | |
return this.ready(); | |
} | |
return SpotBidProfiles.find({ | |
userId: this.userId, | |
},{ | |
fields: SpotBidProfiles.publicFields, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment