// import {Staffs } from '/imports/collections/staff/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'; import { Users } from '/imports/collections/users/index'; class Staff { constructor(doc) { _.assign(this, doc); }; getUserIds() { return _.filter(_.map(this.users, 'userId')); }; }; export { Staff }; class StaffsCollection extends Mongo.Collection { insert(item, callback) { _.assign(item, { createdAt: new Date().getTime(), }); return super.insert(item, callback); }; }; export const Staffs = new StaffsCollection('Teachers', { transform: (item) => { return new Staff(item); }, }); _.assign(Staffs, { allStaffs: () => { 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; }, }); Staffs.deny({ insert() { return true; }, update() { return true; }, remove() { return true; }, }); Staffs.schema = new SimpleSchema({ userId: { type: String }, orgId: { type: String }, employeeId: { type: String }, martialStatus: { type: String }, dob: { type: String }, teaching: { type: String }, type: { type: String }, gender: { type: String, optional: true }, qualifaication: { type: String, optional: true }, specialization: { type: String, optional: true }, university: { type: String, optional: true }, degreeFrom: { type: String, optional: true }, degreeEnded: { type: String, optional: true }, services: { type: Object, optional: true, blackbox: true, }, isMetaUser: { type: Boolean, optional: true }, createdAt: { type: Date, autoValue: function(){return new Date();}} }); Staffs.attachSchema(Staffs.schema); Staffs.privateFields = { orgId: 1, isMetaUser: 1, createdAt: 1, }; Staffs.publicFields = { firstName: 1, lastName: 1, emails: 1, createdAt: 1, };