Blame view

imports/collections/staff/methods.js 2.84 KB
d75229d74   Deepak   fixed dob issue a...
1
2
3
4
5
6
7
8
  // import {Parents } from '/imports/collections/parents/methods'
  import _                                  from 'lodash';
  import { Meteor }                         from 'meteor/meteor';
  import { ValidatedMethod }                from 'meteor/mdg:validated-method';
  import { SimpleSchema }                   from 'meteor/aldeed:simple-schema';
  import { DDPRateLimiter }                 from 'meteor/ddp-rate-limiter';
  import { Bert }                           from 'meteor/themeteorchef:bert';
  import { Users }                          from '/imports/collections/users/index';
ec5f044a9   Deepak   Finished add teac...
9
  import { Staffs }                         from '/imports/collections/staff/index';
d75229d74   Deepak   fixed dob issue a...
10
  import { Orgs }                           from '/imports/collections/orgs/index';
ec5f044a9   Deepak   Finished add teac...
11
12
  export const staffMethods = new ValidatedMethod({
    name: 'staff.method',
d75229d74   Deepak   fixed dob issue a...
13
14
15
16
17
18
19
20
21
22
  
    validate: new SimpleSchema({
      itemId: { type: String },
    }).validator(),
  
    run({itemId}) {
      return {};
    },
  
  });
ec5f044a9   Deepak   Finished add teac...
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
  
  export const staffAddNew = new ValidatedMethod({
    name: 'staff.addNew',
  
    validate: new SimpleSchema({
      employeeId:     { type: String },
      firstName:      { type: String },
      lastName:       { type: String },
      martialStatus:  { type: String },
      gender:         { type: String },
      dob:            { type: String },
      email:          { type: String },
      phone:          { type: String },
      address:        { type: String },
      type:           { type: String },
      doj:            { type: String },
      teaching:       { type: String },
      qualifaication: { type: String },
      specialization: { type: String },
      university:     { type: String },
      degreeFrom:     { type: String },
      degreeEnded:    { type: String },
    }).validator(),
  
    run(data) {
      const user = Users.findOne({_id: Meteor.userId()});
      if(!user) return false;
      const org = Orgs.findOne({_id: user.orgId});
      if(!org) return false;
      // console.log(data);return true;
      orgId = user.orgId;
      newUserId = Users.insert({
        emails:     [{address:data.email, verified: false}],
        phones:     [{number:data.phone, verified: false}],
        firstName:  data.firstName,
        lastName:   data.lastName,
        address:    data.address,
        orgId:      orgId,
        role:       'STAFF'
      });
      console.log("newUserId");
      console.log(newUserId);
      if(newUserId){
        newStaffId = Staffs.insert({
          userId: newUserId,
          orgId: orgId,
          employeeId:  data.employeeId,
          martialStatus:data.martialStatus,
          gender: data.gender,
          dob: data.dob,
          teaching: data.teaching,
          type: data.type,
          qualifaication: data.qualifaication,
          specialization: data.specialization,
          university: data.university,
          degreeFrom: data.degreeFrom,
          degreeEnded: data.degreeEnded
        });
      }
      console.log("newStaffId");
      console.log(newStaffId);
      return {};
    },
  
  });