Guest User

Untitled

a guest
Jan 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. var bookinghistory = database.ref('bookingHistory');
  2. var hospital = database.ref('hospitals');
  3. var client = database.ref('clients');
  4. var patient = database.ref('patients');
  5.  
  6. bookinghistory.once('value', function (snapshot) {
  7. var promises = [];
  8. snapshot.forEach(function (childSnapshot) {
  9.  
  10. var childKey = childSnapshot.key;
  11. var fk = snapshot.child(childKey).val();
  12.  
  13. var myhospital = hospital.child(childSnapshot.val().hospital_fk).once('value');
  14. var myclient = client.child(childSnapshot.val().client_fk).once('value');
  15. var mypatient = patient.child(childSnapshot.val().patient_id).once('value');
  16.  
  17. promises.push(new Promise((resolve, reject) => {
  18. myhospital.then(docResult => {
  19. resolve({
  20. childKey: childKey,
  21. bookhistory: fk,
  22. hospital: docResult
  23. });
  24. }).catch(reason => {
  25. reject(reason);
  26. });
  27. }));
  28. promises.push(new Promise((resolve, reject) => {
  29. myclient.then(docResult => {
  30. resolve({
  31. client: docResult
  32. });
  33. }).catch(reason => {
  34. reject(reason);
  35. });
  36. }));
  37. promises.push(new Promise((resolve, reject) => {
  38. mypatient.then(docResult => {
  39. resolve({
  40. patient: docResult
  41. });
  42. }).catch(reason => {
  43. reject(reason);
  44. });
  45. }));
  46. }));
  47. });
  48. Promise.all(promises).then(function(snapshots) {
  49. var dataSet = [];
  50. snapshots.forEach(function(hospital) {
  51.  
  52. dataSet.push({
  53. childKey: hospital.childKey,
  54. booth: hospital.booth,
  55. hospital:hospital.hospital,
  56. client:hospital.client,
  57. patient:hospital.patient
  58.  
  59. });
  60.  
  61. });
  62. res.json(dataSet);
  63. });
  64.  
  65. [
  66. {
  67. "childKey": "-L2snm8lhye",
  68. "hospital": {
  69. "address": "Rizal Drive cor. ",
  70. "city": "",
  71. "createdAt": "2018-01-14 23:01:32",
  72. "deletedAt": "",
  73. "latitude": "14.554928",
  74. "longitude": "1115",
  75. "name": "St. Luke's Medical Center - Global City",
  76. "province": "",
  77. "updatedAt": ""
  78. }
  79. },
  80. {
  81. "client": {
  82. "createdAt": "2018-01-15",
  83. "firstName": "",
  84. "identifier": "+63933000000",
  85. "lastName": ""
  86. }
  87. },
  88. {
  89. "patient": {
  90. "birthdate": "1993-01-15",
  91. "client_fk": "qFUJT05B19NgQ2",
  92. "createdAt": "2018-01-15 15:02:13",
  93. "deletedAt": "",
  94. "firstName": "Eric Christian",
  95. "gender": "1",
  96. "lastName": "Odulio",
  97. "updatedAt": ""
  98. }
  99. }
  100. ]
  101.  
  102. [
  103. {
  104. "childKey": "-L2snm8lhye",
  105. "hospital": {
  106. "address": "Rizal Drive cor. ",
  107. "city": "",
  108. "createdAt": "2018-01-14 23:01:32",
  109. "deletedAt": "",
  110. "latitude": "14.554928",
  111. "longitude": "1115",
  112. "name": "St. Luke's Medical Center - Global City",
  113. "province": "",
  114. "updatedAt": ""
  115. }
  116. "client": {
  117. "createdAt": "2018-01-15",
  118. "firstName": "",
  119. "identifier": "+63933000000",
  120. "lastName": ""
  121. }
  122. "patient": {
  123. "birthdate": "1993-01-15",
  124. "client_fk": "qFUJT05B19NgQ2",
  125. "createdAt": "2018-01-15 15:02:13",
  126. "deletedAt": "",
  127. "firstName": "Eric",
  128. "gender": "1",
  129. "lastName": "Odulio",
  130. "updatedAt": ""
  131. }
  132. }
  133. ]
Add Comment
Please, Sign In to add comment