The function below needs to return a true or false. Inside the then
call at the bottom of the function, I get the value I need from result.isAny('hasOverride')
but I don't know how to return this value from the hasRoomUpcharge
function. How do I do this? I thought adding return
in front of Ember.RSVP.all
would do it, but it doesn't work. Please help!
hasRoomUpcharge: function(roomRates, defaultRoomTypeCode){
var defaultRoomRates = roomRates.findBy('roomTypeCode', defaultRoomTypeCode);
var nonDefaultRoomRates = roomRates.rejectBy('roomTypeCode', defaultRoomTypeCode);
var nonDefaultRoomMasters = this.modelFor('propertyPricing').roomTypeMasters.rejectBy('isDefault');
var promises = [];
var promise;
nonDefaultRoomMasters.forEach(function(roomMaster){
var roomTypeCode = roomMaster.get('roomTypeCode');
promise = roomMaster.get('roomRateUpcharge').then(function(roomRateUpcharge){
var currentRoomMasterOnePersonPrice = nonDefaultRoomRates.findBy('roomTypeCode', roomTypeCode).onePersonPrice;
var defaultRoomMasterOnePersonPrice = defaultRoomRates.onePersonPrice;
var roomUpcharge = roomRateUpcharge.get('onePersonRateUpcharge');
if(currentRoomMasterOnePersonPrice != defaultRoomMasterOnePersonPrice + roomUpcharge){
return { hasOverride: true };
}
else {
return { hasOverride: false };
}
});
promises.push(promise);
});
return Ember.RSVP.all(promises).then(function(result){
return result.isAny('hasOverride');
});
},
Aucun commentaire:
Enregistrer un commentaire