Blame view

imports/collections/students/methods.js 3.6 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
      admissionId:    { type: String },
      firstName:      { type: String },
d19761913   Deepak   added parent schema
31
32
33
      lastName:       { type: String },
      email:          { type: String },
      dob:            { type: String },
d19761913   Deepak   added parent schema
34
35
      gender:         { type: String },
      rollNo:         { type: String },
d75229d74   Deepak   fixed dob issue a...
36
      studentClass:   { type: String },
d19761913   Deepak   added parent schema
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      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...
54
    }).validator(),
d19761913   Deepak   added parent schema
55
56
57
    run(data) {
      console.log("data");
      console.log(data);
d0099dd88   Deepak   student detail pa...
58
59
      const user = Users.findOne({_id: this.userId});
      orgId = user.orgId;
d19761913   Deepak   added parent schema
60
      newStudentId = Users.insert({
1c4a8cc5d   Deepak   added parents dat...
61
        emails:     [{address:data.email, verified: false}],
1c4a8cc5d   Deepak   added parents dat...
62
        firstName:  data.firstName,
1c4a8cc5d   Deepak   added parents dat...
63
        lastName:   data.lastName,
d19761913   Deepak   added parent schema
64
65
66
        orgId:      orgId,
        role:       'STUDENT'
      });
1c4a8cc5d   Deepak   added parents dat...
67
68
      newParentUserId = Users.insert({
        emails:     [{address:data.parentEmail, verified: false}],
1c4a8cc5d   Deepak   added parents dat...
69
        firstName:  data.parentName,
d19761913   Deepak   added parent schema
70
71
        orgId:      orgId,
        role:       'PARENT'
d0099dd88   Deepak   student detail pa...
72
      });
1c4a8cc5d   Deepak   added parents dat...
73
74
75
76
      if(newParentUserId){
        newParentId = Parents.insert({
          userId: newParentUserId,
          orgId: orgId,
dc0d0c739   Deepak   merged Ajays code
77
78
          address:      data.address,
          gender:       data.gender,
1c4a8cc5d   Deepak   added parents dat...
79
80
          dob:          data.dob,
          rollNo:       data.rollNo,
d75229d74   Deepak   fixed dob issue a...
81
          studentClass: data.studentClass,
1c4a8cc5d   Deepak   added parents dat...
82
83
84
          section:      data.section,
          bloodGroup:   data.bloodGroup,
          community:    data.community,
df05c55ea   Deepak   fixed views for d...
85
          relationship:     data.relation,
1c4a8cc5d   Deepak   added parents dat...
86
        });
1c4a8cc5d   Deepak   added parents dat...
87
      }
1c4a8cc5d   Deepak   added parents dat...
88
      if(newStudentId){
d0099dd88   Deepak   student detail pa...
89
        Students.insert({
1c4a8cc5d   Deepak   added parents dat...
90
          userId: newStudentId,
d0099dd88   Deepak   student detail pa...
91
          orgId: orgId,
d19761913   Deepak   added parent schema
92
93
94
95
96
          admissionId: data.admissionId,
          address: data.address,
          gender: data.gender,
          dob:          data.dob,
          rollNo:       data.rollNo,
d75229d74   Deepak   fixed dob issue a...
97
          class:        data.studentClass,
d19761913   Deepak   added parent schema
98
99
100
          section:      data.section,
          bloodGroup:   data.bloodGroup,
          community:    data.community,
df05c55ea   Deepak   fixed views for d...
101
          parent:       [{id: newParentUserId, relationship: data.relation}]
d0099dd88   Deepak   student detail pa...
102
103
        });
      }
1c4a8cc5d   Deepak   added parents dat...
104
      return {newStudentId};
d0099dd88   Deepak   student detail pa...
105
106
107
    },
  
  });