Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. GetMrcFilterList(vehicle: IVehicle, searchRank: number, customizeParams: ICustomizeParams) {
  2. let availablePlans = this.PlansMrc();
  3. let filteredPlans = [];
  4. searchRank = searchRank >= 0 ? searchRank : 7;
  5.  
  6. let MONTHS_IN_YEAR = 12;
  7. let quoteMileageLow = 1001;
  8. let quoteMileageHigh = 1700;
  9.  
  10. let averageMilesDriven = customizeParams.miles;
  11. let yearsOfCoverage = customizeParams.months;
  12. let monthsTo100000 = (100000 - vehicle.mileage) / averageMilesDriven * MONTHS_IN_YEAR;
  13. let currentYearVehicleYearDifference = new Date().getFullYear() - parseInt(vehicle.year.name);
  14. let minimumTargetMiles = currentYearVehicleYearDifference < vehicle.specification.BaseWarrantyMonths() / MONTHS_IN_YEAR ? vehicle.specification.BaseWarrantyMiles() : 0;
  15.  
  16. //START distinct on plans
  17. filteredPlans = this.groupAndGetLowestPricedMrcPlans(availablePlans);
  18. //END distint on plans
  19.  
  20. filteredPlans = Enumerable(filteredPlans)
  21. .where(/** @param {MrcCoveragePlan} plan */(plan) => {
  22. return plan.endingMiles > (minimumTargetMiles + averageMilesDriven);
  23. })
  24. .toList();
  25.  
  26. //Start first conditional check
  27. let tempList = Enumerable(filteredPlans)
  28. .where((plan) => {
  29. let actualPlanMilesPerYear = ((plan.termMiles - vehicle.mileage) / plan.termMonths) * MONTHS_IN_YEAR; // 12 stands for 12 months in a year.
  30. return plan.rankId == searchRank &&
  31. plan.mileageCalculated == 1 &&
  32. (
  33. actualPlanMilesPerYear >= averageMilesDriven - quoteMileageLow &&
  34. actualPlanMilesPerYear <= averageMilesDriven + quoteMileageHigh
  35. );
  36. })
  37. .toList();
  38. //END first conditional check
  39.  
  40. //Start second conditional check
  41. if (tempList.length == 0 && vehicle.mileage <= 60000) {
  42. tempList = Enumerable(filteredPlans)
  43. .where((plan) => {
  44. let actualPlanMilesPerYear = ((plan.termMiles - vehicle.mileage) / plan.termMonths) * MONTHS_IN_YEAR;
  45. return plan.rankId == searchRank &&
  46. plan.mileageCalculated == 1 &&
  47. (
  48. actualPlanMilesPerYear >= averageMilesDriven - (quoteMileageLow + 2500) &&
  49. actualPlanMilesPerYear <= averageMilesDriven + (quoteMileageHigh + 5000)
  50. );
  51. })
  52. .toList();
  53. }
  54. //End second conditional check
  55.  
  56. if (tempList.length == 0) {
  57. tempList = Enumerable(filteredPlans)
  58. .where((plan) => {
  59. return plan.mileageCalculated == 2 && plan.rankId == searchRank && plan.termMonths > 12 && plan.termMonths < 60;
  60. })
  61. .toList();
  62. }
  63.  
  64. if (tempList.length == 0 && searchRank > 0) {
  65. tempList = this.GetMrcFilterList(vehicle, searchRank - 1, customizeParams);
  66. }
  67.  
  68. if (tempList.length == 0 && searchRank == 0) {
  69. tempList = filteredPlans;
  70. }
  71. // end last chance
  72.  
  73. this.sortMrcPlans(tempList);
  74.  
  75. return tempList;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement