Blame view
imports/collections/students/methods.js
3.73 KB
d0099dd88
|
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
|
10 |
import { Parents } from '/imports/collections/parents/index'; |
d0099dd88
|
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
|
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
|
56 |
}).validator(), |
d19761913
|
57 58 59 |
run(data) { console.log("data"); console.log(data); |
d0099dd88
|
60 61 |
const user = Users.findOne({_id: this.userId}); orgId = user.orgId; |
d19761913
|
62 |
newStudentId = Users.insert({ |
1c4a8cc5d
|
63 64 65 66 67 |
emails: [{address:data.email, verified: false}], username: data.firstName, firstName: data.firstName, middleName: data.middleName, lastName: data.lastName, |
d19761913
|
68 69 70 |
orgId: orgId, role: 'STUDENT' }); |
1c4a8cc5d
|
71 72 73 74 |
newParentUserId = Users.insert({ emails: [{address:data.parentEmail, verified: false}], username: data.parentName, firstName: data.parentName, |
d19761913
|
75 76 |
orgId: orgId, role: 'PARENT' |
d0099dd88
|
77 |
}); |
1c4a8cc5d
|
78 79 80 81 |
if(newParentUserId){ newParentId = Parents.insert({ userId: newParentUserId, orgId: orgId, |
dc0d0c739
|
82 83 |
address: data.address, gender: data.gender, |
1c4a8cc5d
|
84 85 86 87 88 89 90 |
dob: data.dob, rollNo: data.rollNo, class: data.studentclass, section: data.section, bloodGroup: data.bloodGroup, community: data.community, }); |
1c4a8cc5d
|
91 |
} |
1c4a8cc5d
|
92 |
if(newStudentId){ |
d0099dd88
|
93 |
Students.insert({ |
1c4a8cc5d
|
94 |
userId: newStudentId, |
d0099dd88
|
95 |
orgId: orgId, |
d19761913
|
96 97 98 99 100 101 102 103 104 |
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
|
105 |
parent: [{id: newParentUserId, relatinship: data.relation}] |
d0099dd88
|
106 107 |
}); } |
1c4a8cc5d
|
108 |
return {newStudentId}; |
d0099dd88
|
109 110 111 |
}, }); |