Currently, I am facing the challenge of chaining two http calls together. The first call retrieves a set of records, and then I need to fetch finance data for each individual record.
flightRecordService.query().$promise.then(function (flightRecords) {
$scope.flightRecords = flightRecords;
for (var i = 0; i < $scope.flightRecords.length; i++) {
$scope.flightRecords[i].financeDocument =
financeDocumentService
.isReferencedDocumentIdCompensated({
id: $scope.flightRecords[i].id
}).$promise.then(
function (data) {
return ({
'isCompensated': data.headers['compensated']
});
}
);
console.log($scope.flightRecords);
}
});
This section showcases the FlightRecord object:
$$hashKey: "object:27"
aircraft: {id: 100, registration: "LV-OEE", model: "152", status: "ACTIVE", brand: "Cessna", …}
amountOfHours: 1
canceled: false
closed: false
crew: [Object] (1)
destiny: null
endFlight: "2017-01-06T20:54:05.296"
financeDocument: d
--> $$state: {status: 1, value: {isCompensated: "false"}}
--> d prototipo
id: 100
landings: 0
nature: "LDI"
opened: true
origin: null
purpose: "VP"
startFlight: "2017-01-06T19:44:05.296"
status: "OPENED"
type: "ENT"
I have noticed that the structure of the financeDocument object is not as expected. I require it to be in the following format:
...
endFlight: "2017-01-06T20:54:05.296"
financeDocument: { isCompensated: "false" }
id: 100
...
What modifications should be made to achieve this desired structure?
Thank you in advance!