Blame view

imports/collections/parents/methods.js 3.13 KB
d19761913   Deepak   added parent schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
88
89
90
91
92
93
94
95
96
97
98
99
  // 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';
  import { Students }                       from '/imports/collections/students/index';
  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({
      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 },
    }).validator(),
  
    run(data) {
      console.log("data");
      console.log(data);
      const user = Users.findOne({_id: this.userId});
      orgId = user.orgId;
      newStudentId = Users.insert({
        emails:     [data.email],
        username:   firstName,
        firstName:  firstName,
        middleName: middleName,
        lastName:   lastName,
        orgId:      orgId,
        role:       'STUDENT'
      });
      newParentId = Users.insert({
        emails:     [data.parentEmail],
        username:   parentName,
        firstName:  parentName,
        orgId:      orgId,
        role:       'PARENT'
      });
      console.log("newUserId");
      console.log(newUserId);
      if(newUserId){
        Students.insert({
          userId: newUserId,
          orgId: orgId,
          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,
  
        });
      }
      return {newUserId};
    },
  
  });