@sabstravtech/obtservices 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (420) hide show
  1. package/.editorconfig +13 -0
  2. package/.gitmodules +0 -0
  3. package/.vscode/settings.json +4 -0
  4. package/README.md +27 -0
  5. package/angular.json +45 -0
  6. package/audit.config.json +6 -0
  7. package/codegen.yml +18 -0
  8. package/ng-package.json +7 -0
  9. package/package.json +84 -0
  10. package/projects/obtservices/README.md +24 -0
  11. package/projects/obtservices/angular/package.json +3 -0
  12. package/projects/obtservices/angular/src/classes.ts +3 -0
  13. package/projects/obtservices/angular/src/components/basket-panel.ts +139 -0
  14. package/projects/obtservices/angular/src/components/with-component.ts +40 -0
  15. package/projects/obtservices/angular/src/components.ts +2 -0
  16. package/projects/obtservices/angular/src/data.ts +5 -0
  17. package/projects/obtservices/angular/src/fetchers.ts +32 -0
  18. package/projects/obtservices/angular/src/lib/vendor/classes/environment.ts +5 -0
  19. package/projects/obtservices/angular/src/lib/vendor/classes/event-messenager.ts +11 -0
  20. package/projects/obtservices/angular/src/lib/vendor/classes/helpers.ts +87 -0
  21. package/projects/obtservices/angular/src/lib/vendor/data/airports.data.json +5508 -0
  22. package/projects/obtservices/angular/src/lib/vendor/data/animations.ts +38 -0
  23. package/projects/obtservices/angular/src/lib/vendor/data/booking-expected-responses.json +100 -0
  24. package/projects/obtservices/angular/src/lib/vendor/data/cities.data.json +31499 -0
  25. package/projects/obtservices/angular/src/lib/vendor/data/countries.json +1212 -0
  26. package/projects/obtservices/angular/src/lib/vendor/data/flight-booking.data.json +136 -0
  27. package/projects/obtservices/angular/src/lib/vendor/data/postcodes1.json +194 -0
  28. package/projects/obtservices/angular/src/lib/vendor/data/rail_addresses.json +2524 -0
  29. package/projects/obtservices/angular/src/lib/vendor/fetchers/basket-fetcher.ts +14 -0
  30. package/projects/obtservices/angular/src/lib/vendor/fetchers/cabhire-quote-fetcher.ts +15 -0
  31. package/projects/obtservices/angular/src/lib/vendor/fetchers/carhire-availability-detail.fetcher.ts +17 -0
  32. package/projects/obtservices/angular/src/lib/vendor/fetchers/carhire-quote-fetcher.ts +16 -0
  33. package/projects/obtservices/angular/src/lib/vendor/fetchers/conferma-office-names.fetcher.ts +16 -0
  34. package/projects/obtservices/angular/src/lib/vendor/fetchers/conferma-quicklist.fetcher.ts +16 -0
  35. package/projects/obtservices/angular/src/lib/vendor/fetchers/eurostar-quote.fetcher.ts +16 -0
  36. package/projects/obtservices/angular/src/lib/vendor/fetchers/flight-quote.fetcher.ts +16 -0
  37. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-rail-cards.fetcher.ts +16 -0
  38. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-rail-station.fetcher.ts +16 -0
  39. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-risk-alerts.fetcher.ts +18 -0
  40. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-user-company-offices.fetcher.ts +16 -0
  41. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-user-current-carbon-allowance.fetcher.ts +16 -0
  42. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-user-recent-searches.fetcher.ts +16 -0
  43. package/projects/obtservices/angular/src/lib/vendor/fetchers/get-users-baskets-fetcher.ts +16 -0
  44. package/projects/obtservices/angular/src/lib/vendor/fetchers/getMiAutoSugestions.fetcher.ts +16 -0
  45. package/projects/obtservices/angular/src/lib/vendor/fetchers/hotel-avaliability-fetcher.ts +17 -0
  46. package/projects/obtservices/angular/src/lib/vendor/fetchers/hotel-quote-fetcher.ts +16 -0
  47. package/projects/obtservices/angular/src/lib/vendor/fetchers/irl-quote-fetcher.ts +16 -0
  48. package/projects/obtservices/angular/src/lib/vendor/fetchers/lounge-quote.fetcher.ts +16 -0
  49. package/projects/obtservices/angular/src/lib/vendor/fetchers/parking-quote-fetcher.ts +16 -0
  50. package/projects/obtservices/angular/src/lib/vendor/fetchers/rail-quote-fetcher.ts +16 -0
  51. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-airlines-fetcher.ts +14 -0
  52. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-airports-fetcher.ts +14 -0
  53. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-cities.fetcher.ts +16 -0
  54. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-conferma-cities.fetcher.ts +14 -0
  55. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-depots.fetcher.ts +18 -0
  56. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-hotel-chains.fetcher.ts +16 -0
  57. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-postcodes.fetcher.ts +16 -0
  58. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-rail-stations.fetcher.ts +16 -0
  59. package/projects/obtservices/angular/src/lib/vendor/fetchers/search-users-can-book-for-fetcher.ts +16 -0
  60. package/projects/obtservices/angular/src/lib/vendor/fetchers/user-addresses.fetcher.ts +16 -0
  61. package/projects/obtservices/angular/src/lib/vendor/fetchers/user-fetcher.ts +14 -0
  62. package/projects/obtservices/angular/src/lib/vendor/fetchers/user-message.fetcher.ts +16 -0
  63. package/projects/obtservices/angular/src/lib/vendor/fetchers/user-products-fetcher.ts +16 -0
  64. package/projects/obtservices/angular/src/lib/vendor/fetchers/user-ui-configs-fetcher.ts +16 -0
  65. package/projects/obtservices/angular/src/lib/vendor/services/enterprise-basket.service.ts +133 -0
  66. package/projects/obtservices/angular/src/lib/vendor/services/hotel-avallibility.service.ts +19 -0
  67. package/projects/obtservices/angular/src/lib/vendor/services/http-call.service.ts +252 -0
  68. package/projects/obtservices/angular/src/lib/vendor/services/logon.service.ts +40 -0
  69. package/projects/obtservices/angular/src/lib/vendor/services/modal-opener.service.ts +9 -0
  70. package/projects/obtservices/angular/src/lib/vendor/services/my-bookings.service.ts +21 -0
  71. package/projects/obtservices/angular/src/lib/vendor/services/route-happy.service.ts +11 -0
  72. package/projects/obtservices/angular/src/lib/vendor/services/search.service.ts +213 -0
  73. package/projects/obtservices/angular/src/lib/vendor/services/storage.service.ts +82 -0
  74. package/projects/obtservices/angular/src/lib/vendor/services/user.service.ts +36 -0
  75. package/projects/obtservices/angular/src/lib/vendor/services/webtoken.service.ts +62 -0
  76. package/projects/obtservices/angular/src/lib/vendor/testers/postcode-validate.tester.ts +14 -0
  77. package/projects/obtservices/angular/src/lib/vendor/testers/validate-mi-free-value.tester.ts +14 -0
  78. package/projects/obtservices/angular/src/lib/vendor/types/graphql.angular.types.ts +11081 -0
  79. package/projects/obtservices/angular/src/lib/vendor/updaters/accept-new-price.updater.ts +14 -0
  80. package/projects/obtservices/angular/src/lib/vendor/updaters/add-item-to-basket.updater.ts +14 -0
  81. package/projects/obtservices/angular/src/lib/vendor/updaters/addUserToBasketItem.ts +14 -0
  82. package/projects/obtservices/angular/src/lib/vendor/updaters/book-basket-updater.ts +14 -0
  83. package/projects/obtservices/angular/src/lib/vendor/updaters/create-basket-updater.ts +14 -0
  84. package/projects/obtservices/angular/src/lib/vendor/updaters/move-basket-item-to-basket.ts +14 -0
  85. package/projects/obtservices/angular/src/lib/vendor/updaters/remove-basket-updater.ts +14 -0
  86. package/projects/obtservices/angular/src/lib/vendor/updaters/remove-item-from-basket.updater.ts +14 -0
  87. package/projects/obtservices/angular/src/lib/vendor/updaters/remove-recent-search.updater.ts +14 -0
  88. package/projects/obtservices/angular/src/lib/vendor/updaters/remove-user-address.updater.ts +14 -0
  89. package/projects/obtservices/angular/src/lib/vendor/updaters/revalidate-basket-updater.ts +14 -0
  90. package/projects/obtservices/angular/src/lib/vendor/updaters/save-recent-search.updater.ts +14 -0
  91. package/projects/obtservices/angular/src/lib/vendor/updaters/save-user-address.updater.ts +11 -0
  92. package/projects/obtservices/angular/src/lib/vendor/updaters/send-basket-for-approval.updater.ts +14 -0
  93. package/projects/obtservices/angular/src/lib/vendor/updaters/set-basket-item-lead-passenger.updater.ts +14 -0
  94. package/projects/obtservices/angular/src/lib/vendor/updaters/set-basket-item-mi-group.ts +14 -0
  95. package/projects/obtservices/angular/src/lib/vendor/updaters/set-basket-item-mi-value-updater.ts +15 -0
  96. package/projects/obtservices/angular/src/lib/vendor/updaters/set-payment-option.updater.ts +15 -0
  97. package/projects/obtservices/angular/src/lib/vendor/updaters/update-basket-notes-updater.ts +14 -0
  98. package/projects/obtservices/angular/src/lib/vendor/updaters/update-basket-title-updater.ts +14 -0
  99. package/projects/obtservices/angular/src/obtservices.module.ts +131 -0
  100. package/projects/obtservices/angular/src/public_api.ts +8 -0
  101. package/projects/obtservices/angular/src/services.ts +11 -0
  102. package/projects/obtservices/angular/src/testers.ts +2 -0
  103. package/projects/obtservices/angular/src/types.ts +1 -0
  104. package/projects/obtservices/angular/src/updaters.ts +13 -0
  105. package/projects/obtservices/base/package.json +3 -0
  106. package/projects/obtservices/base/src/classes.ts +27 -0
  107. package/projects/obtservices/base/src/custom.d.ts +3 -0
  108. package/projects/obtservices/base/src/fetchers.ts +36 -0
  109. package/projects/obtservices/base/src/interfaces.ts +29 -0
  110. package/projects/obtservices/base/src/lib/vendor/classes/base-enterprise.ts +126 -0
  111. package/projects/obtservices/base/src/lib/vendor/classes/base-network-call.ts +40 -0
  112. package/projects/obtservices/base/src/lib/vendor/classes/basket-info-mi-details.impl.ts +68 -0
  113. package/projects/obtservices/base/src/lib/vendor/classes/bookable-basket.ts +343 -0
  114. package/projects/obtservices/base/src/lib/vendor/classes/cabhire-enterprise-search.ts +907 -0
  115. package/projects/obtservices/base/src/lib/vendor/classes/carhire-enterprise-search.ts +1597 -0
  116. package/projects/obtservices/base/src/lib/vendor/classes/empty-enterprise-search.ts +75 -0
  117. package/projects/obtservices/base/src/lib/vendor/classes/enviroment.ts +25 -0
  118. package/projects/obtservices/base/src/lib/vendor/classes/eurostar-enterprise-search.ts +2126 -0
  119. package/projects/obtservices/base/src/lib/vendor/classes/eurostar-search-type.enum.ts +4 -0
  120. package/projects/obtservices/base/src/lib/vendor/classes/event-messenager.ts +23 -0
  121. package/projects/obtservices/base/src/lib/vendor/classes/flight-enterprise-search.ts +2399 -0
  122. package/projects/obtservices/base/src/lib/vendor/classes/flight-search-type.enum.ts +5 -0
  123. package/projects/obtservices/base/src/lib/vendor/classes/helpers.ts +1233 -0
  124. package/projects/obtservices/base/src/lib/vendor/classes/hotel-enterprise-search.ts +1370 -0
  125. package/projects/obtservices/base/src/lib/vendor/classes/irl-enterprise-search.ts +1380 -0
  126. package/projects/obtservices/base/src/lib/vendor/classes/limited-cache.class.ts +70 -0
  127. package/projects/obtservices/base/src/lib/vendor/classes/lounges-enterprise-search.ts +444 -0
  128. package/projects/obtservices/base/src/lib/vendor/classes/management-info-and-valid.ts +268 -0
  129. package/projects/obtservices/base/src/lib/vendor/classes/modal-types.enum.ts +28 -0
  130. package/projects/obtservices/base/src/lib/vendor/classes/parking-enterprise-search.ts +541 -0
  131. package/projects/obtservices/base/src/lib/vendor/classes/rail-direction.enum.ts +4 -0
  132. package/projects/obtservices/base/src/lib/vendor/classes/rail-enterprise-search.ts +1751 -0
  133. package/projects/obtservices/base/src/lib/vendor/classes/routehappy-request.ts +146 -0
  134. package/projects/obtservices/base/src/lib/vendor/classes/routehappy-response.ts +128 -0
  135. package/projects/obtservices/base/src/lib/vendor/classes/supplementary-booking-info-impl.ts +375 -0
  136. package/projects/obtservices/base/src/lib/vendor/classes/user-favourite.enum.ts +12 -0
  137. package/projects/obtservices/base/src/lib/vendor/classes/validator.checker.ts +7 -0
  138. package/projects/obtservices/base/src/lib/vendor/data/airports.data.json +5508 -0
  139. package/projects/obtservices/base/src/lib/vendor/data/booking-expected-responses.json +100 -0
  140. package/projects/obtservices/base/src/lib/vendor/data/cities.data.json +31499 -0
  141. package/projects/obtservices/base/src/lib/vendor/data/countries.json +1212 -0
  142. package/projects/obtservices/base/src/lib/vendor/data/euro-stations.json +30 -0
  143. package/projects/obtservices/base/src/lib/vendor/data/flight-booking.data.json +136 -0
  144. package/projects/obtservices/base/src/lib/vendor/data/postcodes1.json +194 -0
  145. package/projects/obtservices/base/src/lib/vendor/data/rail_addresses.json +2524 -0
  146. package/projects/obtservices/base/src/lib/vendor/fetchers/basket-fetcher.ts +29 -0
  147. package/projects/obtservices/base/src/lib/vendor/fetchers/cabhire-quote-fetcher.ts +34 -0
  148. package/projects/obtservices/base/src/lib/vendor/fetchers/carhire-availability-detail.fetcher.ts +35 -0
  149. package/projects/obtservices/base/src/lib/vendor/fetchers/carhire-quote-fetcher.ts +34 -0
  150. package/projects/obtservices/base/src/lib/vendor/fetchers/conferma-office-names.fetcher.ts +34 -0
  151. package/projects/obtservices/base/src/lib/vendor/fetchers/conferma-quicklist.fetcher.ts +35 -0
  152. package/projects/obtservices/base/src/lib/vendor/fetchers/eurostar-quote.fetcher.ts +35 -0
  153. package/projects/obtservices/base/src/lib/vendor/fetchers/flight-quote.fetcher.ts +35 -0
  154. package/projects/obtservices/base/src/lib/vendor/fetchers/get-rail-cards.fetcher.ts +35 -0
  155. package/projects/obtservices/base/src/lib/vendor/fetchers/get-rail-station.fetcher.ts +35 -0
  156. package/projects/obtservices/base/src/lib/vendor/fetchers/get-risk-alerts.fetcher.ts +35 -0
  157. package/projects/obtservices/base/src/lib/vendor/fetchers/get-user-company-offices.fetcher.ts +34 -0
  158. package/projects/obtservices/base/src/lib/vendor/fetchers/get-user-current-carbon-allowance.fetcher.ts +35 -0
  159. package/projects/obtservices/base/src/lib/vendor/fetchers/get-user-recent-searches.fetcher.ts +36 -0
  160. package/projects/obtservices/base/src/lib/vendor/fetchers/get-users-baskets-fetcher.ts +33 -0
  161. package/projects/obtservices/base/src/lib/vendor/fetchers/getMiAutoSugestions.fetcher.ts +35 -0
  162. package/projects/obtservices/base/src/lib/vendor/fetchers/hotel-avaliability-fetcher.ts +53 -0
  163. package/projects/obtservices/base/src/lib/vendor/fetchers/hotel-quote-fetcher.ts +35 -0
  164. package/projects/obtservices/base/src/lib/vendor/fetchers/irl-quote-fetcher.ts +34 -0
  165. package/projects/obtservices/base/src/lib/vendor/fetchers/list-fetchable-enterprise.ts +59 -0
  166. package/projects/obtservices/base/src/lib/vendor/fetchers/lounge-quote.fetcher.ts +34 -0
  167. package/projects/obtservices/base/src/lib/vendor/fetchers/object-fetchable-enterprise.ts +20 -0
  168. package/projects/obtservices/base/src/lib/vendor/fetchers/parking-quote-fetcher.ts +34 -0
  169. package/projects/obtservices/base/src/lib/vendor/fetchers/rail-quote-fetcher.ts +34 -0
  170. package/projects/obtservices/base/src/lib/vendor/fetchers/search-airlines.fetcher.ts +30 -0
  171. package/projects/obtservices/base/src/lib/vendor/fetchers/search-airports-fetcher.ts +29 -0
  172. package/projects/obtservices/base/src/lib/vendor/fetchers/search-cities.fetcher.ts +34 -0
  173. package/projects/obtservices/base/src/lib/vendor/fetchers/search-conferma-cities.fetcher.ts +32 -0
  174. package/projects/obtservices/base/src/lib/vendor/fetchers/search-depots.fetcher.ts +34 -0
  175. package/projects/obtservices/base/src/lib/vendor/fetchers/search-hotel-chains.fetcher.ts +34 -0
  176. package/projects/obtservices/base/src/lib/vendor/fetchers/search-postcodes.fetcher.ts +37 -0
  177. package/projects/obtservices/base/src/lib/vendor/fetchers/search-rail-stations.fetcher.ts +35 -0
  178. package/projects/obtservices/base/src/lib/vendor/fetchers/search-users-can-book-for-fetcher.ts +35 -0
  179. package/projects/obtservices/base/src/lib/vendor/fetchers/user-addresses.fetcher.ts +34 -0
  180. package/projects/obtservices/base/src/lib/vendor/fetchers/user-fetcher.ts +27 -0
  181. package/projects/obtservices/base/src/lib/vendor/fetchers/user-message.fetcher.ts +34 -0
  182. package/projects/obtservices/base/src/lib/vendor/fetchers/user-products-fetcher.ts +35 -0
  183. package/projects/obtservices/base/src/lib/vendor/fetchers/user-ui-configs-fetcher.ts +35 -0
  184. package/projects/obtservices/base/src/lib/vendor/interfaces/Icabhire-enterprise-search.ts +174 -0
  185. package/projects/obtservices/base/src/lib/vendor/interfaces/Icarhire-enterprise-search.ts +143 -0
  186. package/projects/obtservices/base/src/lib/vendor/interfaces/Ienterprise-basket.service.ts +127 -0
  187. package/projects/obtservices/base/src/lib/vendor/interfaces/Ieurostar-enterprise-search.ts +197 -0
  188. package/projects/obtservices/base/src/lib/vendor/interfaces/Iflight-enterprise-search.ts +196 -0
  189. package/projects/obtservices/base/src/lib/vendor/interfaces/Ihotel-enterprise-search.ts +219 -0
  190. package/projects/obtservices/base/src/lib/vendor/interfaces/Iirl-enterprise-search.ts +135 -0
  191. package/projects/obtservices/base/src/lib/vendor/interfaces/Ilounges-enterprise-search.ts +58 -0
  192. package/projects/obtservices/base/src/lib/vendor/interfaces/Imybookings.service.ts +27 -0
  193. package/projects/obtservices/base/src/lib/vendor/interfaces/Iparking-enterprise-search.ts +72 -0
  194. package/projects/obtservices/base/src/lib/vendor/interfaces/Irail-enterprise-search.ts +161 -0
  195. package/projects/obtservices/base/src/lib/vendor/interfaces/Isearch.service.ts +178 -0
  196. package/projects/obtservices/base/src/lib/vendor/interfaces/Isupplementary-booking-info-impl.ts +63 -0
  197. package/projects/obtservices/base/src/lib/vendor/interfaces/Iuser.service.ts +87 -0
  198. package/projects/obtservices/base/src/lib/vendor/interfaces/car-hire-classes.interface.ts +8 -0
  199. package/projects/obtservices/base/src/lib/vendor/interfaces/car-hire-filters.interface.ts +11 -0
  200. package/projects/obtservices/base/src/lib/vendor/interfaces/car-hire-sort.interface.ts +4 -0
  201. package/projects/obtservices/base/src/lib/vendor/interfaces/cheapest-price.ts +4 -0
  202. package/projects/obtservices/base/src/lib/vendor/interfaces/code-name.ts +4 -0
  203. package/projects/obtservices/base/src/lib/vendor/interfaces/flight-filters.interface.ts +41 -0
  204. package/projects/obtservices/base/src/lib/vendor/interfaces/flight-multi-destination.interface.ts +8 -0
  205. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-airport-express-stations.interface.ts +4 -0
  206. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-basket-item.interface.ts +79 -0
  207. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-journey-leg.interface.ts +6 -0
  208. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-recent-search-args.interface.ts +20 -0
  209. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-selected-ticket.interface.ts +11 -0
  210. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-ticket-group.interface.ts +29 -0
  211. package/projects/obtservices/base/src/lib/vendor/interfaces/rail-ticket-groups.interface.ts +5 -0
  212. package/projects/obtservices/base/src/lib/vendor/interfaces/search-objects.interface.ts +17 -0
  213. package/projects/obtservices/base/src/lib/vendor/interfaces/select-filter.interface.ts +5 -0
  214. package/projects/obtservices/base/src/lib/vendor/interfaces/user.data.ts +22 -0
  215. package/projects/obtservices/base/src/lib/vendor/interfaces/value-display.ts +4 -0
  216. package/projects/obtservices/base/src/lib/vendor/models/login.model.ts +97 -0
  217. package/projects/obtservices/base/src/lib/vendor/models/regexp.model.ts +13 -0
  218. package/projects/obtservices/base/src/lib/vendor/models/traveller.object.ts +61 -0
  219. package/projects/obtservices/base/src/lib/vendor/services/enterprise-basket.service.ts +1150 -0
  220. package/projects/obtservices/base/src/lib/vendor/services/hotel-avallibility.service.ts +251 -0
  221. package/projects/obtservices/base/src/lib/vendor/services/http-call.service.ts +57 -0
  222. package/projects/obtservices/base/src/lib/vendor/services/logon.service.ts +245 -0
  223. package/projects/obtservices/base/src/lib/vendor/services/modal-opener.service.ts +30 -0
  224. package/projects/obtservices/base/src/lib/vendor/services/my-bookings.service.ts +184 -0
  225. package/projects/obtservices/base/src/lib/vendor/services/routehappy.service.ts +275 -0
  226. package/projects/obtservices/base/src/lib/vendor/services/search.service.ts +2026 -0
  227. package/projects/obtservices/base/src/lib/vendor/services/storage.service.ts +15 -0
  228. package/projects/obtservices/base/src/lib/vendor/services/url.service.ts +12 -0
  229. package/projects/obtservices/base/src/lib/vendor/services/user.service.ts +354 -0
  230. package/projects/obtservices/base/src/lib/vendor/services/webtoken.service.ts +66 -0
  231. package/projects/obtservices/base/src/lib/vendor/testers/base.tester.ts +18 -0
  232. package/projects/obtservices/base/src/lib/vendor/testers/postcode-validate.tester.ts +24 -0
  233. package/projects/obtservices/base/src/lib/vendor/testers/validate-mi-free-value.tester.ts +23 -0
  234. package/projects/obtservices/base/src/lib/vendor/types/graphql.types.ts +6184 -0
  235. package/projects/obtservices/base/src/lib/vendor/types/types.ts +630 -0
  236. package/projects/obtservices/base/src/lib/vendor/updaters/accept-new-price.updater.ts +31 -0
  237. package/projects/obtservices/base/src/lib/vendor/updaters/add-item-to-basket.updater.ts +29 -0
  238. package/projects/obtservices/base/src/lib/vendor/updaters/addUserToBasketItem.ts +30 -0
  239. package/projects/obtservices/base/src/lib/vendor/updaters/book-basket-updater.ts +28 -0
  240. package/projects/obtservices/base/src/lib/vendor/updaters/create-basket-updater.ts +29 -0
  241. package/projects/obtservices/base/src/lib/vendor/updaters/move-basket-item-to-basket.ts +30 -0
  242. package/projects/obtservices/base/src/lib/vendor/updaters/object-updater-enterprise.ts +20 -0
  243. package/projects/obtservices/base/src/lib/vendor/updaters/remove-basket-updater.ts +29 -0
  244. package/projects/obtservices/base/src/lib/vendor/updaters/remove-item-from-basket.updater.ts +28 -0
  245. package/projects/obtservices/base/src/lib/vendor/updaters/remove-recent-search-updater.ts +29 -0
  246. package/projects/obtservices/base/src/lib/vendor/updaters/remove-user-address-updater.ts +29 -0
  247. package/projects/obtservices/base/src/lib/vendor/updaters/revalidate-basket-updater.ts +29 -0
  248. package/projects/obtservices/base/src/lib/vendor/updaters/save-recent-search-updater.ts +30 -0
  249. package/projects/obtservices/base/src/lib/vendor/updaters/save-user-address.updater.ts +30 -0
  250. package/projects/obtservices/base/src/lib/vendor/updaters/send-basket-for-approval.updater.ts +31 -0
  251. package/projects/obtservices/base/src/lib/vendor/updaters/set-basket-item-lead-passenger.updater.ts +30 -0
  252. package/projects/obtservices/base/src/lib/vendor/updaters/set-basket-item-mi-group.ts +32 -0
  253. package/projects/obtservices/base/src/lib/vendor/updaters/set-basket-item-mi-value-updater.ts +30 -0
  254. package/projects/obtservices/base/src/lib/vendor/updaters/set-basket-item-paymenr-option.updater.ts +28 -0
  255. package/projects/obtservices/base/src/lib/vendor/updaters/update-basket-notes-updater.ts +30 -0
  256. package/projects/obtservices/base/src/lib/vendor/updaters/update-basket-title-updater.ts +30 -0
  257. package/projects/obtservices/base/src/models.ts +3 -0
  258. package/projects/obtservices/base/src/public_api.ts +8 -0
  259. package/projects/obtservices/base/src/services.ts +12 -0
  260. package/projects/obtservices/base/src/testers.ts +2 -0
  261. package/projects/obtservices/base/src/types.ts +1 -0
  262. package/projects/obtservices/base/src/updaters.ts +20 -0
  263. package/projects/obtservices/graphQL/autogenerated/index.js +2 -0
  264. package/projects/obtservices/graphQL/autogenerated/mutations/acceptNewPrice.gql +1580 -0
  265. package/projects/obtservices/graphQL/autogenerated/mutations/addItemToBasket.gql +1580 -0
  266. package/projects/obtservices/graphQL/autogenerated/mutations/addUsersToBasketItem.gql +1580 -0
  267. package/projects/obtservices/graphQL/autogenerated/mutations/bookBasket.gql +1580 -0
  268. package/projects/obtservices/graphQL/autogenerated/mutations/cancelBooking.gql +6 -0
  269. package/projects/obtservices/graphQL/autogenerated/mutations/confermaCreateCard.gql +23 -0
  270. package/projects/obtservices/graphQL/autogenerated/mutations/confermaDeleteCard.gql +3 -0
  271. package/projects/obtservices/graphQL/autogenerated/mutations/createBasket.gql +1580 -0
  272. package/projects/obtservices/graphQL/autogenerated/mutations/deleteBasket.gql +3 -0
  273. package/projects/obtservices/graphQL/autogenerated/mutations/deleteFavouriteSearch.gql +3 -0
  274. package/projects/obtservices/graphQL/autogenerated/mutations/deleteRecentSearch.gql +3 -0
  275. package/projects/obtservices/graphQL/autogenerated/mutations/deleteUserAddress.gql +3 -0
  276. package/projects/obtservices/graphQL/autogenerated/mutations/index.js +36 -0
  277. package/projects/obtservices/graphQL/autogenerated/mutations/moveItemToADifferentBasket.gql +1580 -0
  278. package/projects/obtservices/graphQL/autogenerated/mutations/removeItemFromBasket.gql +1580 -0
  279. package/projects/obtservices/graphQL/autogenerated/mutations/removeItemsFromBasket.gql +1580 -0
  280. package/projects/obtservices/graphQL/autogenerated/mutations/removeUserFromBasketItem.gql +1580 -0
  281. package/projects/obtservices/graphQL/autogenerated/mutations/reopenBasket.gql +1580 -0
  282. package/projects/obtservices/graphQL/autogenerated/mutations/revalidateBasket.gql +1580 -0
  283. package/projects/obtservices/graphQL/autogenerated/mutations/revalidateBasketItem.gql +1580 -0
  284. package/projects/obtservices/graphQL/autogenerated/mutations/saveFavouriteSearch.gql +348 -0
  285. package/projects/obtservices/graphQL/autogenerated/mutations/saveRecentSearch.gql +348 -0
  286. package/projects/obtservices/graphQL/autogenerated/mutations/saveUserAddress.gql +14 -0
  287. package/projects/obtservices/graphQL/autogenerated/mutations/sendBasketForApproval.gql +1580 -0
  288. package/projects/obtservices/graphQL/autogenerated/mutations/setAddressAsUserPrimary.gql +14 -0
  289. package/projects/obtservices/graphQL/autogenerated/mutations/setBasketItemLeadPassenger.gql +1580 -0
  290. package/projects/obtservices/graphQL/autogenerated/mutations/setBasketItemMIGroup.gql +1580 -0
  291. package/projects/obtservices/graphQL/autogenerated/mutations/setBasketItemMIValue.gql +1580 -0
  292. package/projects/obtservices/graphQL/autogenerated/mutations/setBasketItemPaymentMethod.gql +1580 -0
  293. package/projects/obtservices/graphQL/autogenerated/mutations/setMIDefaultValue.gql +3 -0
  294. package/projects/obtservices/graphQL/autogenerated/mutations/setUserLanguage.gql +339 -0
  295. package/projects/obtservices/graphQL/autogenerated/mutations/updateBasketNotes.gql +1580 -0
  296. package/projects/obtservices/graphQL/autogenerated/mutations/updateBasketTitle.gql +1580 -0
  297. package/projects/obtservices/graphQL/autogenerated/queries/alive.gql +3 -0
  298. package/projects/obtservices/graphQL/autogenerated/queries/carHireAvailabilityDetailRequest.gql +42 -0
  299. package/projects/obtservices/graphQL/autogenerated/queries/confermaBlockClientHotels.gql +23 -0
  300. package/projects/obtservices/graphQL/autogenerated/queries/confermaBlockConsumerHotels.gql +23 -0
  301. package/projects/obtservices/graphQL/autogenerated/queries/confermaListCards.gql +11 -0
  302. package/projects/obtservices/graphQL/autogenerated/queries/confermaUnblockClientHotels.gql +23 -0
  303. package/projects/obtservices/graphQL/autogenerated/queries/confermaUnblockConsumerHotels.gql +23 -0
  304. package/projects/obtservices/graphQL/autogenerated/queries/getCOVIDMicrositeToken.gql +3 -0
  305. package/projects/obtservices/graphQL/autogenerated/queries/getCancellationInfo.gql +7 -0
  306. package/projects/obtservices/graphQL/autogenerated/queries/getCarHireDepots.gql +13 -0
  307. package/projects/obtservices/graphQL/autogenerated/queries/getConfermaOffice.gql +50 -0
  308. package/projects/obtservices/graphQL/autogenerated/queries/getConfermaOfficeNames.gql +26 -0
  309. package/projects/obtservices/graphQL/autogenerated/queries/getConfermaQuicklist.gql +131 -0
  310. package/projects/obtservices/graphQL/autogenerated/queries/getCountries.gql +8 -0
  311. package/projects/obtservices/graphQL/autogenerated/queries/getHotelAvailability.gql +78 -0
  312. package/projects/obtservices/graphQL/autogenerated/queries/getHotelChains.gql +3 -0
  313. package/projects/obtservices/graphQL/autogenerated/queries/getIRLSupplierStation.gql +28 -0
  314. package/projects/obtservices/graphQL/autogenerated/queries/getMultipleHotelsAvailability.gql +78 -0
  315. package/projects/obtservices/graphQL/autogenerated/queries/getPostcodeDetails.gql +25 -0
  316. package/projects/obtservices/graphQL/autogenerated/queries/getRailStation.gql +27 -0
  317. package/projects/obtservices/graphQL/autogenerated/queries/getRailcards.gql +6 -0
  318. package/projects/obtservices/graphQL/autogenerated/queries/getRiskAlerts.gql +17 -0
  319. package/projects/obtservices/graphQL/autogenerated/queries/getUser.gql +339 -0
  320. package/projects/obtservices/graphQL/autogenerated/queries/getUserAddresses.gql +14 -0
  321. package/projects/obtservices/graphQL/autogenerated/queries/getUserBasket.gql +1580 -0
  322. package/projects/obtservices/graphQL/autogenerated/queries/getUserBaskets.gql +1580 -0
  323. package/projects/obtservices/graphQL/autogenerated/queries/getUserCompanyOffices.gql +88 -0
  324. package/projects/obtservices/graphQL/autogenerated/queries/getUserCurrentCarbonAllowance.gql +524 -0
  325. package/projects/obtservices/graphQL/autogenerated/queries/getUserFavouriteSearches.gql +348 -0
  326. package/projects/obtservices/graphQL/autogenerated/queries/getUserMIAutoSuggestValues.gql +10 -0
  327. package/projects/obtservices/graphQL/autogenerated/queries/getUserMessages.gql +10 -0
  328. package/projects/obtservices/graphQL/autogenerated/queries/getUserPhoneNumbers.gql +13 -0
  329. package/projects/obtservices/graphQL/autogenerated/queries/getUserRecentSearches.gql +348 -0
  330. package/projects/obtservices/graphQL/autogenerated/queries/getUserServices.gql +16 -0
  331. package/projects/obtservices/graphQL/autogenerated/queries/getUserTravelRules.gql +111 -0
  332. package/projects/obtservices/graphQL/autogenerated/queries/getUserUIConfigs.gql +52 -0
  333. package/projects/obtservices/graphQL/autogenerated/queries/index.js +64 -0
  334. package/projects/obtservices/graphQL/autogenerated/queries/isPostcodeValid.gql +3 -0
  335. package/projects/obtservices/graphQL/autogenerated/queries/postcodeAutoSuggest.gql +3 -0
  336. package/projects/obtservices/graphQL/autogenerated/queries/searchAirlines.gql +32 -0
  337. package/projects/obtservices/graphQL/autogenerated/queries/searchAirports.gql +60 -0
  338. package/projects/obtservices/graphQL/autogenerated/queries/searchCabHire.gql +63 -0
  339. package/projects/obtservices/graphQL/autogenerated/queries/searchCarHire.gql +104 -0
  340. package/projects/obtservices/graphQL/autogenerated/queries/searchCities.gql +14 -0
  341. package/projects/obtservices/graphQL/autogenerated/queries/searchConfermaCities.gql +11 -0
  342. package/projects/obtservices/graphQL/autogenerated/queries/searchEurostar.gql +833 -0
  343. package/projects/obtservices/graphQL/autogenerated/queries/searchFastTrack.gql +46 -0
  344. package/projects/obtservices/graphQL/autogenerated/queries/searchFlights.gql +23 -0
  345. package/projects/obtservices/graphQL/autogenerated/queries/searchFlightsV2.gql +833 -0
  346. package/projects/obtservices/graphQL/autogenerated/queries/searchHotelChains.gql +3 -0
  347. package/projects/obtservices/graphQL/autogenerated/queries/searchHotels.gql +131 -0
  348. package/projects/obtservices/graphQL/autogenerated/queries/searchIRL.gql +514 -0
  349. package/projects/obtservices/graphQL/autogenerated/queries/searchIRLSupplierStations.gql +28 -0
  350. package/projects/obtservices/graphQL/autogenerated/queries/searchLounges.gql +89 -0
  351. package/projects/obtservices/graphQL/autogenerated/queries/searchParking.gql +70 -0
  352. package/projects/obtservices/graphQL/autogenerated/queries/searchPostcodes.gql +25 -0
  353. package/projects/obtservices/graphQL/autogenerated/queries/searchRail.gql +840 -0
  354. package/projects/obtservices/graphQL/autogenerated/queries/searchRailStations.gql +27 -0
  355. package/projects/obtservices/graphQL/autogenerated/queries/searchUserCanBookFor.gql +339 -0
  356. package/projects/obtservices/graphQL/autogenerated/queries/validateBasketItemMI.gql +3 -0
  357. package/projects/obtservices/graphQL/autogenerated/queries/validateUserMIFreeValue.gql +3 -0
  358. package/projects/obtservices/graphQL/documents/acceptNewPrice.graphql +5 -0
  359. package/projects/obtservices/graphQL/documents/addUserToBasketItem.graphql +9 -0
  360. package/projects/obtservices/graphQL/documents/basket.fragments.graphql +171 -0
  361. package/projects/obtservices/graphQL/documents/baskets.graphql +111 -0
  362. package/projects/obtservices/graphQL/documents/bookBasket.graphql +9 -0
  363. package/projects/obtservices/graphQL/documents/cabhire.graphql +66 -0
  364. package/projects/obtservices/graphQL/documents/carHireAvailabilityDetailRequest.graphql +44 -0
  365. package/projects/obtservices/graphQL/documents/carhire.graphql +117 -0
  366. package/projects/obtservices/graphQL/documents/deleteRecentSearch.graphql +3 -0
  367. package/projects/obtservices/graphQL/documents/deleteUserAddress.graphql +3 -0
  368. package/projects/obtservices/graphQL/documents/error.fragments.graphql +10 -0
  369. package/projects/obtservices/graphQL/documents/flights.graphql +830 -0
  370. package/projects/obtservices/graphQL/documents/getCarHireDepots.graphql +13 -0
  371. package/projects/obtservices/graphQL/documents/getConfermaOfficeNames.graphql +11 -0
  372. package/projects/obtservices/graphQL/documents/getConfermaQuicklist.graphql +108 -0
  373. package/projects/obtservices/graphQL/documents/getRailStation.graphql +31 -0
  374. package/projects/obtservices/graphQL/documents/getRailcards.graphql +6 -0
  375. package/projects/obtservices/graphQL/documents/getRiskAlerts.graphql +24 -0
  376. package/projects/obtservices/graphQL/documents/getUserAddresses.graphql +14 -0
  377. package/projects/obtservices/graphQL/documents/getUserCompanyOffices.graphql +18 -0
  378. package/projects/obtservices/graphQL/documents/getUserCurrentCarbonAllowance.graphql +29 -0
  379. package/projects/obtservices/graphQL/documents/getUserMIAutoSuggestValues.graphql +10 -0
  380. package/projects/obtservices/graphQL/documents/getUserPhoneNumbers.graphql +13 -0
  381. package/projects/obtservices/graphQL/documents/getUserRecentSearches.graphql +20 -0
  382. package/projects/obtservices/graphQL/documents/hotels.graphql +242 -0
  383. package/projects/obtservices/graphQL/documents/isPostcodeValid.graphql +3 -0
  384. package/projects/obtservices/graphQL/documents/lookups.graphql +54 -0
  385. package/projects/obtservices/graphQL/documents/lounges.graphql +88 -0
  386. package/projects/obtservices/graphQL/documents/moveItemToADifferentBasket.graphql +9 -0
  387. package/projects/obtservices/graphQL/documents/parking.graphql +79 -0
  388. package/projects/obtservices/graphQL/documents/rail.graphql +645 -0
  389. package/projects/obtservices/graphQL/documents/saveRecentSearch.graphql +5 -0
  390. package/projects/obtservices/graphQL/documents/saveUserAddress.graphql +14 -0
  391. package/projects/obtservices/graphQL/documents/searchAirlines.graphql +32 -0
  392. package/projects/obtservices/graphQL/documents/searchCities.graphql +14 -0
  393. package/projects/obtservices/graphQL/documents/searchConfermaCities.graphql +11 -0
  394. package/projects/obtservices/graphQL/documents/searchEurostar.graphql +810 -0
  395. package/projects/obtservices/graphQL/documents/searchHotelChains.graphql +3 -0
  396. package/projects/obtservices/graphQL/documents/searchIRL.graphql +521 -0
  397. package/projects/obtservices/graphQL/documents/searchPostcodes.graphql +7 -0
  398. package/projects/obtservices/graphQL/documents/searchRailStations.graphql +27 -0
  399. package/projects/obtservices/graphQL/documents/searchUserAddresses.graphql +14 -0
  400. package/projects/obtservices/graphQL/documents/set-basker-item-mi-group.graphql +9 -0
  401. package/projects/obtservices/graphQL/documents/setBasketItemLeadPassenger.graphql +5 -0
  402. package/projects/obtservices/graphQL/documents/setBasketItemMIValue.graphql +16 -0
  403. package/projects/obtservices/graphQL/documents/setBasketItemPaymentMethod.graphql +12 -0
  404. package/projects/obtservices/graphQL/documents/updateBasketNotes.graphql +10 -0
  405. package/projects/obtservices/graphQL/documents/updateBasketTitle.graphql +10 -0
  406. package/projects/obtservices/graphQL/documents/user.fragments.graphql +65 -0
  407. package/projects/obtservices/graphQL/documents/user.graphql +95 -0
  408. package/projects/obtservices/graphQL/documents/validateUserMIFreeValue.graphql +3 -0
  409. package/projects/obtservices/graphQL/schema/schema.graphql +2635 -0
  410. package/projects/obtservices/karma.conf.js +32 -0
  411. package/projects/obtservices/ng-package.json +7 -0
  412. package/projects/obtservices/package-lock.json +5 -0
  413. package/projects/obtservices/package.json +12 -0
  414. package/projects/obtservices/src/obtservices.ts +0 -0
  415. package/projects/obtservices/src/public_api.ts +1 -0
  416. package/projects/obtservices/tsconfig.lib.json +30 -0
  417. package/projects/obtservices/tsconfig.spec.json +17 -0
  418. package/projects/obtservices/tslint.json +17 -0
  419. package/tsconfig.json +36 -0
  420. package/tslint.json +62 -0
@@ -0,0 +1,2399 @@
1
+ import moment from 'moment';
2
+ import { BaseEnterpriseSearch } from './base-enterprise';
3
+ import { BaseStorageService } from '../services/storage.service';
4
+ import { BaseHelperRoutines } from './helpers';
5
+ import { Traveller } from '../models/traveller.object';
6
+ import { BehaviorSubject, combineLatest } from 'rxjs';
7
+ import { ValueDisplay } from '../interfaces/value-display';
8
+ import { FlightFilters } from '../interfaces/flight-filters.interface';
9
+ import { SelectFilter } from '../interfaces/select-filter.interface';
10
+ import {
11
+ AddItemToBasketMutationVariables,
12
+ BasketItem,
13
+ CurrencyCode,
14
+ DestinationEntry,
15
+ FareType,
16
+ FlightCabinClass,
17
+ FlightItinerary,
18
+ FlightJourney,
19
+ FlightPassengerObject,
20
+ FlightPassengerType,
21
+ GroupedFieldsFragment,
22
+ ItinerarySummary,
23
+ MatchingFlights,
24
+ SaveRecentSearchMutationVariables,
25
+ SearchFlightsV2QueryVariables,
26
+ ServiceType
27
+ } from '../types/graphql.types';
28
+ import {
29
+ FlightAllQuoteResult,
30
+ FlightGroupedQuoteResult,
31
+ FlightItineraryClass,
32
+ FlightQuoteResultArray,
33
+ NgbDateStruct,
34
+ OBTAirportDetails,
35
+ OBTAirlinesDetails,
36
+ FlightDirectionEnum,
37
+ GroupedFlights,
38
+ FlightItineraryWithSelected,
39
+ RecentSearch
40
+ } from '../types/types';
41
+ import {
42
+ BaseFlightQuoteFetcher,
43
+ FlightQuoteFetcherType
44
+ } from '../fetchers/flight-quote.fetcher';
45
+ import {
46
+ FullUserDetails,
47
+ UserServiceInterface
48
+ } from '../interfaces/Iuser.service';
49
+ import { EnterpriseSearchServiceInterface } from '../interfaces/Isearch.service';
50
+ import {
51
+ FlightEnterpriseSearchInterface,
52
+ FlightTempParams
53
+ } from '../interfaces/Iflight-enterprise-search';
54
+ import { ICheapestPrice } from '../interfaces/cheapest-price';
55
+ import { FlightSearchType } from './flight-search-type.enum';
56
+ import { IMultiDestination } from '../interfaces/flight-multi-destination.interface';
57
+ import {
58
+ EnterpriseBasketServiceInterface,
59
+ InternalBasketInterface
60
+ } from '../interfaces/Ienterprise-basket.service';
61
+ export interface AllowedClass {
62
+ name: string;
63
+ type: FlightCabinClass | null;
64
+ }
65
+
66
+ export interface FlightOperator {
67
+ code: string;
68
+ name: string;
69
+ }
70
+
71
+ export type AllowedClasses = AllowedClass[];
72
+
73
+ export enum TimeWindow {
74
+ Anytime = 'Anytime',
75
+ Depart = 'Depart By',
76
+ Arrive = 'Arrive By'
77
+ }
78
+
79
+ export enum SortTypes {
80
+ CheapestFirst = 'C',
81
+ MostExpensiveFirst = 'M',
82
+ FastestFirst = 'F',
83
+ PreferredFirst = 'P',
84
+ LowestEmissions = 'L'
85
+ }
86
+
87
+ export type FlightGroups =
88
+ | 'LiteEconomy'
89
+ | 'Economy'
90
+ | 'EconomyNoBags'
91
+ | 'EconomyRestricted'
92
+ | 'PremiumEconomy'
93
+ | 'Business'
94
+ | 'PremiumBusiness'
95
+ | 'First'
96
+ | 'PremiumFirst';
97
+
98
+ export type RestrictedFlightGroups =
99
+ | 'Economy'
100
+ | 'EconomyNoBags'
101
+ | 'EconomyRestricted'
102
+ | 'PremiumEconomy'
103
+ | 'Business'
104
+ | 'First';
105
+
106
+ interface FlightSessionType {
107
+ results: FlightQuoteResultArray;
108
+ groupData: { [key: number]: number[] };
109
+ grouped: GroupedFlights;
110
+ query: SearchFlightsV2QueryVariables;
111
+ }
112
+
113
+ export class FlightEnterpriseSearch<FQ_Q extends FlightQuoteFetcherType>
114
+ extends BaseEnterpriseSearch<
115
+ FlightTempParams,
116
+ FlightAllQuoteResult,
117
+ FlightQuoteResultArray
118
+ >
119
+ implements FlightEnterpriseSearchInterface
120
+ {
121
+ static readonly STORAGE_SESSION_PARAMS = 'search_flight';
122
+ static readonly STORAGE_SESSION_RESULTS = 'results_flight';
123
+
124
+ public type: ServiceType = ServiceType.Flight;
125
+
126
+ avaliableClasses: BehaviorSubject<AllowedClasses> =
127
+ new BehaviorSubject<AllowedClasses>([]);
128
+ timeCriteriaOptions: BehaviorSubject<TimeWindow[]> = new BehaviorSubject<
129
+ TimeWindow[]
130
+ >([]);
131
+ flightOperators: BehaviorSubject<FlightOperator[]> = new BehaviorSubject<
132
+ FlightOperator[]
133
+ >([]);
134
+
135
+ private _negotiated: boolean = false;
136
+ private _nearby_airports: boolean = false;
137
+
138
+ private _timeArray: ValueDisplay[];
139
+ private _sortArray: ValueDisplay[] = [
140
+ { display: 'Cheapest First', value: SortTypes.CheapestFirst },
141
+ { display: 'Most Expensive First', value: SortTypes.MostExpensiveFirst },
142
+ { display: 'Fastest First', value: SortTypes.FastestFirst },
143
+ { display: 'Preferred Fares First', value: SortTypes.PreferredFirst },
144
+ { display: 'Lowest Co2 Emissions First', value: SortTypes.LowestEmissions }
145
+ ];
146
+
147
+ private _fareTypeArray: ValueDisplay[] = [
148
+ { value: FareType.Flexible, display: 'Flexible' },
149
+ { value: FareType.Leisure, display: 'Leisure' },
150
+ { value: FareType.Lowest, display: 'Lowest' },
151
+ { value: FareType.Negotiated, display: 'Negotiated' },
152
+ { value: FareType.NonNegotiated, display: 'Non-Negotiated' },
153
+ { value: FareType.RequestFareRules, display: 'Request Fare Rules' },
154
+ { value: FareType.SelectAndPro, display: 'Select & Pro' }
155
+ ];
156
+
157
+ public minimumOutBoundDate = {
158
+ year: moment().year(),
159
+ month: moment().month() + 1,
160
+ day: moment().date()
161
+ };
162
+
163
+ public minimumInBoundDate = {
164
+ year: moment().year(),
165
+ month: moment().month() + 1,
166
+ day: moment().date()
167
+ };
168
+ private _outDate: NgbDateStruct;
169
+ private _outTime: string;
170
+ private _inDate: NgbDateStruct;
171
+ private _inTime: string;
172
+ private _destinationAirport: any;
173
+ private _originAirport: any;
174
+ private _passengers: any;
175
+ private groupedObject: FlightItineraryWithSelected[];
176
+ protected flightsToGroup: { [key: number]: number[] } = {};
177
+ protected resultQuery: SearchFlightsV2QueryVariables;
178
+ protected grouped: GroupedFlights = null;
179
+ travellers: Traveller[] = null;
180
+ protected resultsSessionName = FlightEnterpriseSearch.STORAGE_SESSION_RESULTS;
181
+ selectedGroupFlight: FlightItineraryWithSelected;
182
+ private _showHotelForm: boolean = false;
183
+ private _hotelSearchRequested: boolean = false;
184
+
185
+ public get timeArray() {
186
+ this._timeArray =
187
+ this._timeArray ||
188
+ Array(96)
189
+ .fill(0)
190
+ .map((_, index: number) => {
191
+ return {
192
+ value:
193
+ Math.floor(index / 4)
194
+ .toString()
195
+ .padStart(2, '0') +
196
+ ':' +
197
+ ((index % 4) * 15).toString().padStart(2, '0'),
198
+ display:
199
+ Math.floor(index / 4)
200
+ .toString()
201
+ .padStart(2, '0') +
202
+ ':' +
203
+ ((index % 4) * 15).toString().padStart(2, '0')
204
+ };
205
+ });
206
+ return this._timeArray;
207
+ }
208
+
209
+ public get preferredCarriers(): OBTAirlinesDetails[] {
210
+ return this.tempParams.preferredCarriers;
211
+ }
212
+
213
+ public set preferredCarriers(value: OBTAirlinesDetails[]) {
214
+ this.tempParams.preferredCarriers = value;
215
+ this._isValid();
216
+ }
217
+
218
+ public get operator1(): OBTAirlinesDetails {
219
+ return this.tempParams.preferredCarriers[0];
220
+ }
221
+
222
+ public set operator1(value: OBTAirlinesDetails) {
223
+ this.tempParams.preferredCarriers[0] = value;
224
+ this._isValid();
225
+ }
226
+ public get operator2(): OBTAirlinesDetails {
227
+ return this.tempParams.preferredCarriers[1];
228
+ }
229
+
230
+ public set operator2(value: OBTAirlinesDetails) {
231
+ this.tempParams.preferredCarriers[1] = value;
232
+ this._isValid();
233
+ }
234
+ public get operator3(): OBTAirlinesDetails {
235
+ return this.tempParams.preferredCarriers[2];
236
+ }
237
+
238
+ public set operator3(value: OBTAirlinesDetails) {
239
+ this.tempParams.preferredCarriers[2] = value;
240
+ this._isValid();
241
+ }
242
+ public get operator4(): OBTAirlinesDetails {
243
+ return this.tempParams.preferredCarriers[3];
244
+ }
245
+
246
+ public set operator4(value: OBTAirlinesDetails) {
247
+ this.tempParams.preferredCarriers[3] = value;
248
+ this._isValid();
249
+ }
250
+
251
+ private _minDate: NgbDateStruct;
252
+ public get minDate(): NgbDateStruct {
253
+ this._minDate = this._minDate || this.helpers.momentToNgDate(moment());
254
+ return this._minDate;
255
+ }
256
+
257
+ public get adults(): number {
258
+ return this.tempParams.adults;
259
+ }
260
+
261
+ public set adults(value: number) {
262
+ this.tempParams.adults = Number(value);
263
+ this.updateTravellers();
264
+ }
265
+
266
+ public get children(): number {
267
+ return this.tempParams.children;
268
+ }
269
+
270
+ public set children(value: number) {
271
+ this.tempParams.children = Number(value);
272
+ this.updateTravellers();
273
+ }
274
+
275
+ public get departLocation(): string | OBTAirportDetails {
276
+ return this.tempParams.departLocation;
277
+ }
278
+
279
+ public set departLocation(value: string | OBTAirportDetails) {
280
+ this.tempParams.departLocation = value;
281
+ if (typeof value === 'string') {
282
+ this._originAirport = '';
283
+ } else if (value && value.gateway) {
284
+ this._originAirport = value.gateway;
285
+ } else {
286
+ this._originAirport = null;
287
+ }
288
+ this._isValid();
289
+ }
290
+
291
+ public get queryOriginAiport(): string {
292
+ return this._originAirport;
293
+ }
294
+
295
+ public get queryDestinationAiport(): string {
296
+ return this._destinationAirport;
297
+ }
298
+
299
+ public get departDate(): NgbDateStruct {
300
+ return this._outDate;
301
+ }
302
+
303
+ public set departDate(value: NgbDateStruct) {
304
+ this._outDate = value;
305
+ this.outBoundDate = this.helpers.ngDateToMoment(
306
+ this._outDate,
307
+ this._outTime
308
+ );
309
+ }
310
+
311
+ public get departTime(): string {
312
+ return this._outTime;
313
+ }
314
+
315
+ public set departTime(value: string) {
316
+ this._outTime = value;
317
+ this.outBoundDate = this.helpers.ngDateToMoment(
318
+ this._outDate,
319
+ this._outTime
320
+ );
321
+ }
322
+
323
+ public get outBoundDate(): moment.Moment {
324
+ return this.tempParams.outBoundDate;
325
+ }
326
+
327
+ public set outBoundDate(value: moment.Moment) {
328
+ this.tempParams.outBoundDate = value.isValid() ? value : null;
329
+ this.minimumInBoundDate = {
330
+ year: value.year(),
331
+ month: value.month() + 1,
332
+ day: value.date()
333
+ };
334
+
335
+ if (
336
+ this.tempParams.outBoundDate &&
337
+ this.tempParams.inboundDate &&
338
+ this.tempParams.outBoundDate.isAfter(this.tempParams.inboundDate)
339
+ ) {
340
+ this.inboundDate = moment(this.tempParams.outBoundDate).add(1, 'day');
341
+ }
342
+ this._outDate = this.helpers.momentToNgDate(value);
343
+ this._outTime = this.helpers.formatTimeColon(value);
344
+ this._isValid();
345
+ }
346
+
347
+ public get returnDate(): NgbDateStruct {
348
+ return this._inDate;
349
+ }
350
+
351
+ public set returnDate(value: NgbDateStruct) {
352
+ this._inDate = value;
353
+ this.inboundDate = this.helpers.ngDateToMoment(this._inDate, this._inTime);
354
+ }
355
+
356
+ public get arriveTime(): string {
357
+ return this._inTime;
358
+ }
359
+
360
+ public set arriveTime(value: string) {
361
+ this._inTime = value;
362
+ this.inboundDate = this.helpers.ngDateToMoment(this._inDate, this._inTime);
363
+ }
364
+
365
+ public get inboundDate(): moment.Moment {
366
+ return this.tempParams.inboundDate;
367
+ }
368
+
369
+ public set inboundDate(value: moment.Moment) {
370
+ this.tempParams.inboundDate = value.isValid() ? value : null;
371
+ this._inDate = this.helpers.momentToNgDate(value);
372
+ this._inTime = this.helpers.formatTimeColon(value);
373
+ this._isValid();
374
+ }
375
+
376
+ public get arriveLocation(): string | OBTAirportDetails {
377
+ return this.tempParams.arriveLocation;
378
+ }
379
+
380
+ public set arriveLocation(value: string | OBTAirportDetails) {
381
+ this.tempParams.arriveLocation = value;
382
+ if (typeof value === 'string') {
383
+ this._destinationAirport = '';
384
+ } else if (value && value.gateway) {
385
+ this._destinationAirport = value.gateway;
386
+ } else {
387
+ this._destinationAirport = null;
388
+ }
389
+ this._isValid();
390
+ }
391
+
392
+ get cabinClass(): FlightCabinClass | null {
393
+ return this.tempParams.cabinClass;
394
+ }
395
+
396
+ set cabinClass(value: FlightCabinClass | null) {
397
+ this.tempParams.cabinClass = value;
398
+ this._isValid();
399
+ }
400
+
401
+ get returnCabinClass(): FlightCabinClass | null {
402
+ return this.tempParams.returnCabinClass;
403
+ }
404
+
405
+ set returnCabinClass(value: FlightCabinClass | null) {
406
+ this.tempParams.returnCabinClass = value;
407
+ this._isValid();
408
+ }
409
+
410
+ get chosenSearchType(): FlightSearchType {
411
+ return this.tempParams.chosenSearchType;
412
+ }
413
+
414
+ set chosenSearchType(type: FlightSearchType) {
415
+ this.tempParams.chosenSearchType = type;
416
+ }
417
+
418
+ get isReturn(): boolean {
419
+ return this.tempParams.chosenSearchType === FlightSearchType.return;
420
+ }
421
+
422
+ get outTimeCriteria(): TimeWindow {
423
+ return this.tempParams.outTimeCriteria;
424
+ }
425
+
426
+ set outTimeCriteria(value: TimeWindow) {
427
+ this.tempParams.outTimeCriteria = value;
428
+ this._isValid();
429
+ }
430
+
431
+ get inTimeCriteria(): TimeWindow {
432
+ return this.tempParams.inTimeCriteria;
433
+ }
434
+
435
+ set inTimeCriteria(value: TimeWindow) {
436
+ this.tempParams.inTimeCriteria = value;
437
+ this._isValid();
438
+ }
439
+ get maxConnections(): number {
440
+ return this.tempParams.maxConnections;
441
+ }
442
+
443
+ set maxConnections(value: number) {
444
+ this.tempParams.maxConnections = value;
445
+ }
446
+
447
+ private _multiDestination: DestinationEntry[] = [];
448
+ get multiDestination(): IMultiDestination[] {
449
+ return this.tempParams.multiDestination;
450
+ }
451
+
452
+ set multiDestination(valueArray: IMultiDestination[]) {
453
+ this.tempParams.multiDestination = valueArray;
454
+ this._isValid();
455
+ }
456
+
457
+ public get showHotelForm(): boolean {
458
+ return this._showHotelForm;
459
+ }
460
+
461
+ public set showHotelForm(newVal: boolean) {
462
+ this._showHotelForm = newVal;
463
+ }
464
+
465
+ public get hotelSearchRequested(): boolean {
466
+ return this._hotelSearchRequested;
467
+ }
468
+
469
+ public set hotelSearchRequested(newVal: boolean) {
470
+ this._hotelSearchRequested = newVal;
471
+ }
472
+
473
+ setMultiDestinationQuery(multiDestination: IMultiDestination[]) {
474
+ const newMultiDestination = this.helpers.clone(multiDestination);
475
+ return newMultiDestination.reduce(
476
+ (destinationArray: DestinationEntry[], item: IMultiDestination) => {
477
+ const destinationObject = {} as DestinationEntry;
478
+ destinationObject.orig = item.orig.gateway;
479
+ destinationObject.dest = item.dest.gateway;
480
+ destinationObject.date = this.helpers.formatIsoDate(item.date);
481
+ destinationArray.push(destinationObject);
482
+ return destinationArray;
483
+ },
484
+ [] as DestinationEntry[]
485
+ );
486
+ }
487
+
488
+ // get only
489
+ get sortDropdownValues(): ValueDisplay[] {
490
+ return this._sortArray;
491
+ }
492
+
493
+ get fareTypesValues(): ValueDisplay[] {
494
+ return this._fareTypeArray;
495
+ }
496
+
497
+ get fareType(): FareType {
498
+ return this.tempParams.fareType;
499
+ }
500
+
501
+ set fareType(value: FareType) {
502
+ this.tempParams.fareType = value;
503
+ this._isValid();
504
+ }
505
+
506
+ get negotiated(): boolean {
507
+ return this._negotiated;
508
+ }
509
+
510
+ set negotiated(value: boolean) {
511
+ this._negotiated = value;
512
+ }
513
+
514
+ get includeNearbyAirports(): boolean {
515
+ return this.tempParams.includeNearbyAirports;
516
+ }
517
+
518
+ set includeNearbyAirports(value: boolean) {
519
+ this.tempParams.includeNearbyAirports = value;
520
+ }
521
+ constructor(
522
+ private flightfetcher: BaseFlightQuoteFetcher<FQ_Q>,
523
+ private helpers: BaseHelperRoutines,
524
+ userService: UserServiceInterface,
525
+ private basketService: EnterpriseBasketServiceInterface,
526
+ storageService: BaseStorageService,
527
+ private searchService: EnterpriseSearchServiceInterface
528
+ ) {
529
+ super(
530
+ storageService,
531
+ (results: FlightAllQuoteResult): FlightQuoteResultArray => {
532
+ this.flightsToGroup = {};
533
+ this.grouped = results.grouped || [];
534
+ this.resultQuery = this.getSearchQuery();
535
+ delete this.resultQuery.withGrouped;
536
+
537
+ if (results && this.searchService.isFlightsGrouped()) {
538
+ this.groupedObject = (results.multi || [])
539
+ .reduce(
540
+ (
541
+ previousItems: FlightItineraryWithSelected[],
542
+ nextItem: ItinerarySummary
543
+ ) => {
544
+ return previousItems.concat(nextItem.results);
545
+ },
546
+ results.journeys as unknown as FlightItineraryWithSelected[]
547
+ )
548
+ .map((flight: FlightItineraryWithSelected) => {
549
+ return Object.assign(flight, { seleced: false, canSelect: true });
550
+ });
551
+
552
+ const returnData = (results.grouped || []).reduce(
553
+ (
554
+ acc: FlightGroupedQuoteResult[],
555
+ item: GroupedFieldsFragment,
556
+ groupNumber: number
557
+ ): FlightGroupedQuoteResult[] => {
558
+ const isOutBound =
559
+ item.boundIndicator === FlightDirectionEnum.Outbound;
560
+ const returnObject: FlightGroupedQuoteResult = {
561
+ direction: item.boundIndicator,
562
+ classes: {
563
+ [FlightCabinClass.EconomyNoBags]:
564
+ null as FlightItineraryClass,
565
+ [FlightCabinClass.EconomyRestricted]:
566
+ null as FlightItineraryClass,
567
+ [FlightCabinClass.Economy]: null as FlightItineraryClass,
568
+ [FlightCabinClass.Business]: null as FlightItineraryClass,
569
+ [FlightCabinClass.First]: null as FlightItineraryClass,
570
+ [FlightCabinClass.PremiumEconomy]:
571
+ null as FlightItineraryClass
572
+ },
573
+ originAirport: '',
574
+ originAirportName: '',
575
+ destinationAirport: '',
576
+ destinationAirportName: '',
577
+ departDateTime: '',
578
+ arrivalDateTime: '',
579
+ outboundTotalDuration: 0,
580
+ inboundTotalDuration: 0,
581
+ outlegs: null,
582
+ inlegs: null,
583
+ outlegsCount: 0,
584
+ inlegsCount: 0,
585
+ dataSource: '',
586
+ preferred: false,
587
+ outboundFlightNumber: '',
588
+ operator: '',
589
+ operatorFull: '',
590
+ inboundFlightNumber: '',
591
+ isReturn: false
592
+ };
593
+ const brands: MatchingFlights = item.flights;
594
+
595
+ Object.keys(brands)
596
+ .filter((key: string) => key[0] !== '_')
597
+ .forEach((brand: FlightGroups) => {
598
+ if (!brands[brand].length) {
599
+ return;
600
+ }
601
+ // ! using a reduce because not all flights actually exist and we were seeing undefined in the flight list
602
+ const matchingBrandFlights: FlightItinerary[] = brands[
603
+ brand
604
+ ].reduce((acc1: FlightItinerary[], flightNum: number, i) => {
605
+ (this.flightsToGroup[flightNum] =
606
+ this.flightsToGroup[flightNum] || []).push(groupNumber);
607
+ const flight = this.groupedObject[flightNum];
608
+ if (isOutBound) {
609
+ this.createGroupedItem(
610
+ returnObject,
611
+ flight.source,
612
+ flight.outboundFlights,
613
+ flight.outboundTotalDuration,
614
+ flight.inboundFlights,
615
+ flight.inboundTotalDuration
616
+ );
617
+ } else {
618
+ this.createGroupedItem(
619
+ returnObject,
620
+ flight.source,
621
+ flight.inboundFlights,
622
+ flight.inboundTotalDuration,
623
+ flight.outboundFlights,
624
+ flight.outboundTotalDuration
625
+ );
626
+ }
627
+ if (flight) {
628
+ acc1.push(flight);
629
+ }
630
+ return acc1;
631
+ }, []);
632
+ let correctBrand: RestrictedFlightGroups;
633
+
634
+ switch (brand) {
635
+ case FlightCabinClass.LiteEconomy:
636
+ case FlightCabinClass.Economy:
637
+ correctBrand = FlightCabinClass.Economy;
638
+ break;
639
+ case FlightCabinClass.EconomyNoBags:
640
+ correctBrand = FlightCabinClass.EconomyNoBags;
641
+ break;
642
+ case FlightCabinClass.EconomyRestricted:
643
+ correctBrand = FlightCabinClass.EconomyRestricted;
644
+ break;
645
+ case FlightCabinClass.PremiumBusiness:
646
+ case FlightCabinClass.Business:
647
+ correctBrand = FlightCabinClass.Business;
648
+ break;
649
+ case FlightCabinClass.PremiumFirst:
650
+ case FlightCabinClass.First:
651
+ correctBrand = FlightCabinClass.First;
652
+ break;
653
+ case FlightCabinClass.PremiumEconomy:
654
+ correctBrand = FlightCabinClass.PremiumEconomy;
655
+ break;
656
+ default:
657
+ console.log('something went wrong');
658
+ break;
659
+ }
660
+
661
+ const minprice =
662
+ this.getMinFlightPriceForBrand(matchingBrandFlights);
663
+ const maxprice =
664
+ this.getMaxFlightPriceForBrand(matchingBrandFlights);
665
+ if (returnObject.classes[correctBrand]?.flights?.length) {
666
+ returnObject.classes[correctBrand].flights.concat(
667
+ matchingBrandFlights
668
+ );
669
+ returnObject.classes[correctBrand].minprice = Math.min(
670
+ returnObject.classes[correctBrand].minprice,
671
+ minprice
672
+ );
673
+ returnObject.classes[correctBrand].maxprice = Math.max(
674
+ returnObject.classes[correctBrand].maxprice,
675
+ maxprice
676
+ );
677
+ } else {
678
+ returnObject.classes[correctBrand] = {
679
+ flights: matchingBrandFlights,
680
+ minprice,
681
+ maxprice,
682
+ currency: matchingBrandFlights[0].total.currency
683
+ };
684
+ }
685
+ });
686
+ if (returnObject) {
687
+ acc.push(returnObject);
688
+ }
689
+ return acc;
690
+ },
691
+ []
692
+ );
693
+
694
+ console.log('Processed Grouped data', returnData);
695
+ return returnData;
696
+ } else {
697
+ return results ? [results] : [];
698
+ }
699
+ }
700
+ );
701
+
702
+ const data: {
703
+ tempParams: FlightTempParams;
704
+ originalUserSearch: FlightTempParams;
705
+ } = storageService.getSessionItem(
706
+ FlightEnterpriseSearch.STORAGE_SESSION_PARAMS
707
+ ) || {
708
+ tempParams: {} as FlightTempParams,
709
+ originalUserSearch: {} as FlightTempParams
710
+ };
711
+ // data.tempParams.adults = 1;
712
+ // data.tempParams.cabinClass = [FlightCabinClass.Economy];
713
+ const query = searchService.makeFlightQuery(data.tempParams);
714
+ this.updateTempParams(query);
715
+ this._originalUserSearch = data.originalUserSearch;
716
+ if (searchService.shouldAddTravellerSubscription()) {
717
+ searchService.travellerInformation.subscribe(
718
+ (travellers: Traveller[]) => {
719
+ this.travellers = travellers;
720
+ const splitTravellers = this.helpers.selectedTravellers(
721
+ travellers,
722
+ ServiceType.Flight
723
+ );
724
+ this.tempParams.adults = splitTravellers.adults.length;
725
+ this.tempParams.children = splitTravellers.children.length;
726
+ // this.tempParams.infants = splitTravellers.infants.length;
727
+
728
+ this.updateTravellers();
729
+ this._isValid();
730
+ }
731
+ );
732
+ }
733
+
734
+ userService.changeUser.subscribe((user: FullUserDetails) => {
735
+ this.timeCriteriaOptions.next([
736
+ TimeWindow.Anytime,
737
+ TimeWindow.Arrive,
738
+ TimeWindow.Depart
739
+ ]); // TODO update with any UFs
740
+ this.flightOperators.next([{ code: 'BA', name: 'British Airways' }]); // Fetch these from DB
741
+ this.updateAvaliableClasses();
742
+ });
743
+
744
+ this.updateTravellers();
745
+
746
+ if (this.isValid.value) {
747
+ const results: FlightSessionType = storageService.getSessionItem(
748
+ this.resultsSessionName
749
+ ) || {
750
+ results: [],
751
+ groupData: {},
752
+ grouped: [],
753
+ query: {} as SearchFlightsV2QueryVariables
754
+ };
755
+ this.fullResults = this.helpers.clone(results.results);
756
+ this.flightsToGroup = results.groupData || {};
757
+ this.resultQuery = results.query;
758
+ // if (results == null && this.isValid) {
759
+ // searchService.startSearches();
760
+ // }
761
+ // this._cheapestResultPrice = this.updateLowestPrice(results);
762
+ this.results.next(results.results || ([] as FlightQuoteResultArray));
763
+ }
764
+
765
+ this.negotiated =
766
+ this.tempParams.fareType === FareType.Negotiated ? true : false;
767
+ }
768
+ private createGroupedItem(
769
+ returnObject: FlightGroupedQuoteResult,
770
+ source: string,
771
+ outboundFlights: FlightJourney[],
772
+ outboundTotalDuration: number,
773
+ inboundFlights: FlightJourney[],
774
+ inboundTotalDuration: number
775
+ ) {
776
+ if (outboundFlights?.length && !returnObject.departDateTime) {
777
+ const first = outboundFlights[0];
778
+ const last = outboundFlights[outboundFlights.length - 1];
779
+ returnObject.originAirport = first.originAirport;
780
+ returnObject.originAirportName = first.originAirportName;
781
+ returnObject.destinationAirport = last.destinationAirport;
782
+ returnObject.destinationAirportName = last.destinationAirportName;
783
+ returnObject.departDateTime = first.dateTimeDeparting;
784
+ returnObject.arrivalDateTime = last.dateTimeArriving;
785
+ returnObject.outboundTotalDuration = outboundTotalDuration;
786
+ returnObject.dataSource = source;
787
+ returnObject.operator = first.marketingCarrier;
788
+ returnObject.operatorFull = first.marketingCarrierName;
789
+ returnObject.outlegsCount = outboundFlights.length;
790
+ returnObject.outlegs = outboundFlights;
791
+ returnObject.outboundFlightNumber =
792
+ this.helpers.joinFromAttribute<FlightJourney>(
793
+ '-',
794
+ 'marketingFlightNumber',
795
+ outboundFlights
796
+ );
797
+
798
+ returnObject.isReturn = false;
799
+ }
800
+
801
+ if (inboundFlights?.length && !returnObject.inboundTotalDuration) {
802
+ returnObject.inboundTotalDuration = inboundTotalDuration;
803
+ returnObject.inlegsCount = inboundFlights.length;
804
+ returnObject.inlegs = inboundFlights;
805
+ returnObject.inboundFlightNumber =
806
+ this.helpers.joinFromAttribute<FlightJourney>(
807
+ '-',
808
+ 'operatingFlightNumber',
809
+ inboundFlights
810
+ );
811
+
812
+ returnObject.isReturn = true;
813
+ }
814
+ }
815
+
816
+ protected makeSessionResults(
817
+ data: FlightQuoteResultArray
818
+ ): FlightSessionType {
819
+ return {
820
+ results: data,
821
+ groupData: this.flightsToGroup,
822
+ grouped: this.grouped,
823
+ query: this.resultQuery
824
+ };
825
+ }
826
+
827
+ getMaxFlightPriceForBrand(matchingBrandFlights: FlightItinerary[]): number {
828
+ let max = 0;
829
+ matchingBrandFlights.forEach((flight) => {
830
+ if (max < flight?.total?.price) {
831
+ max = flight.total.price;
832
+ }
833
+ });
834
+ return max;
835
+ }
836
+ getMinFlightPriceForBrand(matchingBrandFlights: FlightItinerary[]): number {
837
+ let min = Number.MAX_SAFE_INTEGER;
838
+ matchingBrandFlights.forEach((flight) => {
839
+ if (min > flight?.total?.price) {
840
+ min = flight.total.price;
841
+ }
842
+ });
843
+ return min;
844
+ }
845
+
846
+ protected resetQuery(checkIsValid: boolean = true): void {
847
+ this.updateTempParams(this.searchService.makeFlightQuery());
848
+ if (checkIsValid) {
849
+ this._isValid();
850
+ }
851
+ }
852
+
853
+ public resetParams(): void {
854
+ this.reset();
855
+ this.resetQuery();
856
+ }
857
+
858
+ private _isValid() {
859
+ if (!this.doChecks) {
860
+ return;
861
+ }
862
+ this.storageService.setSessionItem(
863
+ FlightEnterpriseSearch.STORAGE_SESSION_PARAMS,
864
+ {
865
+ tempParams: this.tempParams,
866
+ originalUserSearch: this.originalUserSearch
867
+ }
868
+ );
869
+
870
+ this.validationMessages = [];
871
+ if (this.tempParams.chosenSearchType === FlightSearchType.multiCity) {
872
+ this.multiCityValidation();
873
+ } else {
874
+ if (!this._originAirport) {
875
+ this.validationMessages.push('Please add in a departure location');
876
+ }
877
+ if (!this._destinationAirport) {
878
+ this.validationMessages.push('Please add in an arrival destination');
879
+ }
880
+ if (!this.tempParams.outBoundDate.isAfter(moment())) {
881
+ this.validationMessages.push('Departure date can not be in the past');
882
+ }
883
+
884
+ if (
885
+ this._originAirport &&
886
+ this._destinationAirport &&
887
+ this._destinationAirport === this._originAirport
888
+ ) {
889
+ this.validationMessages.push(
890
+ 'Origin and destination airport cannot be the same'
891
+ );
892
+ }
893
+ if (this.isReturn) {
894
+ // TODO check that return details are set
895
+ if (
896
+ this.tempParams.outBoundDate.isSameOrAfter(
897
+ this.tempParams.inTimeCriteria
898
+ )
899
+ ) {
900
+ this.validationMessages.push(
901
+ 'Return date must be after the departure date'
902
+ );
903
+ }
904
+ }
905
+ this.isValid.next(this.validationMessages.length === 0);
906
+ this.messages.next(this.validationMessages);
907
+ }
908
+ }
909
+
910
+ multiCityValidation() {
911
+ let isemptyValue = false;
912
+ let isemptyLanding = false;
913
+ let isSameValue = false;
914
+ this.tempParams.multiDestination.map((element, i) => {
915
+ if (!element.orig) {
916
+ isemptyValue = true;
917
+ if (i < 2) {
918
+ isemptyLanding = true;
919
+ }
920
+ }
921
+ if (element.orig === element.dest) isSameValue = true;
922
+ });
923
+ if (!moment(this.tempParams.multiDestination[0].date).isAfter(moment())) {
924
+ this.validationMessages.push('Departure date can not be in the past');
925
+ }
926
+ if (isemptyLanding)
927
+ this.validationMessages.push('Please select landing airport(s)');
928
+ if (isemptyValue)
929
+ this.validationMessages.push('Please select take off airport(s)');
930
+ if (isSameValue)
931
+ this.validationMessages.push(
932
+ 'Take off and landing location(s) cannot be the same'
933
+ );
934
+ }
935
+ startSearch(): Promise<boolean> {
936
+ this.results.next([]);
937
+ this._isValid();
938
+
939
+ if (this.isValid.value) {
940
+ this._originalUserSearch = Object.freeze({ ...this.tempParams });
941
+ this.storageService.setSessionItem(
942
+ FlightEnterpriseSearch.STORAGE_SESSION_PARAMS,
943
+ {
944
+ tempParams: this.tempParams,
945
+ originalUserSearch: this.originalUserSearch
946
+ }
947
+ );
948
+ const query = this.getSearchQuery();
949
+ this.searchService.saveRecentSearch(this.getRecentSearchQuery(query));
950
+
951
+ return this._startSearch(this.flightfetcher.fetchList(query));
952
+ } else {
953
+ return Promise.resolve(false);
954
+ }
955
+ }
956
+
957
+ getRecentSearchQuery(
958
+ query: SearchFlightsV2QueryVariables
959
+ ): SaveRecentSearchMutationVariables {
960
+ return {
961
+ serviceType: ServiceType.Flight,
962
+ searchArgs: query,
963
+ travelDate: this.outBoundDate.format(),
964
+ travellers: this.helpers.getTravellersId(this.travellers)
965
+ };
966
+ }
967
+
968
+ public startRecentSearch(recentSearch: RecentSearch): void {
969
+ if (recentSearch.searchArgs.outboundDate) {
970
+ this.outBoundDate = this.convertRecentSearchDateTime(
971
+ recentSearch.searchArgs.outboundDate,
972
+ recentSearch.searchArgs.outboundDepartureTimeWindow
973
+ );
974
+ }
975
+
976
+ if (recentSearch.searchArgs.returnDate) {
977
+ this.inboundDate = this.convertRecentSearchDateTime(
978
+ recentSearch.searchArgs.returnDate,
979
+ recentSearch.searchArgs.returnDepartureTimeWindow
980
+ );
981
+ }
982
+
983
+ this.fareType = recentSearch.searchArgs.fareType;
984
+ this.maxConnections = recentSearch.searchArgs.maxConnections;
985
+
986
+ if (recentSearch.searchArgs.outboundCabinClass) {
987
+ this.cabinClass = recentSearch.searchArgs.outboundCabinClass[0];
988
+ }
989
+ if (recentSearch.searchArgs.returnCabinClass) {
990
+ this.returnCabinClass = recentSearch.searchArgs.returnCabinClass[0];
991
+ }
992
+
993
+ this.includeNearbyAirports = recentSearch.searchArgs.includeNearbyAirports
994
+ ? true
995
+ : false;
996
+
997
+ this.chosenSearchType = recentSearch.searchArgs.returnTrip
998
+ ? FlightSearchType.return
999
+ : FlightSearchType.oneWay;
1000
+
1001
+ if (recentSearch.searchArgs.outboundDepartureTimeWindow) {
1002
+ this.outTimeCriteria = TimeWindow.Depart;
1003
+ } else if (recentSearch.searchArgs.outboundArrivalTimeWindow) {
1004
+ this.outTimeCriteria = TimeWindow.Arrive;
1005
+ } else {
1006
+ this.outTimeCriteria = TimeWindow.Anytime;
1007
+ }
1008
+
1009
+ if (recentSearch.searchArgs.returnDepartureTimeWindow) {
1010
+ this.inTimeCriteria = TimeWindow.Depart;
1011
+ } else if (recentSearch.searchArgs.returnArrivalTimeWindow) {
1012
+ this.inTimeCriteria = TimeWindow.Arrive;
1013
+ } else {
1014
+ this.inTimeCriteria = TimeWindow.Anytime;
1015
+ }
1016
+
1017
+ combineLatest([
1018
+ this.searchService.getAirportByCode(
1019
+ recentSearch.searchArgs.originAirport
1020
+ ),
1021
+ this.searchService.getAirportByCode(
1022
+ recentSearch.searchArgs.destinationAirport
1023
+ )
1024
+ ]).subscribe(([departLocation, arriveLocation]) => {
1025
+ if (departLocation && arriveLocation) {
1026
+ this.departLocation = {
1027
+ destination: departLocation.iataMatch.name,
1028
+ gateway: departLocation.iataMatch.iata,
1029
+ terminals: this.searchService.processTerminals(
1030
+ departLocation.iataMatch.terminals
1031
+ ),
1032
+ country: departLocation.iataMatch?.locationDetails?.country,
1033
+ postcode: departLocation.iataMatch?.locationDetails?.postcode,
1034
+ countryCode: departLocation.iataMatch?.locationDetails?.countryCode
1035
+ };
1036
+ this.arriveLocation = {
1037
+ destination: arriveLocation.iataMatch.name,
1038
+ gateway: arriveLocation.iataMatch.iata,
1039
+ terminals: this.searchService.processTerminals(
1040
+ arriveLocation.iataMatch.terminals
1041
+ ),
1042
+ country: arriveLocation.iataMatch?.locationDetails?.country,
1043
+ postcode: arriveLocation.iataMatch?.locationDetails?.postcode,
1044
+ countryCode: arriveLocation.iataMatch?.locationDetails?.countryCode
1045
+ };
1046
+
1047
+ if (recentSearch.searchArgs.preferredCarriers) {
1048
+ let preferredCarriers: OBTAirlinesDetails[] = [];
1049
+ recentSearch.searchArgs.preferredCarriers.map(
1050
+ (preferredCarry: string) => {
1051
+ this.searchService
1052
+ .getAirlinesList(preferredCarry)
1053
+ .subscribe((items: OBTAirlinesDetails[]) => {
1054
+ items.map((item: OBTAirlinesDetails) => {
1055
+ if (item.code === preferredCarry) {
1056
+ preferredCarriers.push(item);
1057
+ }
1058
+ });
1059
+ this.preferredCarriers = preferredCarriers;
1060
+ this.searchService.startSearches();
1061
+ });
1062
+ }
1063
+ );
1064
+ }
1065
+ this.searchService.startSearches();
1066
+ }
1067
+ });
1068
+ this.searchService.startSearches();
1069
+ }
1070
+
1071
+ private makeDepartureTimeWindow(
1072
+ dateTime: moment.Moment,
1073
+ window: TimeWindow,
1074
+ isFlightsGrouped: boolean
1075
+ ): string {
1076
+ return window === TimeWindow.Depart
1077
+ ? isFlightsGrouped
1078
+ ? this.helpers.makeTimeWindow(dateTime, -2, 2)
1079
+ : this.helpers.makeTimeWindow(dateTime, 0, 4)
1080
+ : null;
1081
+ }
1082
+
1083
+ private makeArrivalTimeWindow(
1084
+ dateTime: moment.Moment,
1085
+ window: TimeWindow,
1086
+ isFlightsGrouped: boolean
1087
+ ): string {
1088
+ if (window !== TimeWindow.Arrive) return null;
1089
+ return isFlightsGrouped
1090
+ ? this.helpers.makeTimeWindow(dateTime, -2, 2)
1091
+ : this.helpers.makeTimeWindow(dateTime, 0, 4);
1092
+ }
1093
+
1094
+ convertRecentSearchDateTime(
1095
+ date: string,
1096
+ timeWindow?: string
1097
+ ): moment.Moment {
1098
+ if (timeWindow) {
1099
+ const flightTime = timeWindow.split('-');
1100
+ let timeAndDate = moment(date).add(
1101
+ moment.duration(this.helpers.hhmmToTime(flightTime[0]))
1102
+ );
1103
+ // add 2 hour
1104
+ return timeAndDate.clone().add(2, 'hour');
1105
+ } else {
1106
+ return moment(date);
1107
+ }
1108
+ }
1109
+
1110
+ getSearchQuery(): SearchFlightsV2QueryVariables {
1111
+ const isMultiCityActive =
1112
+ this.tempParams.chosenSearchType === FlightSearchType.multiCity;
1113
+ this._multiDestination = isMultiCityActive
1114
+ ? this.setMultiDestinationQuery(this.tempParams.multiDestination)
1115
+ : null;
1116
+
1117
+ this._multiDestination =
1118
+ this.tempParams.chosenSearchType === FlightSearchType.multiCity
1119
+ ? this.setMultiDestinationQuery(this.tempParams.multiDestination)
1120
+ : [];
1121
+ const isFlightsGrouped = this.searchService.isFlightsGrouped();
1122
+ return this.helpers.removeNulls<SearchFlightsV2QueryVariables>(
1123
+ Object.assign(
1124
+ {},
1125
+ isMultiCityActive
1126
+ ? {
1127
+ multiDestination: this._multiDestination
1128
+ }
1129
+ : {
1130
+ originAirport: this._originAirport,
1131
+ destinationAirport: this._destinationAirport,
1132
+ outboundDate: this.helpers.formatIsoDate(
1133
+ this.tempParams.outBoundDate
1134
+ ),
1135
+ outboundDepartureTimeWindow: this.makeDepartureTimeWindow(
1136
+ this.tempParams.outBoundDate,
1137
+ this.tempParams.outTimeCriteria,
1138
+ isFlightsGrouped
1139
+ ),
1140
+ outboundArrivalTimeWindow: this.makeArrivalTimeWindow(
1141
+ this.tempParams.outBoundDate,
1142
+ this.tempParams.outTimeCriteria,
1143
+ isFlightsGrouped
1144
+ )
1145
+ },
1146
+ {
1147
+ passengers: this._passengers,
1148
+ returnTrip: this.isReturn,
1149
+ outboundCabinClass: this.tempParams.cabinClass
1150
+ ? [this.tempParams.cabinClass]
1151
+ : null,
1152
+ requireFreeBag: null,
1153
+ maxConnections: this.tempParams.maxConnections,
1154
+ includeNearbyAirports: this.tempParams.includeNearbyAirports,
1155
+ preferredCarriers: this.tempParams.preferredCarriers.map(
1156
+ (carrier: OBTAirlinesDetails) =>
1157
+ carrier?.code ? carrier.code : null
1158
+ ),
1159
+ fareType: this.tempParams.fareType,
1160
+ withGrouped: isFlightsGrouped
1161
+ },
1162
+ this.isReturn
1163
+ ? {
1164
+ returnDate: this.helpers.formatIsoDate(
1165
+ this.tempParams.inboundDate
1166
+ ),
1167
+ returnDepartureTimeWindow: this.makeDepartureTimeWindow(
1168
+ this.tempParams.inboundDate,
1169
+ this.tempParams.inTimeCriteria,
1170
+ isFlightsGrouped
1171
+ ),
1172
+ returnArrivalTimeWindow: this.makeArrivalTimeWindow(
1173
+ this.tempParams.inboundDate,
1174
+ this.tempParams.inTimeCriteria,
1175
+ isFlightsGrouped
1176
+ ),
1177
+ returnCabinClass: this.tempParams.returnCabinClass
1178
+ ? [this.tempParams.returnCabinClass]
1179
+ : null
1180
+ }
1181
+ : {}
1182
+ )
1183
+ );
1184
+ }
1185
+
1186
+ private updateTravellers() {
1187
+ const travellers: FlightPassengerObject[] = [];
1188
+ for (let loop = 0; loop < this.tempParams.adults; loop += 1) {
1189
+ travellers.push({ type: FlightPassengerType.Adult });
1190
+ }
1191
+ for (let loop = 0; loop < this.tempParams.children; loop += 1) {
1192
+ travellers.push({ type: FlightPassengerType.Child });
1193
+ }
1194
+
1195
+ this._passengers = travellers;
1196
+ this._isValid();
1197
+ }
1198
+
1199
+ private updateAvaliableClasses() {
1200
+ this.avaliableClasses.next([
1201
+ { name: 'Any', type: FlightCabinClass.Any },
1202
+ { name: 'Economy', type: FlightCabinClass.Economy },
1203
+ { name: 'Premium', type: FlightCabinClass.PremiumEconomy },
1204
+ { name: 'Business', type: FlightCabinClass.Business },
1205
+ { name: 'First', type: FlightCabinClass.First }
1206
+ ]);
1207
+ }
1208
+
1209
+ /**
1210
+ * @description - sort the flight results
1211
+ * @todo - Fill out Preferred and Co2 sorting when we have that data
1212
+ */
1213
+ public sortResults(
1214
+ sortMethodValue: SortTypes,
1215
+ givenResults?: FlightItinerary[]
1216
+ ): FlightItinerary[] {
1217
+ let results = this.helpers.clone(
1218
+ givenResults
1219
+ ? givenResults
1220
+ : <FlightItinerary[]>(<unknown>this.fullResults)
1221
+ );
1222
+
1223
+ switch (sortMethodValue) {
1224
+ case SortTypes.CheapestFirst:
1225
+ results = results.sort((a: FlightItinerary, b: FlightItinerary) => {
1226
+ return a.total.price - b.total.price;
1227
+ });
1228
+ break;
1229
+ case SortTypes.MostExpensiveFirst:
1230
+ results = results.sort((a: FlightItinerary, b: FlightItinerary) => {
1231
+ return b.total.price - a.total.price;
1232
+ });
1233
+ break;
1234
+ case SortTypes.FastestFirst:
1235
+ results = results.sort((a: FlightItinerary, b: FlightItinerary) => {
1236
+ return (
1237
+ a.outboundTotalDuration +
1238
+ (a.inboundTotalDuration ? a.inboundTotalDuration : 0) -
1239
+ (b.outboundTotalDuration +
1240
+ (b.inboundTotalDuration ? b.inboundTotalDuration : 0))
1241
+ );
1242
+ });
1243
+ break;
1244
+ case SortTypes.LowestEmissions:
1245
+ results = results.sort((a: FlightItinerary, b: FlightItinerary) => {
1246
+ return a.co2PerItem - b.co2PerItem;
1247
+ });
1248
+ break;
1249
+ default:
1250
+ console.error(`+++ Unknown sorting method: ${sortMethodValue} +++`);
1251
+ }
1252
+
1253
+ return results;
1254
+ }
1255
+
1256
+ updateFromPreviousSearches(
1257
+ previousItems: Record<ServiceType, BasketItem>
1258
+ ): void {
1259
+ // Flights can not be search after other products so no defaults can be set.
1260
+ }
1261
+
1262
+ getTotalBaggage(result: FlightItinerary): number {
1263
+ let total = 0;
1264
+
1265
+ const parsedAdditional = JSON.parse(result.additional);
1266
+ if (parsedAdditional && parsedAdditional.outboundFlights) {
1267
+ parsedAdditional.outboundFlights.forEach((flight: any) => {
1268
+ flight.baggage.forEach((bag: any) => {
1269
+ if (bag.allowance && bag.allowance > total) {
1270
+ total = bag.allowance;
1271
+ }
1272
+ });
1273
+ });
1274
+ } else if (parsedAdditional && parsedAdditional.baggageAllowance) {
1275
+ parsedAdditional.baggageAllowance.forEach((baggageAllow: any) => {
1276
+ if (
1277
+ baggageAllow.baggage.qty &&
1278
+ Number(baggageAllow.baggage.qty) > total
1279
+ ) {
1280
+ total = Number(baggageAllow.baggage.qty);
1281
+ }
1282
+ });
1283
+ }
1284
+
1285
+ return total;
1286
+ }
1287
+
1288
+ /**
1289
+ * @description - filter the results, then sort the remainder
1290
+ * @todo - Add filters for travel policy, fare types and ancilliaries
1291
+ */
1292
+ filterResults(
1293
+ filters: FlightFilters,
1294
+ sortValue: SortTypes,
1295
+ givenResults?: FlightItinerary[]
1296
+ ): FlightItinerary[] {
1297
+ console.log('+++ Applying Filters to flights: ', filters, ' +++');
1298
+ let results: FlightItinerary[] = this.helpers.clone(givenResults);
1299
+
1300
+ if (this.isReturn) {
1301
+ results = results.filter(
1302
+ (result: FlightItinerary) =>
1303
+ result.inboundFlights && result.inboundFlights.length
1304
+ );
1305
+ }
1306
+
1307
+ // Add In Filters Here
1308
+ // filter stops
1309
+ results = this.filterResultsByStops(filters.stops, results);
1310
+ results = this.filterResultsByAirline(filters.airlines, results);
1311
+ results = this.filterResultsByClass(filters.classes, results);
1312
+ results = this.filterByDepartureAirport(filters.depatureAirport, results);
1313
+ results = this.filterByDepartureReturnAirport(
1314
+ filters.depatureReturnAirport,
1315
+ results
1316
+ );
1317
+ results = this.filterByArrivalAirport(filters.arrivalAirport, results);
1318
+ results = this.filterByArrivalReturnAirport(
1319
+ filters.arrivalReturnAirport,
1320
+ results
1321
+ );
1322
+ results = this.filterByPrice(filters.minPrice, filters.maxPrice, results);
1323
+ results = this.filterByFlightNumber(filters.flightNumber, results);
1324
+ results = this.filterByBaggage(filters.baggage, results);
1325
+ results = this.filterByDepartureTime(
1326
+ filters.minDepartureTime,
1327
+ filters.maxDepartureTime,
1328
+ results
1329
+ );
1330
+ results = this.filterByReturnDepartureTime(
1331
+ filters.minReturnDepartureTime,
1332
+ filters.maxReturnDepartureTime,
1333
+ results
1334
+ );
1335
+ results = this.filterByArrivalTime(
1336
+ filters.minArrivalTime,
1337
+ filters.maxArrivalTime,
1338
+ results
1339
+ );
1340
+ results = this.filterByReturnArrivalTime(
1341
+ filters.minReturnArrivalTime,
1342
+ filters.maxReturnArrivalTime,
1343
+ results
1344
+ );
1345
+ results = this.filterByDuration(
1346
+ filters.minDuration,
1347
+ filters.maxDuration,
1348
+ results
1349
+ );
1350
+ results = this.filterByDuration(
1351
+ filters.minReturnDuration,
1352
+ filters.maxReturnDuration,
1353
+ results,
1354
+ true
1355
+ ); // return duration
1356
+
1357
+ results = this.sortResults(sortValue, results);
1358
+ return results;
1359
+ }
1360
+
1361
+ /**
1362
+ * @description - give the correct format for transfering minuetes on the sliders
1363
+ * @param min - the min in 100th's to transform onto 60th's
1364
+ */
1365
+ transformMin(min: number): string {
1366
+ let num = (Number(min) * 60) / 100;
1367
+ // console.log('+++ Num Copy: ', _.clone(num), ' +++');
1368
+ if (num % 1 < 0.5) {
1369
+ num = Math.floor(num);
1370
+ } else {
1371
+ num = Math.ceil(num);
1372
+ }
1373
+
1374
+ return num.toString().padStart(2, '0');
1375
+ }
1376
+
1377
+ filterByDuration(
1378
+ minDuration: number,
1379
+ maxDuration: number,
1380
+ results: FlightItinerary[],
1381
+ isReturn = false
1382
+ ): FlightItinerary[] {
1383
+ results = results.filter((result) => {
1384
+ let dur = 0;
1385
+ if (!isReturn) {
1386
+ result.outboundFlights.forEach((out: FlightJourney) => {
1387
+ dur += out.totalDuration;
1388
+ });
1389
+ }
1390
+
1391
+ if (result.inboundFlights?.length && isReturn) {
1392
+ result.inboundFlights.forEach((inb: FlightJourney) => {
1393
+ dur += inb.totalDuration;
1394
+ });
1395
+ }
1396
+
1397
+ return dur >= minDuration && dur <= maxDuration;
1398
+ });
1399
+
1400
+ return results;
1401
+ }
1402
+
1403
+ filterByDepartureTime(
1404
+ minDep: number,
1405
+ maxDep: number,
1406
+ results: FlightItinerary[]
1407
+ ): FlightItinerary[] {
1408
+ results = results.filter((result) => {
1409
+ const departureTime = Number(
1410
+ moment(result.outboundFlights[0].dateTimeDeparting).format('HHmm')
1411
+ );
1412
+ const newNumString1 = Number(
1413
+ Math.floor(Number(minDep / 100)).toString() +
1414
+ this.transformMin(Math.ceil(Number(minDep % 100)))
1415
+ );
1416
+ const newNumString2 = Number(
1417
+ Math.floor(Number(maxDep / 100)).toString() +
1418
+ this.transformMin(Math.ceil(Number(maxDep % 100)))
1419
+ );
1420
+
1421
+ return departureTime >= newNumString1 && departureTime <= newNumString2;
1422
+ });
1423
+
1424
+ return results;
1425
+ }
1426
+
1427
+ filterByReturnDepartureTime(
1428
+ minDep: number,
1429
+ maxDep: number,
1430
+ results: FlightItinerary[]
1431
+ ): FlightItinerary[] {
1432
+ if (!minDep && !maxDep) {
1433
+ return results;
1434
+ }
1435
+
1436
+ const newNumString1 = Number(
1437
+ Math.floor(Number(minDep / 100)).toString() +
1438
+ this.transformMin(Math.ceil(Number(minDep % 100)))
1439
+ );
1440
+ const newNumString2 = Number(
1441
+ Math.floor(Number(maxDep / 100)).toString() +
1442
+ this.transformMin(Math.ceil(Number(maxDep % 100)))
1443
+ );
1444
+
1445
+ results = results.filter((result) => {
1446
+ if (!result.inboundFlights || !result.inboundFlights[0]) {
1447
+ return true;
1448
+ }
1449
+
1450
+ const departureTime = Number(
1451
+ moment(result.inboundFlights[0].dateTimeDeparting).format('HHmm')
1452
+ );
1453
+ return departureTime >= newNumString1 && departureTime <= newNumString2;
1454
+ });
1455
+
1456
+ return results;
1457
+ }
1458
+
1459
+ filterByReturnArrivalTime(
1460
+ minArr: number,
1461
+ maxArr: number,
1462
+ results: FlightItinerary[]
1463
+ ): FlightItinerary[] {
1464
+ if (!minArr && !maxArr) {
1465
+ return results;
1466
+ }
1467
+
1468
+ const newNumString1 = Number(
1469
+ Math.floor(Number(minArr / 100)).toString() +
1470
+ this.transformMin(Math.ceil(Number(minArr % 100)))
1471
+ );
1472
+ const newNumString2 = Number(
1473
+ Math.floor(Number(maxArr / 100)).toString() +
1474
+ this.transformMin(Math.ceil(Number(maxArr % 100)))
1475
+ );
1476
+
1477
+ results = results.filter((result) => {
1478
+ if (!result.inboundFlights || !result.inboundFlights[0]) {
1479
+ return true;
1480
+ }
1481
+
1482
+ const arrivalTime = Number(
1483
+ moment(
1484
+ result.inboundFlights[result.inboundFlights.length - 1]
1485
+ .dateTimeArriving
1486
+ ).format('HHmm')
1487
+ );
1488
+ const retVal =
1489
+ arrivalTime >= newNumString1 && arrivalTime <= newNumString2;
1490
+
1491
+ // for debugging
1492
+ // if (!retVal) {
1493
+ // console.warn(`+++ Filtering Out: ${arrivalTime} +++`);
1494
+ // }
1495
+
1496
+ return retVal;
1497
+ });
1498
+
1499
+ return results;
1500
+ }
1501
+
1502
+ filterByArrivalTime(
1503
+ minArr: number,
1504
+ maxArr: number,
1505
+ results: FlightItinerary[]
1506
+ ): FlightItinerary[] {
1507
+ const newNumString1 = Number(
1508
+ Math.floor(Number(minArr / 100)).toString() +
1509
+ this.transformMin(Math.ceil(Number(minArr % 100)))
1510
+ );
1511
+ const newNumString2 = Number(
1512
+ Math.floor(Number(maxArr / 100)).toString() +
1513
+ this.transformMin(Math.ceil(Number(maxArr % 100)))
1514
+ );
1515
+
1516
+ results = results.filter((result) => {
1517
+ const arrivalTime = Number(
1518
+ moment(
1519
+ result.outboundFlights[result.outboundFlights.length - 1]
1520
+ .dateTimeArriving
1521
+ ).format('HHmm')
1522
+ );
1523
+
1524
+ return arrivalTime >= newNumString1 && arrivalTime <= newNumString2;
1525
+ });
1526
+
1527
+ return results;
1528
+ }
1529
+
1530
+ filterByBaggage(
1531
+ baggageFilters: SelectFilter[],
1532
+ results: FlightItinerary[]
1533
+ ): FlightItinerary[] {
1534
+ const selected = baggageFilters.filter((x) => x.selected);
1535
+
1536
+ if (selected?.length >= 1 && selected.length !== baggageFilters.length) {
1537
+ results = results.filter((result) => {
1538
+ try {
1539
+ const totalBags = this.getTotalBaggage(result);
1540
+
1541
+ return selected.find((x) => x.value === totalBags);
1542
+ } catch (error) {
1543
+ console.error('+++ Error determening baggage: ${error} +++');
1544
+ return false;
1545
+ }
1546
+ });
1547
+ }
1548
+
1549
+ return results;
1550
+ }
1551
+
1552
+ filterByPrice(
1553
+ minPrice: number,
1554
+ maxPrice: number,
1555
+ results: FlightItinerary[]
1556
+ ): FlightItinerary[] {
1557
+ results = results.filter((result) => {
1558
+ // console.log(`+++ Price: ${result.total.price} is between: ${minPrice} and ${maxPrice}: ${result.total.price >= minPrice && result.total.price <= maxPrice} +++`)
1559
+
1560
+ return result.total.price >= minPrice && result.total.price <= maxPrice;
1561
+ });
1562
+
1563
+ return results;
1564
+ }
1565
+
1566
+ /**
1567
+ * @description - filter the results by the number of stops
1568
+ * @param stopFilters - the selected stops
1569
+ * @param fullResults - all of our results so far
1570
+ */
1571
+ filterResultsByStops(
1572
+ stopFilters: SelectFilter[],
1573
+ fullResults: FlightItinerary[]
1574
+ ): FlightItinerary[] {
1575
+ const selected = stopFilters.filter((x) => x.selected);
1576
+
1577
+ if (selected?.length >= 1 && selected.length !== stopFilters.length) {
1578
+ fullResults = fullResults.filter((result) => {
1579
+ const totalStops = result.outboundFlights.length - 1;
1580
+
1581
+ const haveStop = selected.find(
1582
+ (selected1: SelectFilter) => selected1.value === totalStops
1583
+ );
1584
+
1585
+ return haveStop;
1586
+ });
1587
+ }
1588
+
1589
+ return fullResults;
1590
+ }
1591
+
1592
+ filterResultsByAirline(
1593
+ airlineFilters: SelectFilter[],
1594
+ results: FlightItinerary[]
1595
+ ): FlightItinerary[] {
1596
+ const selected = airlineFilters.filter((x) => x.selected);
1597
+
1598
+ if (selected?.length >= 1 && selected.length !== airlineFilters.length) {
1599
+ results = results.filter((result) => {
1600
+ return selected.find(
1601
+ (x) => x.value === result.outboundFlights[0].operatingCarrier
1602
+ );
1603
+ });
1604
+ }
1605
+
1606
+ return results;
1607
+ }
1608
+
1609
+ filterResultsByClass(
1610
+ classFilters: SelectFilter[],
1611
+ results: FlightItinerary[]
1612
+ ): FlightItinerary[] {
1613
+ const selected = classFilters.filter((x) => x.selected);
1614
+
1615
+ if (selected?.length >= 1 && selected.length !== classFilters.length) {
1616
+ results = results.filter((result) => {
1617
+ return selected.find(
1618
+ (x) => x.value === result.outboundFlights[0].cabinClass
1619
+ );
1620
+ });
1621
+ }
1622
+
1623
+ return results;
1624
+ }
1625
+
1626
+ filterByDepartureAirport(
1627
+ departureAirports: SelectFilter[],
1628
+ results: FlightItinerary[]
1629
+ ): FlightItinerary[] {
1630
+ const selected = departureAirports.filter((x) => x.selected);
1631
+
1632
+ if (selected?.length >= 1 && selected.length !== departureAirports.length) {
1633
+ results = results.filter((result) => {
1634
+ return selected.find(
1635
+ (x) => x.value === result.outboundFlights[0].originAirport
1636
+ );
1637
+ });
1638
+ }
1639
+
1640
+ return results;
1641
+ }
1642
+
1643
+ filterByArrivalAirport(
1644
+ arrivalAirports: SelectFilter[],
1645
+ results: FlightItinerary[]
1646
+ ): FlightItinerary[] {
1647
+ const selected = arrivalAirports.filter((x) => x.selected);
1648
+
1649
+ if (selected?.length >= 1 && selected.length !== arrivalAirports.length) {
1650
+ results = results.filter((result) => {
1651
+ const destinationAirport =
1652
+ result.outboundFlights[result.outboundFlights.length - 1]
1653
+ .destinationAirport;
1654
+ return selected.find((x) => x.value === destinationAirport);
1655
+ });
1656
+ }
1657
+
1658
+ return results;
1659
+ }
1660
+
1661
+ filterByDepartureReturnAirport(
1662
+ departureAirports: SelectFilter[],
1663
+ results: FlightItinerary[]
1664
+ ): FlightItinerary[] {
1665
+ const selected = departureAirports.filter((x) => x.selected);
1666
+
1667
+ if (selected?.length >= 1 && selected.length !== departureAirports.length) {
1668
+ results = results.filter((result) => {
1669
+ if (!result.inboundFlights?.length) {
1670
+ return true;
1671
+ }
1672
+
1673
+ return selected.find(
1674
+ (x) => x.value === result.inboundFlights[0].originAirport
1675
+ );
1676
+ });
1677
+ }
1678
+
1679
+ return results;
1680
+ }
1681
+
1682
+ filterByArrivalReturnAirport(
1683
+ arrivalAirports: SelectFilter[],
1684
+ results: FlightItinerary[]
1685
+ ): FlightItinerary[] {
1686
+ const selected = arrivalAirports.filter((x) => x.selected);
1687
+
1688
+ if (selected?.length >= 1 && selected.length !== arrivalAirports.length) {
1689
+ results = results.filter((result) => {
1690
+ if (!result.inboundFlights?.length) {
1691
+ return true;
1692
+ }
1693
+
1694
+ const destinationAirport =
1695
+ result.inboundFlights[result.inboundFlights.length - 1]
1696
+ .destinationAirport;
1697
+ return selected.find((x) => x.value === destinationAirport);
1698
+ });
1699
+ }
1700
+
1701
+ return results;
1702
+ }
1703
+
1704
+ filterByFlightNumber(
1705
+ flightNumber: string,
1706
+ results: FlightItinerary[]
1707
+ ): FlightItinerary[] {
1708
+ if (flightNumber) {
1709
+ // make sure to check both outbound and inbound
1710
+
1711
+ results = results.filter((result: FlightItinerary) => {
1712
+ const inOutbound = result.outboundFlights.find((out: FlightJourney) => {
1713
+ return out.operatingFlightNumber
1714
+ .toUpperCase()
1715
+ .includes(flightNumber.toUpperCase());
1716
+ });
1717
+
1718
+ let inInbound;
1719
+
1720
+ if (result.inboundFlights?.length) {
1721
+ inInbound = result.inboundFlights.find((inB: FlightJourney) => {
1722
+ return inB.operatingFlightNumber
1723
+ .toUpperCase()
1724
+ .includes(flightNumber.toUpperCase());
1725
+ });
1726
+ }
1727
+
1728
+ return inOutbound || inInbound;
1729
+ });
1730
+ }
1731
+
1732
+ return results;
1733
+ }
1734
+
1735
+ createFilters(results: FlightItinerary[] = []): FlightFilters {
1736
+ const minPrice = this.getMinPrice(results);
1737
+ const maxPrice = this.getMaxPrice(results);
1738
+
1739
+ const newFilters: FlightFilters = {
1740
+ stops: this.getAllStops(results),
1741
+ mustInclude: [],
1742
+ classes: this.getAllClasses(results),
1743
+ airlines: this.getAllAirlines(results),
1744
+ travelPolicy: [],
1745
+ depatureAirport: this.getAllDepartureAirports(results),
1746
+ arrivalAirport: this.getAllArrivalAirports(results),
1747
+ minPrice,
1748
+ maxPrice,
1749
+ depatureReturnAirport: this.getAllDepartureAirports(results, true),
1750
+ arrivalReturnAirport: this.getAllArrivalAirports(results, true),
1751
+ baggage: this.getBaggage(results),
1752
+ fareTypes: [],
1753
+ minDuration: this.getMinDuration(results),
1754
+ maxDuration: this.getMaxDuration(results),
1755
+ minReturnDuration: this.getMinDuration(results, true),
1756
+ maxReturnDuration: this.getMaxDuration(results, true),
1757
+ minDepartureTime: this.getMinDepartureTime(results),
1758
+ maxDepartureTime: this.getMaxDepartureTime(results),
1759
+ minArrivalTime: this.getMinArrivalTime(results),
1760
+ maxArrivalTime: this.getMaxArrivalTime(results),
1761
+ minReturnDepartureTime: this.getMinReturnDepartureTime(results),
1762
+ maxReturnDepartureTime: this.getMaxReturnDepartureTime(results),
1763
+ maxReturnArrivalTime: this.getMaxReturnArrivalTime(results),
1764
+ minReturnArrivalTime: this.getMinReturnArrivalTime(results),
1765
+ flightNumber: ''
1766
+ };
1767
+
1768
+ return newFilters;
1769
+ }
1770
+
1771
+ getMinDuration(results: FlightItinerary[], isReturn = false): number {
1772
+ let min = 0;
1773
+
1774
+ results.forEach((result) => {
1775
+ let dur = 0;
1776
+
1777
+ if (!isReturn) {
1778
+ result.outboundFlights.forEach((out: FlightJourney) => {
1779
+ dur += out.totalDuration;
1780
+ });
1781
+ }
1782
+
1783
+ if (result.inboundFlights?.length && isReturn) {
1784
+ result.inboundFlights.forEach((inb: FlightJourney) => {
1785
+ dur += inb.totalDuration;
1786
+ });
1787
+ }
1788
+
1789
+ if (!min || dur < min) {
1790
+ min = dur;
1791
+ }
1792
+ });
1793
+
1794
+ return min;
1795
+ }
1796
+
1797
+ getMaxDuration(results: FlightItinerary[], isReturn = false): number {
1798
+ let max = 0;
1799
+
1800
+ results.forEach((result) => {
1801
+ let dur = 0;
1802
+ if (!isReturn) {
1803
+ result.outboundFlights.forEach((out: FlightJourney) => {
1804
+ dur += out.totalDuration;
1805
+ });
1806
+ }
1807
+
1808
+ if (result.inboundFlights?.length && isReturn) {
1809
+ result.inboundFlights.forEach((inb: FlightJourney) => {
1810
+ dur += inb.totalDuration;
1811
+ });
1812
+ }
1813
+
1814
+ if (!max || dur > max) {
1815
+ max = dur;
1816
+ }
1817
+ });
1818
+
1819
+ return max;
1820
+ }
1821
+
1822
+ getMinArrivalTime(results: FlightItinerary[]): number {
1823
+ let min: number;
1824
+
1825
+ results.forEach((result) => {
1826
+ let minDepTime = Number(
1827
+ moment(
1828
+ result.outboundFlights[result.outboundFlights.length - 1]
1829
+ .dateTimeArriving
1830
+ ).format('HHmm')
1831
+ );
1832
+ minDepTime = Math.floor(minDepTime / 100) * 100;
1833
+ if (!min || minDepTime < min) {
1834
+ min = minDepTime;
1835
+ }
1836
+ });
1837
+
1838
+ return min;
1839
+ }
1840
+
1841
+ getMinReturnArrivalTime(results: FlightItinerary[]): number {
1842
+ let min: number;
1843
+
1844
+ results.forEach((result) => {
1845
+ if (result.inboundFlights && result.inboundFlights.length) {
1846
+ let minDepTime = Number(
1847
+ moment(
1848
+ result.inboundFlights[result.inboundFlights.length - 1]
1849
+ .dateTimeArriving
1850
+ ).format('HHmm')
1851
+ );
1852
+ minDepTime = Math.floor(minDepTime / 100) * 100;
1853
+ if (!min || minDepTime < min) {
1854
+ min = minDepTime;
1855
+ }
1856
+ }
1857
+ });
1858
+
1859
+ return min;
1860
+ }
1861
+
1862
+ getMaxReturnArrivalTime(results: FlightItinerary[]): number {
1863
+ let max: number;
1864
+
1865
+ results.forEach((result) => {
1866
+ if (result.inboundFlights && result.inboundFlights.length) {
1867
+ let maxDepTime = Number(
1868
+ moment(
1869
+ result.inboundFlights[result.inboundFlights.length - 1]
1870
+ .dateTimeArriving
1871
+ ).format('HHmm')
1872
+ );
1873
+ maxDepTime = Math.ceil(maxDepTime / 100) * 100;
1874
+ if (!max || maxDepTime > max) {
1875
+ max = maxDepTime;
1876
+ }
1877
+ }
1878
+ });
1879
+
1880
+ return max;
1881
+ }
1882
+
1883
+ getMaxArrivalTime(results: FlightItinerary[]): number {
1884
+ let max: number;
1885
+
1886
+ results.forEach((result) => {
1887
+ let maxDepTime = Number(
1888
+ moment(
1889
+ result.outboundFlights[result.outboundFlights.length - 1]
1890
+ .dateTimeArriving
1891
+ ).format('HHmm')
1892
+ );
1893
+
1894
+ maxDepTime = Math.ceil(maxDepTime / 100) * 100;
1895
+ if (!max || maxDepTime > max) {
1896
+ max = maxDepTime;
1897
+ }
1898
+ });
1899
+ return max;
1900
+ }
1901
+
1902
+ getMinDepartureTime(results: FlightItinerary[]): number {
1903
+ let min: number;
1904
+
1905
+ results.forEach((result) => {
1906
+ let minDepTime = Number(
1907
+ moment(result.outboundFlights[0].dateTimeDeparting).format('HHmm')
1908
+ );
1909
+ minDepTime = Math.floor(minDepTime / 100) * 100;
1910
+ if (!min || minDepTime < min) {
1911
+ min = minDepTime;
1912
+ }
1913
+ });
1914
+
1915
+ return min;
1916
+ }
1917
+
1918
+ getMinReturnDepartureTime(results: FlightItinerary[]): number {
1919
+ let min: number;
1920
+
1921
+ results.forEach((result) => {
1922
+ if (result.inboundFlights && result.inboundFlights[0]) {
1923
+ let minDepTime = Number(
1924
+ moment(result.inboundFlights[0].dateTimeDeparting).format('HHmm')
1925
+ );
1926
+ minDepTime = Math.floor(minDepTime / 100) * 100;
1927
+ if (!min || minDepTime < min) {
1928
+ min = minDepTime;
1929
+ }
1930
+ }
1931
+ });
1932
+
1933
+ return min;
1934
+ }
1935
+
1936
+ getMaxReturnDepartureTime(results: FlightItinerary[]): number {
1937
+ let max: number;
1938
+
1939
+ results.forEach((result) => {
1940
+ if (result.inboundFlights && result.inboundFlights[0]) {
1941
+ let maxDepTime = Number(
1942
+ moment(result.inboundFlights[0].dateTimeDeparting).format('HHmm')
1943
+ );
1944
+
1945
+ maxDepTime = Math.ceil(maxDepTime / 100) * 100;
1946
+
1947
+ if (!max || maxDepTime > max) {
1948
+ max = maxDepTime;
1949
+ }
1950
+ }
1951
+ });
1952
+
1953
+ return max;
1954
+ }
1955
+
1956
+ getMaxDepartureTime(results: FlightItinerary[]): number {
1957
+ let max: number;
1958
+
1959
+ results.forEach((result) => {
1960
+ let maxDepTime = Number(
1961
+ moment(result.outboundFlights[0].dateTimeDeparting).format('HHmm')
1962
+ );
1963
+
1964
+ maxDepTime = Math.ceil(maxDepTime / 100) * 100;
1965
+
1966
+ if (!max || maxDepTime > max) {
1967
+ max = maxDepTime;
1968
+ }
1969
+ });
1970
+
1971
+ return max;
1972
+ }
1973
+
1974
+ getBaggage(results: FlightItinerary[]): SelectFilter[] {
1975
+ const baggage: any = {};
1976
+
1977
+ results.forEach((result) => {
1978
+ try {
1979
+ if (result.baggageAllowance.length) {
1980
+ let total = +result.baggageAllowance[0]?.qty;
1981
+ if (result.inboundFlights.length) {
1982
+ // ! assuming second item is inbound if the airlines are different, steven said he would sort this out
1983
+ if (
1984
+ result.baggageAllowance[1] &&
1985
+ +result.baggageAllowance[1].qty > total
1986
+ ) {
1987
+ total = +result.baggageAllowance[1]?.qty;
1988
+ } else if (+result.baggageAllowance[0]?.qty > total) {
1989
+ total = +result.baggageAllowance[0]?.qty;
1990
+ }
1991
+ }
1992
+ if (+result.baggageAllowance[0]?.qty > total) {
1993
+ total = +result.baggageAllowance[0]?.qty;
1994
+ }
1995
+ baggage[total] = {
1996
+ selected: false,
1997
+ value: total,
1998
+ display: `${total} bag${total !== 1 ? 's' : ''}`
1999
+ };
2000
+ }
2001
+ } catch (error) {
2002
+ console.error(`+++ Error parsing additional flight data: ${error} +++`);
2003
+ }
2004
+ });
2005
+
2006
+ return Object.values(baggage);
2007
+ }
2008
+
2009
+ getMinPrice(results: FlightItinerary[]): number {
2010
+ let minPrice: number;
2011
+
2012
+ results.forEach((result) => {
2013
+ if (!minPrice || result.total.price < minPrice) {
2014
+ minPrice = result.total.price;
2015
+ }
2016
+ });
2017
+
2018
+ return minPrice;
2019
+ }
2020
+
2021
+ getMaxPrice(results: FlightItinerary[]): number {
2022
+ let maxPrice: any;
2023
+
2024
+ results.forEach((result) => {
2025
+ if (!maxPrice || result.total.price > maxPrice) {
2026
+ maxPrice = result.total.price;
2027
+ }
2028
+ });
2029
+
2030
+ return maxPrice;
2031
+ }
2032
+
2033
+ getAllStops(results: FlightItinerary[]): SelectFilter[] {
2034
+ const allStops: any = {};
2035
+
2036
+ results.forEach((result) => {
2037
+ const totalStops = result.outboundFlights.length - 1; // might have to recalculate this
2038
+ allStops[totalStops] = {
2039
+ value: totalStops,
2040
+ display: `${totalStops} stop` + (totalStops !== 1 ? 's' : ''),
2041
+ selected: false
2042
+ };
2043
+ });
2044
+
2045
+ return Object.values(allStops);
2046
+ }
2047
+
2048
+ getAllClasses(results: FlightItinerary[]): SelectFilter[] {
2049
+ const allClasses: any = [];
2050
+
2051
+ results.forEach((result) => {
2052
+ result.outboundFlights.forEach((outFlight: FlightJourney) => {
2053
+ allClasses[outFlight.cabinClass] = {
2054
+ value: outFlight.cabinClass,
2055
+ display: outFlight.cabinClass,
2056
+ selected: false
2057
+ } as SelectFilter;
2058
+ });
2059
+
2060
+ if (result.inboundFlights) {
2061
+ result.inboundFlights.forEach((inFlight: FlightJourney) => {
2062
+ allClasses[inFlight.cabinClass] = {
2063
+ value: inFlight.cabinClass,
2064
+ display: inFlight.cabinClass,
2065
+ selected: false
2066
+ } as SelectFilter;
2067
+ });
2068
+ }
2069
+ });
2070
+
2071
+ return Object.values(allClasses);
2072
+ }
2073
+
2074
+ /**
2075
+ * @description - create select filters for all unique departure airports returned in the search
2076
+ * @param results - the flight results
2077
+ */
2078
+ getAllDepartureAirports(
2079
+ results: FlightItinerary[],
2080
+ inbound = false
2081
+ ): SelectFilter[] {
2082
+ const allAirports: any = {};
2083
+
2084
+ results.forEach((result) => {
2085
+ if (result.outboundFlights.length && !inbound) {
2086
+ allAirports[result.outboundFlights[0].originAirport] = {
2087
+ value: result.outboundFlights[0].originAirport,
2088
+ display: result.outboundFlights[0].originAirportName,
2089
+ selected: false
2090
+ };
2091
+ }
2092
+
2093
+ if (result.inboundFlights?.length && inbound) {
2094
+ allAirports[result.inboundFlights[0].originAirport] = {
2095
+ value: result.inboundFlights[0].originAirport,
2096
+ display: result.inboundFlights[0].originAirportName,
2097
+ selected: false
2098
+ };
2099
+ }
2100
+ });
2101
+
2102
+ return Object.values(allAirports);
2103
+ }
2104
+
2105
+ /**
2106
+ * @description - create select filters for all unique departure airports returned in the search
2107
+ * @param results - the flight results
2108
+ */
2109
+ getAllArrivalAirports(
2110
+ results: FlightItinerary[],
2111
+ inbound = false
2112
+ ): SelectFilter[] {
2113
+ const allAirports: any = {};
2114
+
2115
+ results.forEach((result) => {
2116
+ if (result.outboundFlights.length && !inbound) {
2117
+ allAirports[
2118
+ result.outboundFlights[
2119
+ result.outboundFlights.length - 1
2120
+ ].destinationAirport
2121
+ ] = {
2122
+ value:
2123
+ result.outboundFlights[result.outboundFlights.length - 1]
2124
+ .destinationAirport,
2125
+ display:
2126
+ result.outboundFlights[result.outboundFlights.length - 1]
2127
+ .destinationAirportName,
2128
+ selected: false
2129
+ };
2130
+ }
2131
+
2132
+ if (result.inboundFlights?.length && inbound) {
2133
+ allAirports[
2134
+ result.inboundFlights[
2135
+ result.inboundFlights.length - 1
2136
+ ].destinationAirport
2137
+ ] = {
2138
+ value:
2139
+ result.inboundFlights[result.inboundFlights.length - 1]
2140
+ .destinationAirport,
2141
+ display:
2142
+ result.inboundFlights[result.inboundFlights.length - 1]
2143
+ .destinationAirportName,
2144
+ selected: false
2145
+ };
2146
+ }
2147
+ });
2148
+
2149
+ return Object.values(allAirports);
2150
+ }
2151
+
2152
+ /**
2153
+ * @description - create select filters for all unique airlines returned in the search
2154
+ * @param results - the flight results
2155
+ */
2156
+ getAllAirlines(results: FlightItinerary[]): SelectFilter[] {
2157
+ const allAirlines: any = {};
2158
+
2159
+ results.forEach((result: FlightItinerary) => {
2160
+ result.outboundFlights.forEach((outFlight: FlightJourney) => {
2161
+ allAirlines[outFlight.operatingCarrier] = {
2162
+ value: outFlight.operatingCarrier,
2163
+ display: outFlight.operatingCarrierName,
2164
+ selected: false
2165
+ } as SelectFilter;
2166
+ });
2167
+
2168
+ if (result.inboundFlights) {
2169
+ result.inboundFlights.forEach((inFlight: FlightJourney) => {
2170
+ allAirlines[inFlight.operatingCarrier] = {
2171
+ value: inFlight.operatingCarrier,
2172
+ display: inFlight.operatingCarrierName,
2173
+ selected: false
2174
+ } as SelectFilter;
2175
+ });
2176
+ }
2177
+ });
2178
+
2179
+ return Object.values(allAirlines);
2180
+ }
2181
+
2182
+ updateLowestPrice(results: FlightQuoteResultArray): ICheapestPrice {
2183
+ return null;
2184
+ // add in once filght result is updated///
2185
+ // const results = this.storageService.getSessionItemAsList<FlightQuoteResultArray>(this.resultsSessionName) || [] as FlightQuoteResultArray;
2186
+ // if(!results.length) return;
2187
+ // this._cheapestResultPrice.currencyCode = results[0].total.currency;
2188
+ // results.map(result => {
2189
+ // const price = result.total.price;
2190
+ // if( this._cheapestResultPrice.amount > price || this._cheapestResultPrice.amount === null){
2191
+ // this._cheapestResultPrice.amount = price;
2192
+ // }
2193
+ // })
2194
+ }
2195
+
2196
+ async selectGroupedFlight(
2197
+ selectedFlight: FlightItineraryWithSelected,
2198
+ direction: FlightDirectionEnum
2199
+ ) {
2200
+ const intBasket: InternalBasketInterface =
2201
+ await this.basketService.getDefaultBasket();
2202
+ const basket = intBasket?.subject.value;
2203
+
2204
+ if (
2205
+ basket &&
2206
+ this.originalUserSearch.chosenSearchType === FlightSearchType.oneWay &&
2207
+ direction === FlightDirectionEnum.Outbound
2208
+ ) {
2209
+ this.doBooking(
2210
+ intBasket,
2211
+ selectedFlight,
2212
+ {
2213
+ outboundFlights: selectedFlight.outboundFlights.map(
2214
+ (flight: FlightJourney, segmentIndex: number) =>
2215
+ this.makeSchemaFlights(flight, 'outbound', 0, segmentIndex)
2216
+ ),
2217
+ inboundFlights: [],
2218
+ journeyType: 'single'
2219
+ },
2220
+ selectedFlight.outboundFlights[0].dateTimeDeparting
2221
+ );
2222
+ return;
2223
+ }
2224
+ if (
2225
+ basket &&
2226
+ this.originalUserSearch.chosenSearchType === FlightSearchType.return &&
2227
+ direction === FlightDirectionEnum.Outbound
2228
+ ) {
2229
+ if (selectedFlight.selected) {
2230
+ this.results.next(this.fullResults);
2231
+ this.selectedGroupFlight = null;
2232
+ } else {
2233
+ this.selectedGroupFlight = selectedFlight;
2234
+ const groupsToShow = this.flightsToGroup[selectedFlight.uid];
2235
+ // const relatedFlights = this.grouped[groupsToShow[0]].flights;
2236
+ // const filter = (flight: FlightItinerary, segmentIndex: number) => {
2237
+ // return true;
2238
+ // };
2239
+ this.results.next(
2240
+ (this.fullResults as FlightGroupedQuoteResult[]).filter(
2241
+ (result: FlightGroupedQuoteResult, groupIndex: number) => {
2242
+ return groupsToShow.includes(groupIndex);
2243
+ }
2244
+ )
2245
+ );
2246
+ }
2247
+ selectedFlight.selected = !selectedFlight.selected;
2248
+ }
2249
+ if (
2250
+ basket &&
2251
+ this.originalUserSearch.chosenSearchType === FlightSearchType.return &&
2252
+ direction === FlightDirectionEnum.Inbound &&
2253
+ this.selectedGroupFlight
2254
+ ) {
2255
+ this.doBooking(
2256
+ intBasket,
2257
+ selectedFlight,
2258
+ {
2259
+ outboundFlights: [
2260
+ ...selectedFlight.outboundFlights.map(
2261
+ (flight: FlightJourney, segmentIndex: number) =>
2262
+ this.makeSchemaFlights(flight, 'outbound', 0, segmentIndex)
2263
+ )
2264
+ ],
2265
+ inboundFlights: [
2266
+ ...selectedFlight.inboundFlights.map(
2267
+ (flight: FlightJourney, segmentIndex: number) =>
2268
+ this.makeSchemaFlights(flight, 'inbound', 0, segmentIndex)
2269
+ )
2270
+ ],
2271
+ journeyType: 'roundtrip'
2272
+ },
2273
+ selectedFlight.outboundFlights[0].dateTimeDepartingUTC,
2274
+ selectedFlight.inboundFlights[0].dateTimeDepartingUTC
2275
+ );
2276
+ this.selectedGroupFlight.selected = false;
2277
+ this.results.next(this.fullResults);
2278
+ }
2279
+ }
2280
+
2281
+ doBooking(
2282
+ intBasket: InternalBasketInterface,
2283
+ selectedFlight: FlightItinerary,
2284
+ schemaDetails: any,
2285
+ outboundDate: string,
2286
+ inboundDate?: string
2287
+ ): void {
2288
+ const { sourceId, co2PerItem, co2PerPassenger, total } = selectedFlight;
2289
+ const booking: AddItemToBasketMutationVariables = {
2290
+ adults: this.adults,
2291
+ basket: intBasket.id,
2292
+ children: this.children,
2293
+ co2PerItem,
2294
+ co2PerPassenger,
2295
+ currency: total.currency as CurrencyCode,
2296
+ detail: schemaDetails,
2297
+ price: total.price,
2298
+ searchQuery: this.resultQuery,
2299
+ service: sourceId.toString(),
2300
+ outboundDate
2301
+ };
2302
+ if (inboundDate) {
2303
+ booking.inboundDate = inboundDate;
2304
+ }
2305
+ this.basketService.addToBasket(
2306
+ booking,
2307
+ intBasket,
2308
+ this.searchService,
2309
+ this.travellers
2310
+ );
2311
+ }
2312
+ makeSchemaFlights(
2313
+ selectedFlight: FlightJourney,
2314
+ flightGroup: 'outbound' | 'inbound',
2315
+ groupIndex: number,
2316
+ segmentIndex: number
2317
+ ): any {
2318
+ return {
2319
+ cabinClass: selectedFlight.cabinClass,
2320
+ dateTimeArriving: selectedFlight.dateTimeArriving,
2321
+ dateTimeArrivingUTC: selectedFlight.dateTimeArrivingUTC,
2322
+ dateTimeDeparting: selectedFlight.dateTimeDeparting,
2323
+ dateTimeDepartingUTC: selectedFlight.dateTimeDepartingUTC,
2324
+ destinationAirport: selectedFlight.destinationAirport,
2325
+ journeyInfo: {
2326
+ flightGroup,
2327
+ groupIndex,
2328
+ segmentIndex
2329
+ },
2330
+ marketingCarrier: selectedFlight.marketingCarrier,
2331
+ marketingFlightNumber: selectedFlight.marketingFlightNumber,
2332
+ operatingCarrier: selectedFlight.operatingCarrier,
2333
+ operatingFlightNumber: selectedFlight.operatingFlightNumber,
2334
+ originAirport: selectedFlight.originAirport,
2335
+ totalDuration: selectedFlight.totalDuration
2336
+ };
2337
+ }
2338
+
2339
+ async addFlightJourneysToBasket(
2340
+ flightQuote: FlightItinerary
2341
+ ): Promise<boolean> {
2342
+ if (flightQuote.unavailable) {
2343
+ return Promise.resolve(false);
2344
+ }
2345
+ const intBasket: InternalBasketInterface =
2346
+ await this.basketService.getDefaultBasket();
2347
+ const basket = intBasket?.subject.value;
2348
+ if (basket) {
2349
+ const { sourceId, co2PerItem, co2PerPassenger, total } = flightQuote;
2350
+ const outboundDate: any = moment(
2351
+ flightQuote.outboundFlights[0].dateTimeDeparting
2352
+ );
2353
+ const inboundDate: any = flightQuote.inboundFlights.length
2354
+ ? moment(flightQuote.inboundFlights[0].dateTimeDeparting)
2355
+ : null;
2356
+
2357
+ const schemaDetails = {
2358
+ outboundFlights: [
2359
+ ...flightQuote.outboundFlights.map(
2360
+ (flight: FlightJourney, segmentIndex: number) =>
2361
+ this.makeSchemaFlights(flight, 'outbound', 0, segmentIndex)
2362
+ )
2363
+ ],
2364
+ inboundFlights: [
2365
+ ...flightQuote.inboundFlights.map(
2366
+ (flight: FlightJourney, segmentIndex: number) =>
2367
+ this.makeSchemaFlights(flight, 'inbound', 0, segmentIndex)
2368
+ )
2369
+ ],
2370
+ journeyType: 'single'
2371
+ };
2372
+ const booking: AddItemToBasketMutationVariables = {
2373
+ adults: this.adults,
2374
+ basket: intBasket.id,
2375
+ children: this.children,
2376
+ co2PerItem,
2377
+ co2PerPassenger,
2378
+ currency: total.currency as CurrencyCode,
2379
+ detail: schemaDetails,
2380
+ price: total.price,
2381
+ searchQuery: this.resultQuery,
2382
+ service: sourceId.toString(),
2383
+ outboundDate: outboundDate.format()
2384
+ };
2385
+ if (inboundDate) {
2386
+ booking.inboundDate = inboundDate.format();
2387
+ schemaDetails.journeyType = 'roundtrip';
2388
+ }
2389
+
2390
+ return this.basketService.addToBasket(
2391
+ booking,
2392
+ intBasket,
2393
+ this.searchService,
2394
+ this.travellers
2395
+ );
2396
+ }
2397
+ return Promise.resolve(false); // TODO should this throw an error?
2398
+ }
2399
+ }