Blame view

imports/collections/staff/index.js 4.28 KB
925ffa9d3   Deepak   changed teachers ...
1
  // import {Staffs } from '/imports/collections/staff/index'
d75229d74   Deepak   fixed dob issue a...
2
3
4
5
6
7
8
9
  
  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';
925ffa9d3   Deepak   changed teachers ...
10
  class Staff {
d75229d74   Deepak   fixed dob issue a...
11
12
13
14
15
16
17
18
    constructor(doc) {
      _.assign(this, doc);
    };
  
    getUserIds() {
      return _.filter(_.map(this.users, 'userId'));
    };
  };
925ffa9d3   Deepak   changed teachers ...
19
  export { Staff };
d75229d74   Deepak   fixed dob issue a...
20

925ffa9d3   Deepak   changed teachers ...
21
  class StaffsCollection extends Mongo.Collection {
d75229d74   Deepak   fixed dob issue a...
22
23
24
25
26
27
28
    insert(item, callback) {
      _.assign(item, {
        createdAt:        new Date().getTime(),
      });
      return super.insert(item, callback);
    };
  };
167dd6325   satheesh   [#004]-Revised Sc...
29
  export const Staffs = new StaffsCollection('Staffs', {
d75229d74   Deepak   fixed dob issue a...
30
    transform: (item) => {
925ffa9d3   Deepak   changed teachers ...
31
      return new Staff(item);
d75229d74   Deepak   fixed dob issue a...
32
33
    },
  });
925ffa9d3   Deepak   changed teachers ...
34
35
  _.assign(Staffs, {
    allStaffs: () => {
d75229d74   Deepak   fixed dob issue a...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      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;
    },
  
  });
925ffa9d3   Deepak   changed teachers ...
52
  Staffs.deny({
d75229d74   Deepak   fixed dob issue a...
53
54
55
56
    insert() { return true; },
    update() { return true; },
    remove() { return true; },
  });
925ffa9d3   Deepak   changed teachers ...
57
  Staffs.schema = new SimpleSchema({
d75229d74   Deepak   fixed dob issue a...
58
59
    userId:               { type: String },
    orgId:                { type: String },
167dd6325   satheesh   [#004]-Revised Sc...
60
61
  
    employeeId:           { type: String ,unique: true,},
ec5f044a9   Deepak   Finished add teac...
62
63
    martialStatus:        { type: String },
    dob:                  { type: String },
d75229d74   Deepak   fixed dob issue a...
64
    gender:               { type: String, optional: true },
167dd6325   satheesh   [#004]-Revised Sc...
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  
    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({
        home:             { type: String, optional: true },
        street:           { type: String, optional: true },
        town:             { 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 
    },
d75229d74   Deepak   fixed dob issue a...
122
123
124
125
126
127
128
129
130
131
132
    services: {
      type: Object,
      optional: true,
      blackbox: true,
    },
  
    isMetaUser:           { type: Boolean, optional: true },
  
    createdAt:            { type: Date, autoValue: function(){return new Date();}}
  
  });
925ffa9d3   Deepak   changed teachers ...
133
  Staffs.attachSchema(Staffs.schema);
d75229d74   Deepak   fixed dob issue a...
134

925ffa9d3   Deepak   changed teachers ...
135
  Staffs.privateFields = {
d75229d74   Deepak   fixed dob issue a...
136
    orgId:              1,
d75229d74   Deepak   fixed dob issue a...
137
138
139
140
  
    isMetaUser:         1,
    createdAt:          1,
  };
925ffa9d3   Deepak   changed teachers ...
141
  Staffs.publicFields = {
d75229d74   Deepak   fixed dob issue a...
142
143
144
145
146
147
    firstName:          1,
    lastName:           1,
    emails:             1,
  
    createdAt:          1,
  };