I have a two calls,for match and matches. Match gets the data for one specific match, and matches the whole batch, with some relative ratings. I need to pass those relative ratings to a matching specific match.
Service that returns the json data from different API endpoints
function matchService($http, $q, API_URL) {
function getMatchesForVacancy(vacancyId) {
var deferred = $q.defer();
$http.get(API_URL + vacancyId + '/matches') //v2.0 lib
.then(function matchesArrived(matchData) {
deferred.resolve(matchData.data);
}, function matchesFailed(error) {
deferred.reject(error);
});
return deferred.promise;
}
function getMatchForVacancy(vacancyId, accountId) {
var deferred = $q.defer();
$http.get(API_URL + vacancyId + '/matches/' + accountId)
.then(function matchesArrived(matchData) {
//matchData.data.candidateRating = {overallScore: 0.65}; - ie. what I need to get
deferred.resolve(matchData.data);
}, function matchesFailed(error) {
deferred.reject(error);
});
return deferred.promise;
}
Matches and match are displayed in the different views, so I have separate controller files. Now in the single match controller I am trying to pass in the specific rating where id's are the same.
So what I tried to do, was in candidate controller create a function like this:
function connectRating(vacancyId, match){
var matches = matchService.getMatchesForVacancy(vacancyId);
for(var i = 0; i < matches.length; i++){
if(matches[i].accountId === match.accountId){
match.candidateRating.overralScore = matches[i].candidateRating.overralScore;
return match;
}
}
}
The json for matches is like this:
[
{
"accountId": 0,
"candidateRating": {
"overallScore": 0
}
}
]
And somehow the right data is not passed, or anything for that matter. I must be missing something, so I would appreciate any help.