Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bookinghistory = database.ref('bookingHistory');
- var hospital = database.ref('hospitals');
- var client = database.ref('clients');
- var patient = database.ref('patients');
- bookinghistory.once('value', function (snapshot) {
- var promises = [];
- snapshot.forEach(function (childSnapshot) {
- var childKey = childSnapshot.key;
- var fk = snapshot.child(childKey).val();
- var myhospital = hospital.child(childSnapshot.val().hospital_fk).once('value');
- var myclient = client.child(childSnapshot.val().client_fk).once('value');
- var mypatient = patient.child(childSnapshot.val().patient_id).once('value');
- promises.push(new Promise((resolve, reject) => {
- myhospital.then(docResult => {
- resolve({
- childKey: childKey,
- bookhistory: fk,
- hospital: docResult
- });
- }).catch(reason => {
- reject(reason);
- });
- }));
- promises.push(new Promise((resolve, reject) => {
- myclient.then(docResult => {
- resolve({
- client: docResult
- });
- }).catch(reason => {
- reject(reason);
- });
- }));
- promises.push(new Promise((resolve, reject) => {
- mypatient.then(docResult => {
- resolve({
- patient: docResult
- });
- }).catch(reason => {
- reject(reason);
- });
- }));
- }));
- });
- Promise.all(promises).then(function(snapshots) {
- var dataSet = [];
- snapshots.forEach(function(hospital) {
- dataSet.push({
- childKey: hospital.childKey,
- booth: hospital.booth,
- hospital:hospital.hospital,
- client:hospital.client,
- patient:hospital.patient
- });
- });
- res.json(dataSet);
- });
- [
- {
- "childKey": "-L2snm8lhye",
- "hospital": {
- "address": "Rizal Drive cor. ",
- "city": "",
- "createdAt": "2018-01-14 23:01:32",
- "deletedAt": "",
- "latitude": "14.554928",
- "longitude": "1115",
- "name": "St. Luke's Medical Center - Global City",
- "province": "",
- "updatedAt": ""
- }
- },
- {
- "client": {
- "createdAt": "2018-01-15",
- "firstName": "",
- "identifier": "+63933000000",
- "lastName": ""
- }
- },
- {
- "patient": {
- "birthdate": "1993-01-15",
- "client_fk": "qFUJT05B19NgQ2",
- "createdAt": "2018-01-15 15:02:13",
- "deletedAt": "",
- "firstName": "Eric Christian",
- "gender": "1",
- "lastName": "Odulio",
- "updatedAt": ""
- }
- }
- ]
- [
- {
- "childKey": "-L2snm8lhye",
- "hospital": {
- "address": "Rizal Drive cor. ",
- "city": "",
- "createdAt": "2018-01-14 23:01:32",
- "deletedAt": "",
- "latitude": "14.554928",
- "longitude": "1115",
- "name": "St. Luke's Medical Center - Global City",
- "province": "",
- "updatedAt": ""
- }
- "client": {
- "createdAt": "2018-01-15",
- "firstName": "",
- "identifier": "+63933000000",
- "lastName": ""
- }
- "patient": {
- "birthdate": "1993-01-15",
- "client_fk": "qFUJT05B19NgQ2",
- "createdAt": "2018-01-15 15:02:13",
- "deletedAt": "",
- "firstName": "Eric",
- "gender": "1",
- "lastName": "Odulio",
- "updatedAt": ""
- }
- }
- ]
Add Comment
Please, Sign In to add comment