Blame view

imports/collections/students/methods.js 3.85 KB
d0099dd88   Deepak   student detail pa...
1
2
3
4
5
6
7
8
9
  // import { } from '/imports/collections/students/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';
  import { Students }                       from '/imports/collections/students/index';
1c4a8cc5d   Deepak   added parents dat...
10
  import { Parents }                        from '/imports/collections/parents/index';
d0099dd88   Deepak   student detail pa...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  import { Orgs }                           from '/imports/collections/orgs/index';
  export const studentMethods = new ValidatedMethod({
    name: 'student.method',
  
    validate: new SimpleSchema({
      itemId: { type: String },
    }).validator(),
  
    run({itemId}) {
      return {};
    },
  
  });
  
  export const addStudentManually = new ValidatedMethod({
    name: 'student.addManually',
  
    validate: new SimpleSchema({
d19761913   Deepak   added parent schema
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
      admissionId:    { type: String },
      firstName:      { type: String },
      middleName:     { type: String },
      lastName:       { type: String },
      email:          { type: String },
      dob:            { type: String },
      formattedDob:   { type: String },
      gender:         { type: String },
      rollNo:         { type: String },
      studentclass:   { type: String },
      section:        { type: String },
      community:      { type: String },
      bloodGroup:     { type: String },
      phone:          { type: String },
      address:        { type: String },
      city:           { type: String },
      state:          { type: String },
      parentName:     { type: String },
      parentEmail:    { type: String },
      relation:       { type: String },
      profession:     { type: String },
      parentGender:   { type: String },
      parentPhone:    { type: String },
      parentAddress:  { type: String },
      parentCity:     { type: String },
      parentState:    { type: String },
      parentZipcode:  { type: String },
d0099dd88   Deepak   student detail pa...
56
    }).validator(),
d19761913   Deepak   added parent schema
57
58
59
    run(data) {
      console.log("data");
      console.log(data);
d0099dd88   Deepak   student detail pa...
60
61
      const user = Users.findOne({_id: this.userId});
      orgId = user.orgId;
d19761913   Deepak   added parent schema
62
      newStudentId = Users.insert({
1c4a8cc5d   Deepak   added parents dat...
63
64
65
66
67
        emails:     [{address:data.email, verified: false}],
        username:   data.firstName,
        firstName:  data.firstName,
        middleName: data.middleName,
        lastName:   data.lastName,
d19761913   Deepak   added parent schema
68
69
70
        orgId:      orgId,
        role:       'STUDENT'
      });
1c4a8cc5d   Deepak   added parents dat...
71
72
73
74
      newParentUserId = Users.insert({
        emails:     [{address:data.parentEmail, verified: false}],
        username:   data.parentName,
        firstName:  data.parentName,
d19761913   Deepak   added parent schema
75
76
        orgId:      orgId,
        role:       'PARENT'
d0099dd88   Deepak   student detail pa...
77
      });
1c4a8cc5d   Deepak   added parents dat...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
      if(newParentUserId){
        newParentId = Parents.insert({
          userId: newParentUserId,
          orgId: orgId,
          address: data.address,
          gender: data.gender,
          dob:          data.dob,
          rollNo:       data.rollNo,
          class:        data.studentclass,
          section:      data.section,
          bloodGroup:   data.bloodGroup,
          community:    data.community,
        });
        console.log("newParentUserId");
        console.log(newParentUserId);
      }
d19761913   Deepak   added parent schema
94
      console.log("newUserId");
1c4a8cc5d   Deepak   added parents dat...
95
96
      console.log(newStudentId);
      if(newStudentId){
d0099dd88   Deepak   student detail pa...
97
        Students.insert({
1c4a8cc5d   Deepak   added parents dat...
98
          userId: newStudentId,
d0099dd88   Deepak   student detail pa...
99
          orgId: orgId,
d19761913   Deepak   added parent schema
100
101
102
103
104
105
106
107
108
          admissionId: data.admissionId,
          address: data.address,
          gender: data.gender,
          dob:          data.dob,
          rollNo:       data.rollNo,
          class:        data.studentclass,
          section:      data.section,
          bloodGroup:   data.bloodGroup,
          community:    data.community,
1c4a8cc5d   Deepak   added parents dat...
109
          parent:       [{id: newParentUserId, relatinship: data.relation}]
d0099dd88   Deepak   student detail pa...
110
111
        });
      }
1c4a8cc5d   Deepak   added parents dat...
112
      return {newStudentId};
d0099dd88   Deepak   student detail pa...
113
114
115
    },
  
  });