Commit d19761913001817679ef8f9fe1203aae27cab2b6
1 parent
15998a6afd
Exists in
master
added parent schema
Showing
4 changed files
with
581 additions
and
18 deletions
Show diff stats
imports/client/views/org/admin/students/addStudentForm.js
1 | import _ from 'lodash'; | 1 | import _ from 'lodash'; |
2 | import { Meteor } from 'meteor/meteor'; | 2 | import { Meteor } from 'meteor/meteor'; |
3 | 3 | ||
4 | import React, { Component } from 'react'; | 4 | import React, { Component } from 'react'; |
5 | import { Link,browserHistory } from 'react-router'; | 5 | import { Link,browserHistory } from 'react-router'; |
6 | import { Form, FormGroup,InputGroup, | 6 | import { Form, FormGroup,InputGroup, |
7 | DropdownButton,MenuItem,ControlLabel, | 7 | DropdownButton,MenuItem,ControlLabel, |
8 | SplitButton, | 8 | SplitButton, |
9 | FormControl,Glyphicon,Button } from 'react-bootstrap'; | 9 | FormControl,Glyphicon,Button } from 'react-bootstrap'; |
10 | import DatePicker from 'react-bootstrap-date-picker' | 10 | import DatePicker from 'react-bootstrap-date-picker' |
11 | import {addStudentManually} from '/imports/collections/students/methods'; | 11 | import {addStudentManually} from '/imports/collections/students/methods'; |
12 | 12 | ||
13 | export class AddStudentForm extends Component { | 13 | export class AddStudentForm extends Component { |
14 | 14 | ||
15 | constructor(props) { | 15 | constructor(props) { |
16 | super(props); | 16 | super(props); |
17 | this.state = { | 17 | this.state = { |
18 | admissionId: "", | 18 | admissionId: "", |
19 | firstName: "", | 19 | firstName: "", |
20 | lastName: "", | 20 | lastName: "", |
21 | middleName: "", | 21 | middleName: "", |
22 | email: "", | 22 | email: "", |
23 | dob: "", | 23 | dob: "", |
24 | formattedDob: "", | 24 | formattedDob: "", |
25 | gender: "", | 25 | gender: "", |
26 | rollNo: "", | 26 | rollNo: "", |
27 | class: "", | 27 | class: "", |
28 | section: "", | 28 | section: "", |
29 | community: "", | ||
29 | bloodGroup: "", | 30 | bloodGroup: "", |
30 | phone: "", | 31 | phone: "", |
31 | address: "", | 32 | address: "", |
32 | city: "", | 33 | city: "", |
33 | state: "", | 34 | state: "", |
34 | parentName: "", | 35 | parentName: "", |
35 | parentEmail: "", | 36 | parentEmail: "", |
36 | relation: "", | 37 | relation: "", |
37 | profession: "", | 38 | profession: "", |
38 | parentGender: "", | 39 | parentGender: "", |
39 | parentPhone: "", | 40 | parentPhone: "", |
40 | parentAddress: "", | 41 | parentAddress: "", |
41 | parentCity: "", | 42 | parentCity: "", |
42 | parentState: "", | 43 | parentState: "", |
43 | parentZipcode: "", | 44 | parentZipcode: "", |
44 | }; | 45 | }; |
45 | this.onUpdate = this.onUpdate.bind(this); | 46 | this.onUpdate = this.onUpdate.bind(this); |
46 | this.handleDob = this.handleDob.bind(this); | 47 | this.handleDob = this.handleDob.bind(this); |
47 | }; | 48 | }; |
48 | 49 | ||
49 | onUpdate(key, value) { | 50 | onUpdate(key, value) { |
50 | this.setState({[key]: value}); | 51 | this.setState({[key]: value}); |
51 | }; | 52 | }; |
52 | 53 | ||
53 | handleDob(value, formattedValue) { | 54 | handleDob(value, formattedValue) { |
54 | this.setState({ | 55 | this.setState({ |
55 | dob: value, // ISO String, ex: "2016-11-19T12:00:00.000Z" | 56 | dob: value, // ISO String, ex: "2016-11-19T12:00:00.000Z" |
56 | formattedDob: formattedValue // Formatted String, ex: "11/19/2016" | 57 | formattedDob: formattedValue // Formatted String, ex: "11/19/2016" |
57 | }); | 58 | }); |
58 | } | 59 | } |
59 | addStudent(e){ | 60 | addStudent(e){ |
60 | e.preventDefault(); | 61 | e.preventDefault(); |
61 | e.persist(); | 62 | e.persist(); |
62 | const firstName = this.state.firstName; | 63 | const firstName = this.state.firstName; |
63 | const middleName = this.state.middleName; | 64 | const middleName = this.state.middleName; |
64 | const lastName = this.state.lastName; | 65 | const lastName = this.state.lastName; |
65 | if(firstName==""){ | 66 | const admissionId = this.state.admissionId; |
67 | const email = this.state.email; | ||
68 | const dob = this.state.dob; | ||
69 | const formattedDob = this.state.formattedDob; | ||
70 | const gender = this.state.gender; | ||
71 | const rollNo = this.state.rollNo; | ||
72 | const studentclass = this.state.class; | ||
73 | const section = this.state.section; | ||
74 | const community = this.state.community; | ||
75 | const bloodGroup = this.state.bloodGroup; | ||
76 | const phone = this.state.phone; | ||
77 | const address = this.state.address; | ||
78 | const city = this.state.city; | ||
79 | const state = this.state.state; | ||
80 | const parentName = this.state.parentName; | ||
81 | const parentEmail = this.state.parentEmail; | ||
82 | const relation = this.state.relation; | ||
83 | const profession = this.state.profession; | ||
84 | const parentGender = this.state.parentGender; | ||
85 | const parentPhone = this.state.parentPhone; | ||
86 | const parentAddress = this.state.parentAddress; | ||
87 | const parentCity = this.state.parentCity; | ||
88 | const parentState = this.state.parentState; | ||
89 | const parentZipcode = this.state.parentZipcode; | ||
90 | if(admissionId==""){ | ||
91 | Bert.alert('Enter Admission Id!', 'danger'); | ||
92 | }else if(firstName==""){ | ||
66 | Bert.alert('Enter Fist Name', 'danger'); | 93 | Bert.alert('Enter Fist Name', 'danger'); |
67 | } else if(middleName==""){ | 94 | } else if(middleName==""){ |
68 | Bert.alert('Enter Middle name!', 'danger'); | 95 | Bert.alert('Enter Middle name!', 'danger'); |
69 | } else{ | 96 | }else if(lastName==""){ |
97 | Bert.alert('Enter Last name!', 'danger'); | ||
98 | }else if(email==""){ | ||
99 | Bert.alert('Enter email!', 'danger'); | ||
100 | }else if(dob==""){ | ||
101 | Bert.alert('Enter DOB!', 'danger'); | ||
102 | }else if(gender==""){ | ||
103 | Bert.alert('Enter Student Gender!', 'danger'); | ||
104 | }else if(studentclass==""){ | ||
105 | Bert.alert('Enter Class!', 'danger'); | ||
106 | }else if(section==""){ | ||
107 | Bert.alert('Enter Section!', 'danger'); | ||
108 | }else if(community==""){ | ||
109 | Bert.alert('Enter Section!', 'danger'); | ||
110 | }else if(bloodGroup==""){ | ||
111 | Bert.alert('Enter Blood Group!', 'danger'); | ||
112 | }else if(phone==""){ | ||
113 | Bert.alert('Enter phone!', 'danger'); | ||
114 | }else if(address==""){ | ||
115 | Bert.alert('Enter address!', 'danger'); | ||
116 | }else if(city==""){ | ||
117 | Bert.alert('Enter city!', 'danger'); | ||
118 | }else if(state==""){ | ||
119 | Bert.alert('Enter state!', 'danger'); | ||
120 | }else if(parentName==""){ | ||
121 | Bert.alert('Enter Parent name!', 'danger'); | ||
122 | }else if(parentEmail==""){ | ||
123 | Bert.alert('Enter Parent Email!', 'danger'); | ||
124 | }else if(relation==""){ | ||
125 | Bert.alert('Enter relation!', 'danger'); | ||
126 | }else if(profession==""){ | ||
127 | Bert.alert('Enter parent profession!', 'danger'); | ||
128 | }else if(parentGender==""){ | ||
129 | Bert.alert("Enter Parent's Gender!", 'danger'); | ||
130 | }else if(parentPhone==""){ | ||
131 | Bert.alert("Enter Parent's Phone!", 'danger'); | ||
132 | }else if(parentAddress==""){ | ||
133 | Bert.alert("Enter Parent's Address!", 'danger'); | ||
134 | }else if(parentCity==""){ | ||
135 | Bert.alert("Enter Parent's City!", 'danger'); | ||
136 | }else if(parentState==""){ | ||
137 | Bert.alert("Enter Parent's State!", 'danger'); | ||
138 | }else if(parentZipcode==""){ | ||
139 | Bert.alert("Enter Parent's zipcode!", 'danger'); | ||
140 | }else{ | ||
70 | addStudentManually.call({ | 141 | addStudentManually.call({ |
71 | firstName: firstName, | 142 | admissionId, |
72 | middleName: middleName, | 143 | firstName, |
73 | lastName: lastName | 144 | middleName, |
145 | lastName, | ||
146 | email, | ||
147 | dob, | ||
148 | formattedDob, | ||
149 | gender, | ||
150 | rollNo, | ||
151 | studentclass, | ||
152 | section, | ||
153 | community, | ||
154 | bloodGroup, | ||
155 | phone, | ||
156 | address, | ||
157 | city, | ||
158 | state, | ||
159 | parentName, | ||
160 | parentEmail, | ||
161 | relation, | ||
162 | profession, | ||
163 | parentGender, | ||
164 | parentPhone, | ||
165 | parentAddress, | ||
166 | parentCity, | ||
167 | parentState, | ||
168 | parentZipcode | ||
74 | }, function (error, result) { | 169 | }, function (error, result) { |
75 | console.log(error); | 170 | console.log(error); |
76 | console.log(result); | 171 | console.log(result); |
77 | }); | 172 | }); |
78 | } | 173 | } |
79 | } | 174 | } |
80 | render() { | 175 | render() { |
81 | return ( | 176 | return ( |
82 | <Form onSubmit={ (e) => this.addStudent(e) } inline> | 177 | <Form onSubmit={ (e) => this.addStudent(e) } inline> |
83 | <FormGroup controlId="admissionId"> | 178 | <FormGroup controlId="admissionId"> |
84 | <ControlLabel>Admission Id</ControlLabel> | 179 | <ControlLabel>Admission Id</ControlLabel> |
85 | <FormControl | 180 | <FormControl |
86 | type="text" | 181 | type="text" |
87 | value={this.state.admissionId} | 182 | value={this.state.admissionId} |
88 | placeholder="admission Id" | 183 | placeholder="admission Id" |
89 | onChange={e=>this.onUpdate('admissionId',e.target.value)} | 184 | onChange={e=>this.onUpdate('admissionId',e.target.value)} |
90 | /> | 185 | /> |
91 | </FormGroup> | 186 | </FormGroup> |
92 | 187 | ||
93 | <FormGroup controlId="firstName"> | 188 | <FormGroup controlId="firstName"> |
94 | <ControlLabel>First Name</ControlLabel> | 189 | <ControlLabel>First Name</ControlLabel> |
95 | <FormControl | 190 | <FormControl |
96 | type="text" | 191 | type="text" |
97 | value={this.state.firstName} | 192 | value={this.state.firstName} |
98 | placeholder="First Name" | 193 | placeholder="First Name" |
99 | onChange={e=>this.onUpdate('firstName',e.target.value)} | 194 | onChange={e=>this.onUpdate('firstName',e.target.value)} |
100 | /> | 195 | /> |
101 | </FormGroup> | 196 | </FormGroup> |
102 | <FormGroup controlId="middleName"> | 197 | <FormGroup controlId="middleName"> |
103 | <ControlLabel>Middle Name</ControlLabel> | 198 | <ControlLabel>Middle Name</ControlLabel> |
104 | <FormControl | 199 | <FormControl |
105 | type="text" | 200 | type="text" |
106 | value={this.state.middleName} | 201 | value={this.state.middleName} |
107 | placeholder="Middle Name" | 202 | placeholder="Middle Name" |
108 | onChange={e=>this.onUpdate('middleName',e.target.value)} | 203 | onChange={e=>this.onUpdate('middleName',e.target.value)} |
109 | /> | 204 | /> |
110 | </FormGroup> | 205 | </FormGroup> |
206 | |||
111 | <FormGroup controlId="lastName"> | 207 | <FormGroup controlId="lastName"> |
112 | <ControlLabel>Last Name</ControlLabel> | 208 | <ControlLabel>Last Name</ControlLabel> |
113 | <FormControl | 209 | <FormControl |
114 | type="text" | 210 | type="text" |
115 | value={this.state.lastName} | 211 | value={this.state.lastName} |
116 | placeholder="Last Name" | 212 | placeholder="Last Name" |
117 | onChange={e=>this.onUpdate('lastName',e.target.value)} | 213 | onChange={e=>this.onUpdate('lastName',e.target.value)} |
118 | /> | 214 | /> |
215 | |||
119 | </FormGroup> | 216 | </FormGroup> |
120 | <FormGroup controlId="email"> | 217 | <FormGroup controlId="email"> |
121 | <ControlLabel>Email</ControlLabel> | 218 | <ControlLabel>Email</ControlLabel> |
122 | <FormControl | 219 | <FormControl |
123 | type="email" | 220 | type="email" |
124 | value={this.state.email} | 221 | value={this.state.email} |
125 | placeholder="Email" | 222 | placeholder="Email" |
126 | onChange={e=>this.onUpdate('email',e.target.value)} | 223 | onChange={e=>this.onUpdate('email',e.target.value)} |
127 | /> | 224 | /> |
128 | </FormGroup> | 225 | </FormGroup> |
129 | <FormGroup> | 226 | <FormGroup> |
130 | <ControlLabel>Date of birth</ControlLabel> | 227 | <ControlLabel>Date of birth</ControlLabel> |
131 | <DatePicker id="dob" | 228 | <DatePicker id="dob" |
132 | value={this.state.dob} | 229 | value={this.state.dob} |
133 | onChange={this.handleDob} | 230 | onChange={this.handleDob} |
134 | /> | 231 | /> |
135 | </FormGroup> | 232 | </FormGroup> |
233 | |||
234 | <FormGroup controlId="formControlsSelect"> | ||
235 | <ControlLabel>Gender</ControlLabel> | ||
236 | <FormControl componentClass="select" | ||
237 | placeholder="select" | ||
238 | value={this.state.gender} | ||
239 | onChange={e=>this.onUpdate('gender',e.target.value)} | ||
240 | > | ||
241 | <option value="male">Male</option> | ||
242 | <option value="female">Female</option> | ||
243 | </FormControl> | ||
244 | </FormGroup> | ||
245 | |||
246 | <FormGroup controlId="rollNo"> | ||
247 | <ControlLabel>Roll No</ControlLabel> | ||
248 | <FormControl | ||
249 | type="text" | ||
250 | value={this.state.rollNo} | ||
251 | placeholder="Roll No" | ||
252 | onChange={e=>this.onUpdate('rollNo',e.target.value)} | ||
253 | /> | ||
254 | </FormGroup> | ||
255 | <FormGroup controlId="class"> | ||
256 | <ControlLabel>Class</ControlLabel> | ||
257 | <FormControl | ||
258 | type="text" | ||
259 | value={this.state.class} | ||
260 | placeholder="7" | ||
261 | onChange={e=>this.onUpdate('class',e.target.value)} | ||
262 | /> | ||
263 | </FormGroup> | ||
264 | <FormGroup controlId="section"> | ||
265 | <ControlLabel>Section</ControlLabel> | ||
266 | <FormControl | ||
267 | type="text" | ||
268 | value={this.state.section} | ||
269 | placeholder="B" | ||
270 | onChange={e=>this.onUpdate('section',e.target.value)} | ||
271 | /> | ||
272 | </FormGroup> | ||
273 | |||
274 | <FormGroup controlId="community"> | ||
275 | <ControlLabel>Community</ControlLabel> | ||
276 | <FormControl | ||
277 | type="text" | ||
278 | value={this.state.community} | ||
279 | placeholder="General" | ||
280 | onChange={e=>this.onUpdate('community',e.target.value)} | ||
281 | /> | ||
282 | </FormGroup> | ||
283 | |||
284 | <FormGroup controlId="bloodGroup"> | ||
285 | <ControlLabel>bloodGroup</ControlLabel> | ||
286 | <FormControl | ||
287 | type="text" | ||
288 | value={this.state.bloodGroup} | ||
289 | placeholder="B+" | ||
290 | onChange={e=>this.onUpdate('bloodGroup',e.target.value)} | ||
291 | /> | ||
292 | </FormGroup> | ||
293 | |||
294 | <FormGroup controlId="phone"> | ||
295 | <ControlLabel>Phone</ControlLabel> | ||
296 | <FormControl | ||
297 | type="text" | ||
298 | value={this.state.phone} | ||
299 | placeholder="9999999999" | ||
300 | onChange={e=>this.onUpdate('phone',e.target.value)} | ||
301 | /> | ||
302 | </FormGroup> | ||
303 | |||
304 | <FormGroup controlId="address"> | ||
305 | <ControlLabel>Address</ControlLabel> | ||
306 | <FormControl | ||
307 | type="text" | ||
308 | value={this.state.address} | ||
309 | placeholder="#876, Street, town" | ||
310 | onChange={e=>this.onUpdate('address',e.target.value)} | ||
311 | /> | ||
312 | </FormGroup> | ||
313 | |||
314 | <FormGroup controlId="city"> | ||
315 | <ControlLabel>City</ControlLabel> | ||
316 | <FormControl | ||
317 | type="text" | ||
318 | value={this.state.city} | ||
319 | placeholder="Chennai" | ||
320 | onChange={e=>this.onUpdate('city',e.target.value)} | ||
321 | /> | ||
322 | </FormGroup> | ||
323 | |||
324 | <FormGroup controlId="state"> | ||
325 | <ControlLabel>State</ControlLabel> | ||
326 | <FormControl | ||
327 | type="text" | ||
328 | value={this.state.state} | ||
329 | placeholder="Tamilnadu" | ||
330 | onChange={e=>this.onUpdate('state',e.target.value)} | ||
331 | /> | ||
332 | </FormGroup> | ||
333 | |||
334 | <FormGroup controlId="parentName"> | ||
335 | <ControlLabel>Parent Name</ControlLabel> | ||
336 | <FormControl | ||
337 | type="text" | ||
338 | value={this.state.parentName} | ||
339 | placeholder="John" | ||
340 | onChange={e=>this.onUpdate('parentName',e.target.value)} | ||
341 | /> | ||
342 | </FormGroup> | ||
343 | |||
344 | <FormGroup controlId="parentEmail"> | ||
345 | <ControlLabel>Parent Email</ControlLabel> | ||
346 | <FormControl | ||
347 | type="text" | ||
348 | value={this.state.parentEmail} | ||
349 | placeholder="john@email.com" | ||
350 | onChange={e=>this.onUpdate('parentEmail',e.target.value)} | ||
351 | /> | ||
352 | </FormGroup> | ||
353 | |||
354 | <FormGroup controlId="relation"> | ||
355 | <ControlLabel>Relation</ControlLabel> | ||
356 | <FormControl | ||
357 | type="text" | ||
358 | value={this.state.relation} | ||
359 | placeholder="Father" | ||
360 | onChange={e=>this.onUpdate('relation',e.target.value)} | ||
361 | /> | ||
362 | </FormGroup> | ||
363 | |||
364 | <FormGroup controlId="profession"> | ||
365 | <ControlLabel>Profession</ControlLabel> | ||
366 | <FormControl | ||
367 | type="text" | ||
368 | value={this.state.profession} | ||
369 | placeholder="Farmer" | ||
370 | onChange={e=>this.onUpdate('profession',e.target.value)} | ||
371 | /> | ||
372 | </FormGroup> | ||
373 | |||
374 | <FormGroup controlId="parentGender"> | ||
375 | <ControlLabel>Parent Gender</ControlLabel> | ||
376 | <FormControl componentClass="select" | ||
377 | placeholder="select" | ||
378 | value={this.state.parentGender} | ||
379 | onChange={e=>this.onUpdate('parentGender',e.target.value)} | ||
380 | > | ||
381 | <option value="male">Male</option> | ||
382 | <option value="female">Female</option> | ||
383 | </FormControl> | ||
384 | </FormGroup> | ||
385 | |||
386 | <FormGroup controlId="parentPhone"> | ||
387 | <ControlLabel>Parent Phone</ControlLabel> | ||
388 | <FormControl | ||
389 | type="text" | ||
390 | value={this.state.parentPhone} | ||
391 | placeholder="9876543210" | ||
392 | onChange={e=>this.onUpdate('parentPhone',e.target.value)} | ||
393 | /> | ||
394 | </FormGroup> | ||
395 | |||
396 | <FormGroup controlId="parentAddress"> | ||
397 | <ControlLabel>Parent Address</ControlLabel> | ||
398 | <FormControl | ||
399 | type="text" | ||
400 | value={this.state.parentAddress} | ||
401 | placeholder="#12, street, town" | ||
402 | onChange={e=>this.onUpdate('parentAddress',e.target.value)} | ||
403 | /> | ||
404 | </FormGroup> | ||
405 | |||
406 | <FormGroup controlId="parentCity"> | ||
407 | <ControlLabel>Parent City</ControlLabel> | ||
408 | <FormControl | ||
409 | type="text" | ||
410 | value={this.state.parentCity} | ||
411 | placeholder="Chennai" | ||
412 | onChange={e=>this.onUpdate('parentCity',e.target.value)} | ||
413 | /> | ||
414 | </FormGroup> | ||
415 | |||
416 | <FormGroup controlId="parentState"> | ||
417 | <ControlLabel>Parent State</ControlLabel> | ||
418 | <FormControl | ||
419 | type="text" | ||
420 | value={this.state.parentState} | ||
421 | placeholder="Tamilnadu" | ||
422 | onChange={e=>this.onUpdate('parentState',e.target.value)} | ||
423 | /> | ||
424 | </FormGroup> | ||
425 | |||
426 | <FormGroup controlId="parentZipcode"> | ||
427 | <ControlLabel>Parent Zipcode</ControlLabel> | ||
428 | <FormControl | ||
429 | type="text" | ||
430 | value={this.state.parentZipcode} | ||
431 | placeholder="600031" | ||
432 | onChange={e=>this.onUpdate('parentZipcode',e.target.value)} | ||
433 | /> | ||
434 | </FormGroup> | ||
136 | <Button type="submit" bsStyle="default">Add Student</Button> | 435 | <Button type="submit" bsStyle="default">Add Student</Button> |
137 | </Form> | 436 | </Form> |
138 | ); | 437 | ); |
139 | }; | 438 | }; |
140 | 439 | ||
141 | }; | 440 | }; |
142 | 441 |
imports/collections/parents/index.js
File was created | 1 | // import {Parents } from '/imports/collections/parents/index' | |
2 | |||
3 | import _ from 'lodash'; | ||
4 | import { Meteor } from 'meteor/meteor'; | ||
5 | import { Mongo } from 'meteor/mongo'; | ||
6 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | ||
7 | |||
8 | import { Orgs } from '/imports/collections/orgs/index'; | ||
9 | import { Users } from '/imports/collections/users/index'; | ||
10 | |||
11 | class Parent { | ||
12 | constructor(doc) { | ||
13 | _.assign(this, doc); | ||
14 | }; | ||
15 | |||
16 | getUserIds() { | ||
17 | return _.filter(_.map(this.users, 'userId')); | ||
18 | }; | ||
19 | }; | ||
20 | export { Parent }; | ||
21 | |||
22 | class ParentsCollection extends Mongo.Collection { | ||
23 | insert(item, callback) { | ||
24 | _.assign(item, { | ||
25 | createdAt: new Date().getTime(), | ||
26 | }); | ||
27 | return super.insert(item, callback); | ||
28 | }; | ||
29 | }; | ||
30 | |||
31 | export const Parents = new ParentsCollection('Parents', { | ||
32 | transform: (item) => { | ||
33 | return new Parent(item); | ||
34 | }, | ||
35 | }); | ||
36 | |||
37 | _.assign(Parents, { | ||
38 | allStudents: () => { | ||
39 | const user = Users.current(); | ||
40 | if(!user) return null; | ||
41 | return Orgs.find({'users.userId': user._id}); | ||
42 | }, | ||
43 | current: () => { | ||
44 | const user = Users.current(); | ||
45 | if(!user) return null; | ||
46 | return Orgs.findOne({_id: user.orgId}); | ||
47 | }, | ||
48 | currentOrgUsers: () => { | ||
49 | const OrgsArr = Orgs.current(); | ||
50 | if(!OrgsArr) return null; | ||
51 | return OrgsArr.users; | ||
52 | }, | ||
53 | |||
54 | }); | ||
55 | |||
56 | Parents.deny({ | ||
57 | insert() { return true; }, | ||
58 | update() { return true; }, | ||
59 | remove() { return true; }, | ||
60 | }); | ||
61 | |||
62 | |||
63 | Parents.schema = new SimpleSchema({ | ||
64 | userId: { type: String }, | ||
65 | orgId: { type: String }, | ||
66 | relationship: { type: String, optional: true }, | ||
67 | gender: { type: String, optional: true }, | ||
68 | profession: { type: String, optional: true }, | ||
69 | permanentAddress: { | ||
70 | type: new SimpleSchema({ | ||
71 | home: { type: String, optional: true }, | ||
72 | street: { type: String, optional: true }, | ||
73 | town: { type: String, optional: true }, | ||
74 | city: { type: String, optional: true }, | ||
75 | state: { type: String, optional: true }, | ||
76 | zip: { type: String, optional: true }, | ||
77 | }), | ||
78 | optional: true | ||
79 | }, | ||
80 | currentAddress: { | ||
81 | type: new SimpleSchema({ | ||
82 | home: { type: String, optional: true }, | ||
83 | street: { type: String, optional: true }, | ||
84 | town: { type: String, optional: true }, | ||
85 | city: { type: String, optional: true }, | ||
86 | state: { type: String, optional: true }, | ||
87 | zip: { type: String, optional: true }, | ||
88 | }), | ||
89 | optional: true | ||
90 | }, | ||
91 | services: { | ||
92 | type: Object, | ||
93 | optional: true, | ||
94 | blackbox: true, | ||
95 | }, | ||
96 | |||
97 | isMetaUser: { type: Boolean, optional: true }, | ||
98 | |||
99 | createdAt: { type: Date, autoValue: function(){return new Date();}} | ||
100 | |||
101 | }); | ||
102 | |||
103 | Parents.attachSchema(Parents.schema); | ||
104 | |||
105 | Parents.privateFields = { | ||
106 | orgId: 1, | ||
107 | address: 1, | ||
108 | |||
109 | isMetaUser: 1, | ||
110 | createdAt: 1, | ||
111 | }; | ||
112 | |||
113 | Parents.publicFields = { | ||
114 | firstName: 1, | ||
115 | lastName: 1, | ||
116 | emails: 1, | ||
117 | |||
118 | createdAt: 1, | ||
119 | }; | ||
120 |
imports/collections/parents/methods.js
File was created | 1 | // import {Parents } from '/imports/collections/parents/methods' | |
2 | import _ from 'lodash'; | ||
3 | import { Meteor } from 'meteor/meteor'; | ||
4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | ||
5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | ||
6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | ||
7 | import { Bert } from 'meteor/themeteorchef:bert'; | ||
8 | import { Users } from '/imports/collections/users/index'; | ||
9 | import { Students } from '/imports/collections/students/index'; | ||
10 | import { Orgs } from '/imports/collections/orgs/index'; | ||
11 | export const studentMethods = new ValidatedMethod({ | ||
12 | name: 'student.method', | ||
13 | |||
14 | validate: new SimpleSchema({ | ||
15 | itemId: { type: String }, | ||
16 | }).validator(), | ||
17 | |||
18 | run({itemId}) { | ||
19 | return {}; | ||
20 | }, | ||
21 | |||
22 | }); | ||
23 | |||
24 | export const addStudentManually = new ValidatedMethod({ | ||
25 | name: 'student.addManually', | ||
26 | |||
27 | validate: new SimpleSchema({ | ||
28 | admissionId: { type: String }, | ||
29 | firstName: { type: String }, | ||
30 | middleName: { type: String }, | ||
31 | lastName: { type: String }, | ||
32 | email: { type: String }, | ||
33 | dob: { type: String }, | ||
34 | formattedDob: { type: String }, | ||
35 | gender: { type: String }, | ||
36 | rollNo: { type: String }, | ||
37 | studentclass: { type: String }, | ||
38 | section: { type: String }, | ||
39 | community: { type: String }, | ||
40 | bloodGroup: { type: String }, | ||
41 | phone: { type: String }, | ||
42 | address: { type: String }, | ||
43 | city: { type: String }, | ||
44 | state: { type: String }, | ||
45 | parentName: { type: String }, | ||
46 | parentEmail: { type: String }, | ||
47 | relation: { type: String }, | ||
48 | profession: { type: String }, | ||
49 | parentGender: { type: String }, | ||
50 | parentPhone: { type: String }, | ||
51 | parentAddress: { type: String }, | ||
52 | parentCity: { type: String }, | ||
53 | parentState: { type: String }, | ||
54 | parentZipcode: { type: String }, | ||
55 | }).validator(), | ||
56 | |||
57 | run(data) { | ||
58 | console.log("data"); | ||
59 | console.log(data); | ||
60 | const user = Users.findOne({_id: this.userId}); | ||
61 | orgId = user.orgId; | ||
62 | newStudentId = Users.insert({ | ||
63 | emails: [data.email], | ||
64 | username: firstName, | ||
65 | firstName: firstName, | ||
66 | middleName: middleName, | ||
67 | lastName: lastName, | ||
68 | orgId: orgId, | ||
69 | role: 'STUDENT' | ||
70 | }); | ||
71 | newParentId = Users.insert({ | ||
72 | emails: [data.parentEmail], | ||
73 | username: parentName, | ||
74 | firstName: parentName, | ||
75 | orgId: orgId, | ||
76 | role: 'PARENT' | ||
77 | }); | ||
78 | console.log("newUserId"); | ||
79 | console.log(newUserId); | ||
80 | if(newUserId){ | ||
81 | Students.insert({ | ||
82 | userId: newUserId, | ||
83 | orgId: orgId, | ||
84 | admissionId: data.admissionId, | ||
85 | address: data.address, | ||
86 | gender: data.gender, | ||
87 | dob: data.dob, | ||
88 | rollNo: data.rollNo, | ||
89 | class: data.studentclass, | ||
90 | section: data.section, | ||
91 | bloodGroup: data.bloodGroup, | ||
92 | community: data.community, | ||
93 | |||
94 | }); | ||
95 | } | ||
96 | return {newUserId}; | ||
97 | }, | ||
98 | |||
99 | }); | ||
100 |
imports/collections/students/methods.js
1 | // import { } from '/imports/collections/students/methods'; | 1 | // import { } from '/imports/collections/students/methods'; |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | 4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | 6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
7 | import { Bert } from 'meteor/themeteorchef:bert'; | 7 | import { Bert } from 'meteor/themeteorchef:bert'; |
8 | import { Users } from '/imports/collections/users/index'; | 8 | import { Users } from '/imports/collections/users/index'; |
9 | import { Students } from '/imports/collections/students/index'; | 9 | import { Students } from '/imports/collections/students/index'; |
10 | import { Orgs } from '/imports/collections/orgs/index'; | 10 | import { Orgs } from '/imports/collections/orgs/index'; |
11 | export const studentMethods = new ValidatedMethod({ | 11 | export const studentMethods = new ValidatedMethod({ |
12 | name: 'student.method', | 12 | name: 'student.method', |
13 | 13 | ||
14 | validate: new SimpleSchema({ | 14 | validate: new SimpleSchema({ |
15 | itemId: { type: String }, | 15 | itemId: { type: String }, |
16 | }).validator(), | 16 | }).validator(), |
17 | 17 | ||
18 | run({itemId}) { | 18 | run({itemId}) { |
19 | return {}; | 19 | return {}; |
20 | }, | 20 | }, |
21 | 21 | ||
22 | }); | 22 | }); |
23 | 23 | ||
24 | export const addStudentManually = new ValidatedMethod({ | 24 | export const addStudentManually = new ValidatedMethod({ |
25 | name: 'student.addManually', | 25 | name: 'student.addManually', |
26 | 26 | ||
27 | validate: new SimpleSchema({ | 27 | validate: new SimpleSchema({ |
28 | firstName: { type: String }, | 28 | admissionId: { type: String }, |
29 | middleName: { type: String }, | 29 | firstName: { type: String }, |
30 | lastName: { type: String }, | 30 | middleName: { type: String }, |
31 | lastName: { type: String }, | ||
32 | email: { type: String }, | ||
33 | dob: { type: String }, | ||
34 | formattedDob: { type: String }, | ||
35 | gender: { type: String }, | ||
36 | rollNo: { type: String }, | ||
37 | studentclass: { type: String }, | ||
38 | section: { type: String }, | ||
39 | community: { type: String }, | ||
40 | bloodGroup: { type: String }, | ||
41 | phone: { type: String }, | ||
42 | address: { type: String }, | ||
43 | city: { type: String }, | ||
44 | state: { type: String }, | ||
45 | parentName: { type: String }, | ||
46 | parentEmail: { type: String }, | ||
47 | relation: { type: String }, | ||
48 | profession: { type: String }, | ||
49 | parentGender: { type: String }, | ||
50 | parentPhone: { type: String }, | ||
51 | parentAddress: { type: String }, | ||
52 | parentCity: { type: String }, | ||
53 | parentState: { type: String }, | ||
54 | parentZipcode: { type: String }, | ||
31 | }).validator(), | 55 | }).validator(), |
32 | 56 | ||
33 | run({firstName,middleName,lastName}) { | 57 | run(data) { |
58 | console.log("data"); | ||
59 | console.log(data); | ||
34 | const user = Users.findOne({_id: this.userId}); | 60 | const user = Users.findOne({_id: this.userId}); |
35 | orgId = user.orgId; | 61 | orgId = user.orgId; |
36 | newUserId = Users.insert({ | 62 | newStudentId = Users.insert({ |
37 | username: firstName, | 63 | emails: [data.email], |
38 | firstName: firstName, | 64 | username: firstName, |
39 | middleName: middleName, | 65 | firstName: firstName, |
40 | lastName: lastName, | 66 | middleName: middleName, |
41 | orgId: orgId, | 67 | lastName: lastName, |
42 | role: 'STUDENT' | 68 | orgId: orgId, |
69 | role: 'STUDENT' | ||
70 | }); | ||
71 | newParentId = Users.insert({ | ||
72 | emails: [data.parentEmail], | ||
73 | username: parentName, | ||
74 | firstName: parentName, | ||
75 | orgId: orgId, | ||
76 | role: 'PARENT' | ||
43 | }); | 77 | }); |
78 | console.log("newUserId"); | ||
79 | console.log(newUserId); | ||
44 | if(newUserId){ | 80 | if(newUserId){ |
45 | Students.insert({ | 81 | Students.insert({ |
46 | userId: newUserId, | 82 | userId: newUserId, |
47 | orgId: orgId, | 83 | orgId: orgId, |
84 | admissionId: data.admissionId, | ||
85 | address: data.address, | ||
86 | gender: data.gender, | ||
87 | dob: data.dob, | ||
88 | rollNo: data.rollNo, | ||
89 | class: data.studentclass, | ||
90 | section: data.section, | ||
91 | bloodGroup: data.bloodGroup, | ||
92 | community: data.community, | ||
93 | |||
48 | }); | 94 | }); |
49 | } | 95 | } |
50 | return {newUserId}; | 96 | return {newUserId}; |
51 | }, | 97 | }, |
52 | 98 | ||
53 | }); | 99 | }); |
54 | 100 |