Commit c32092e5ea4a736bab6836c77da8f253fa5fa281
1 parent
97d8d6ce88
Exists in
master
added condition on students fetch
Showing
1 changed file
with
2 additions
and
2 deletions
Show diff stats
imports/client/views/org/admin/students/index.js
1 | // import { StudentDataController } from '/imports/client/views/org/admin/students/index' | 1 | // import { StudentDataController } from '/imports/client/views/org/admin/students/index' |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { | 3 | import { |
4 | composeWithTracker, | 4 | composeWithTracker, |
5 | compose, | 5 | compose, |
6 | composeAll | 6 | composeAll |
7 | } from 'react-komposer'; | 7 | } from 'react-komposer'; |
8 | import { Loading } from '/imports/client/components/Loading'; | 8 | import { Loading } from '/imports/client/components/Loading'; |
9 | 9 | ||
10 | import { Orgs } from '/imports/collections/orgs/index'; | 10 | import { Orgs } from '/imports/collections/orgs/index'; |
11 | import { Users } from '/imports/collections/users/index'; | 11 | import { Users } from '/imports/collections/users/index'; |
12 | import { StudentView } from './StudentView'; | 12 | import { StudentView } from './StudentView'; |
13 | import { Students } from '/imports/collections/students/index'; | 13 | import { Students } from '/imports/collections/students/index'; |
14 | 14 | ||
15 | 15 | ||
16 | const meteorTick = (props, onData) => { | 16 | const meteorTick = (props, onData) => { |
17 | 17 | ||
18 | const handles = [ | 18 | const handles = [ |
19 | Meteor.subscribe('users.current'), | 19 | Meteor.subscribe('users.current'), |
20 | Meteor.subscribe('orgs.current'), | 20 | Meteor.subscribe('orgs.current'), |
21 | Meteor.subscribe('users.forMyOrg'), | 21 | Meteor.subscribe('users.forMyOrg'), |
22 | Meteor.subscribe('student.forMyOrg'), | 22 | Meteor.subscribe('student.forMyOrg'), |
23 | ]; | 23 | ]; |
24 | 24 | ||
25 | if(_.every(handles, (handle) => (handle.ready()) )) { | 25 | if(_.every(handles, (handle) => (handle.ready()) )) { |
26 | const user = Users.current(); | 26 | const user = Users.current(); |
27 | const org = Orgs.current(); | 27 | const org = Orgs.current(); |
28 | students = Users.find({"role":"STUDENT"}).fetch(); | 28 | students = Users.find({"role":"STUDENT"}).fetch() ? Users.find({"role":"STUDENT"}).fetch() : ""; |
29 | studentData = Students.find().fetch(); | 29 | studentData = Students.find().fetch() ? Students.find().fetch() : ""; |
30 | for(var i=0; i< students.length; i++){ | 30 | for(var i=0; i< students.length; i++){ |
31 | for(var j=0; j< studentData.length; j++){ | 31 | for(var j=0; j< studentData.length; j++){ |
32 | if(students[i]._id == studentData[j].userId){ | 32 | if(students[i]._id == studentData[j].userId){ |
33 | students[i].class = studentData[j].class; | 33 | students[i].class = studentData[j].class; |
34 | students[i].dob = studentData[j].dob; | 34 | students[i].dob = studentData[j].dob; |
35 | } | 35 | } |
36 | } | 36 | } |
37 | } | 37 | } |
38 | onData(null, { | 38 | onData(null, { |
39 | data: { | 39 | data: { |
40 | user: user, | 40 | user: user, |
41 | org: org, | 41 | org: org, |
42 | students: students, | 42 | students: students, |
43 | studentData: studentData | 43 | studentData: studentData |
44 | }, | 44 | }, |
45 | }); | 45 | }); |
46 | } | 46 | } |
47 | 47 | ||
48 | return () => { | 48 | return () => { |
49 | _.each(handles, (handle) => handle.stop() ); | 49 | _.each(handles, (handle) => handle.stop() ); |
50 | }; | 50 | }; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | 53 | ||
54 | const reduxTick = (props, onData) => { | 54 | const reduxTick = (props, onData) => { |
55 | onData(null, { | 55 | onData(null, { |
56 | data: {} | 56 | data: {} |
57 | }); | 57 | }); |
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
61 | export const StudentDataController = composeAll( | 61 | export const StudentDataController = composeAll( |
62 | composeWithTracker(meteorTick, Loading), | 62 | composeWithTracker(meteorTick, Loading), |
63 | compose(reduxTick, Loading), | 63 | compose(reduxTick, Loading), |
64 | )(StudentView); | 64 | )(StudentView); |
65 | 65 |