Blame view
imports/collections/users/index.js
4.34 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 |
// import { Users } from '/imports/collections/users/index'; // import { Users } from '/imports/collections/users/index'; import _ from 'lodash'; import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { SimpleSchema } from 'meteor/aldeed:simple-schema'; import { Orgs } from '/imports/collections/orgs/index'; class User { constructor(doc) { _.assign(this, doc); }; isEmailVerified() { return !! _.find(this.emails, x => x.verified); }; isPhoneVerified() { return !! _.find(this.phones, x => x.verified); }; isIdentityVerified() { return !! _.find(this.identities, x => x.verified); }; getRole() { |
d532f2f02
|
30 |
return (this._id); |
ff976df49
|
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
const org = Orgs.findOne({_id: this.orgId}); if(!org) return null; const connection = _.find(org.users, {userId: this._id}); if(!connection) return null; return connection.role; }; getFullName() { return `${this.firstName} ${this.lastName}`; }; getFirstName() { return `${this.firstName}`; }; getLastName() { return `${this.lastName}`; }; getEmail() { return `${this.emails[0].address}`; }; getOrganization(){ return `${this.orgId}`; }; getNameByUserId(userId){ var user = Users.findOne({"_id":userId}); return user.firstName + " " + user.lastName; } getAvatarUrl() { let random = parseInt(this._id.substr(0, 4), 36); random = '' + (random % 32); while(random.length < 3) random = '0' + random; return `/files/random/random${ random }.png`; }; }; export { User }; const transform = function(doc) { return new User(doc); }; export const Users = { current: function() { return Meteor.users.findOne({_id: Meteor.userId()}, _.extend({transform: transform})); }, find: function(selector, options) { return Meteor.users.find(selector || {}, _.extend({transform: transform}, options)); }, findOne: function(selector, options) { return Meteor.users.findOne(selector || {}, _.extend({transform: transform}, options)); }, insert: _.bind(Meteor.users.insert, Meteor.users), update: _.bind(Meteor.users.update, Meteor.users), remove: _.bind(Meteor.users.remove, Meteor.users), allow: _.bind(Meteor.users.allow, Meteor.users), deny: _.bind(Meteor.users.deny, Meteor.users), attachSchema: _.bind(Meteor.users.attachSchema, Meteor.users), }; Users.deny({ insert() { return true; }, update() { return true; }, remove() { return true; }, }); Users.roles = { 'STUDENT': 'STUDENT', |
925ffa9d3
|
105 |
'STAFF': 'STAFF', |
ff976df49
|
106 107 108 109 110 111 |
'ADMIN': 'ADMIN', 'PARENT': 'PARENT' }; Users.schema = new SimpleSchema({ |
d0099dd88
|
112 |
role: { type: String }, |
ff976df49
|
113 |
orgId: { type: String }, |
d0099dd88
|
114 |
username: { type: String, optional: true }, |
ff976df49
|
115 116 117 118 |
prefix: { type: String, optional: true }, firstName: { type: String, optional: true }, middlename: { type: String, optional: true }, lastName: { type: String, optional: true }, |
ec5f044a9
|
119 |
address: { type: String, optional: true, }, |
ff976df49
|
120 121 |
gender: { type: String, optional: true }, dob: { type: String, optional: true }, |
ff976df49
|
122 123 124 125 126 |
emails: { type: [new SimpleSchema({ address: { type: String, }, verified: { type: Boolean, }, })], |
d0099dd88
|
127 |
optional: true |
ff976df49
|
128 |
}, |
ff976df49
|
129 130 |
phones: { type: [new SimpleSchema({ |
ec5f044a9
|
131 132 |
country: { type: String, optional: true }, prefix: { type: String, optional: true }, |
ff976df49
|
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
number: { type: String, }, verified: { type: Boolean, }, })], optional: true }, services: { type: Object, optional: true, blackbox: true, }, isMetaUser: { type: Boolean, optional: true }, createdAt: { type: Date, autoValue: function(){return new Date();}} }); Users.attachSchema(Users.schema); Users.privateFields = { orgId: 1, address: 1, firstName: 1, lastName: 1, emails: 1, phones: 1, isMetaUser: 1, createdAt: 1, }; Users.publicFields = { firstName: 1, lastName: 1, emails: 1, createdAt: 1, }; |