index.js 4.17 KB
// 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('Staffs', {
  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 ,unique: true,},
  martialStatus:        { type: String },
  dob:                  { type: String },
  gender:               { type: String, optional: true },

  teaching:             { type: String },
  type:                 { type: String, optional: true },
  doj:                  { type: String },

  bloodGroup:           { type: String, optional: true },
  nationality:          { type: String, optional: true },
  motherTongue:         { type: String, optional: true },
  religion:             { type: String, optional: true },

  PANNumber:            { type: String, optional: true },
  ESINumber:            { type: String, optional: true },
  aadharNumber:         { type: String, optional: true },
  PFNumber:             { type: String,optional: true },

  permanentAddress: {
    type: new SimpleSchema({
      address:          { type: String, optional: true },
      city:             { type: String, optional: true },
      state:            { type: String, optional: true },
      zip:              { type: String, optional: true },
    }),
    optional: true
  },

  bankdetails: {
    type: new SimpleSchema({
      bankAccountNo:      { type: String, optional: true },
      bankIFSC:           { type: String, optional: true },
      bankBranchDetails:  { type: String, optional: true }
    }),
    optional: true
  },

  workingExperience: {
    type: [new SimpleSchema({
      previousJobRole:     { type: String, optional: true },
      previousJobType:     { type: String, optional: true },
      previousOrganization:{ type: String, optional: true },
      from:                { type: String, optional: true },
      to:                  { type: String, optional: true }
    })],
    optional: true
  },

  educationDetails: {
    type: [ new SimpleSchema({
      qualifaication:      { type: String, optional: true },
      specialization:      { type: String, optional: true },
      university:          { type: String, optional: true },
      from:                { type: String, optional: true },
      to:                  { type: String, optional: true }
    })],
    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,
};