Skip to content

Instantly share code, notes, and snippets.

@wesmaldonado
Created November 23, 2016 19:42
Show Gist options
  • Save wesmaldonado/8bc8ff2f8f8bd3770c5a029ab50bed72 to your computer and use it in GitHub Desktop.
Save wesmaldonado/8bc8ff2f8f8bd3770c5a029ab50bed72 to your computer and use it in GitHub Desktop.
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(er_id
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('spotbid_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 } });
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment