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