Blame view
imports/collections/orgs/index.js
2.51 KB
ff976df49
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
// import { Orgs } from '/imports/collections/orgs/index'; import _ from 'lodash'; import { Mongo } from 'meteor/mongo'; import { SimpleSchema } from 'meteor/aldeed:simple-schema'; import { Users } from '/imports/collections/users/index'; class Org { constructor(doc) { _.assign(this, doc); }; getUserIds() { return _.filter(_.map(this.users, 'userId')); }; getInvitationIds() { return _.filter(_.map(this.users, 'invitationId')); }; areDetailsDone() { return ( this.name && this.name.length && this.shortCode && this.shortCode.length && this.acn && this.acn.length ); }; ifCurrentUserIsAdmin(){ const user = Users.current(); if(!user) return null; for(let i = 0; i < this.users.length; ++i) { if( (this.users[i].role == "SECRETARY") && this.users[i].userId == user._id ) { return true; } } return false; } }; export { Org }; class OrgsCollection extends Mongo.Collection { insert(item, callback) { _.assign(item, { createdAt: new Date().getTime(), }); return super.insert(item, callback); }; }; export const Orgs = new OrgsCollection('Orgs', { transform: (item) => { return new Org(item); }, }); _.assign(Orgs, { allOrgsCurrentUser: () => { const user = Users.current(); if(!user) return null; return Orgs.find({'users.userId': user._id}); }, current: () => { const user = Users.current(); if(!user) return null; return Orgs.findOne({_id: user.orgId}); }, currentOrgUsers: () => { const OrgsArr = Orgs.current(); if(!OrgsArr) return null; return OrgsArr.users; }, }); Orgs.deny({ insert() { return true; }, update() { return true; }, remove() { return true; }, }); Orgs.schema = new SimpleSchema({ |
39d8f536d
|
89 90 |
name: { type: String }, slug: { type: String }, |
ff976df49
|
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
address: { type: String, optional: true}, users: { type: [new SimpleSchema({ userId: { type: String, optional: true}, invitationId: { type: String, optional: true}, role: { type: String, }, email: { type: String, optional: true}, })], }, createdAt: { type: Date, autoValue: function(){return new Date();}}, }); Orgs.attachSchema(Orgs.schema); Orgs.publicFields = { name: 1, slug: 1, createdAt: 1, }; |