@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,1751 @@
1
+ import moment from 'moment';
2
+ import { of, Observable, BehaviorSubject, combineLatest } from 'rxjs';
3
+ import { map, take, tap } from 'rxjs/operators';
4
+ import { BaseEnterpriseSearch } from './base-enterprise';
5
+ import { BaseStorageService } from '../services/storage.service';
6
+ import { BaseHelperRoutines } from './helpers';
7
+ import { RailTicketGroups } from '../interfaces/rail-ticket-groups.interface';
8
+ import {
9
+ RailResultIndifiers,
10
+ RailTicketGroup,
11
+ TicketGroups
12
+ } from '../interfaces/rail-ticket-group.interface';
13
+ import { RailDirection } from './rail-direction.enum';
14
+ import { ValueDisplay } from '../interfaces/value-display';
15
+ import {
16
+ NgbDateStruct,
17
+ RailQuoteResultArray,
18
+ RecentSearch,
19
+ RecursivePartial
20
+ } from '../types/types';
21
+ import {
22
+ BasketItem,
23
+ CurrencyCode,
24
+ RailAccount,
25
+ RailClass,
26
+ RailJourneyOption,
27
+ RailJourneyOptions,
28
+ RailJourneyType,
29
+ RailProvider,
30
+ RailSegment,
31
+ RailStation,
32
+ RailTicketOption,
33
+ RailTicketQueue,
34
+ ReferenceRailCardQualifier,
35
+ SaveRecentSearchMutationVariables,
36
+ SearchRailQueryVariables,
37
+ ServiceType,
38
+ RailTicketExtra
39
+ } from '../types/graphql.types';
40
+ import {
41
+ BaseRailQuoteFetcher,
42
+ RailQuoteFetcherType
43
+ } from '../fetchers/rail-quote-fetcher';
44
+ import {
45
+ BaseGetRailStationFetcher,
46
+ GetRailStationFetcherType
47
+ } from '../fetchers/get-rail-station.fetcher';
48
+ import {
49
+ EnterpriseBasketServiceInterface,
50
+ InternalBasketInterface
51
+ } from '../interfaces/Ienterprise-basket.service';
52
+ import { EnterpriseSearchServiceInterface } from '../interfaces/Isearch.service';
53
+ import {
54
+ RailEnterpriseSearchInterface,
55
+ RailTempParams
56
+ } from '../interfaces/Irail-enterprise-search';
57
+ import { Traveller } from '../models/traveller.object';
58
+ import { ICheapestPrice } from '../interfaces/cheapest-price';
59
+ import { IRailAirportExpressStations } from '../interfaces/rail-airport-express-stations.interface';
60
+ import { RailBasketItem, TicketExtras } from '../interfaces/rail-basket-item.interface';
61
+ import { RailRecentSearchArgs } from '../interfaces/rail-recent-search-args.interface';
62
+
63
+ export enum RailSearchCriteria {
64
+ Depart = 'Depart After',
65
+ Arrive = 'Arrive Before'
66
+ }
67
+
68
+ export enum RailTicketOptionType { // may need to be expanded for dual/split
69
+ Return = 'Return',
70
+ Single = 'Single'
71
+ }
72
+
73
+ export class RailEnterpriseSearch<
74
+ Q extends RailQuoteFetcherType,
75
+ GRS_Q extends GetRailStationFetcherType
76
+ >
77
+ extends BaseEnterpriseSearch<
78
+ RailTempParams,
79
+ RailQuoteResultArray,
80
+ RailQuoteResultArray
81
+ >
82
+ implements RailEnterpriseSearchInterface
83
+ {
84
+ static readonly STORAGE_SESSION_PARAMS = 'search_rail';
85
+ static readonly STORAGE_SESSION_RESULTS = 'rail_results';
86
+ static readonly PASSING_POINT = 'Passing';
87
+ private travellers: Traveller[];
88
+
89
+ protected resultsSessionName = RailEnterpriseSearch.STORAGE_SESSION_RESULTS;
90
+
91
+ public searchTypes = [
92
+ { display: 'Return', value: RailJourneyType.ReturnJourney },
93
+ { display: 'One-Way', value: RailJourneyType.SingleJourney }
94
+ // { display: 'Open Return', value: RailJourneyType.OpenReturnJourney },
95
+ // { display: 'Dual Singles', value: RailJourneyType.DualSingleJourney },
96
+ ];
97
+
98
+ public classTypes = [
99
+ { display: 'Any', value: RailClass.All },
100
+ { display: 'Standard', value: RailClass.Standard },
101
+ { display: 'First', value: RailClass.First }
102
+ ];
103
+
104
+ public airportExpressStations: IRailAirportExpressStations[] = [
105
+ { code: 'HP1-3', name: 'Heathrow T1-3 - Paddington' },
106
+ { code: 'HP4', name: 'Heathrow T4 - Paddington' },
107
+ { code: 'HP5', name: 'Heathrow T5 - Paddington' },
108
+ { code: 'PH1-3', name: 'Paddington - Heathrow T1-3' },
109
+ { code: 'PH4', name: 'Paddington - Heathrow T4' },
110
+ { code: 'PH5', name: 'Paddington - Heathrow T5' },
111
+ { code: 'GV', name: 'Gatwick - Victoria' },
112
+ { code: 'VG', name: 'Victoria - Gatwick' },
113
+ { code: 'SL', name: 'Stansted - Liverpool Street' },
114
+ { code: 'LS', name: 'Liverpool Street - Stansted' }
115
+ ];
116
+
117
+ public airportExpressStationsCodes: {
118
+ [key: string]: { dep: string; arr: string };
119
+ } = {
120
+ 'HP1-3': { dep: 'HXX', arr: 'PAD' },
121
+ 'PH1-3': { dep: 'PAD', arr: 'HXX' },
122
+ HP4: { dep: 'HAF', arr: 'PAD' },
123
+ PH4: { dep: 'PAD', arr: 'HAF' },
124
+ HP5: { dep: 'HWV', arr: 'PAD' },
125
+ PH5: { dep: 'PAD', arr: 'HWV' },
126
+ GV: { dep: 'GTW', arr: 'VIC' },
127
+ VG: { dep: 'VIC', arr: 'GTW' },
128
+ SL: { dep: 'SSD', arr: 'LST' },
129
+ LS: { dep: 'LST', arr: 'SSD' }
130
+ };
131
+
132
+ public railCriteria = [RailSearchCriteria.Depart, RailSearchCriteria.Arrive];
133
+
134
+ public travelCards = [
135
+ { display: 'Young persons railcard', value: 'YNG' },
136
+ { display: 'Disability railcard', value: 'DIS' },
137
+ { display: 'Family railcard', value: 'FAM' },
138
+ { display: 'Forces railcard', value: 'HMF' },
139
+ { display: 'Travel agency discount', value: 'TAD' }
140
+ ];
141
+
142
+ // YNG: "Young persons railcard",
143
+ // DIS: "Disability railcard",
144
+ // FAM: "Family railcard",
145
+ // HMF: "Forces railcard",
146
+ // TAD: "Travel agency discount"
147
+ public removePassingPointsFromResults = true;
148
+ public type: ServiceType = ServiceType.Rail;
149
+ public minOutboundDate: NgbDateStruct = {
150
+ year: moment().year(),
151
+ month: moment().month() + 1,
152
+ day: moment().date()
153
+ };
154
+ public minInboundDate: NgbDateStruct = {
155
+ year: moment().year(),
156
+ month: moment().month() + 1,
157
+ day: moment().date()
158
+ };
159
+ public maxDate: NgbDateStruct = {
160
+ // ENT-1557 - max Evolvi search date is 6 months in future
161
+ year: moment().add('month', 6).year(),
162
+ month: moment().add('month', 6).month(),
163
+ day: moment().add('month', 6).date()
164
+ };
165
+ private _timeArray: ValueDisplay[];
166
+ private _canCombine: any;
167
+ private _chosenOutboundTicket: RecursivePartial<RailTicketOption>;
168
+ private _chosenInboundTicket: RecursivePartial<RailTicketOption>;
169
+ private _chosenOutboundJourney: RecursivePartial<RailJourneyOption>;
170
+ private _chosenInboundJourney: RecursivePartial<RailJourneyOption>;
171
+ private _chosenTicketGroup: RailTicketGroup;
172
+ private _viaLocation: string;
173
+ private _travellingFrom: string;
174
+ private _travellingTo: string;
175
+ protected _originalUserSearch: RailTempParams;
176
+
177
+ get chosenTicketGroup(): RailTicketGroup {
178
+ return this._chosenTicketGroup;
179
+ }
180
+
181
+ get chosenTotalPrice(): number {
182
+ if (this._chosenOutboundTicket) {
183
+ if (this._chosenInboundTicket) {
184
+ // now check if they are returns or dual
185
+ if (
186
+ this._chosenOutboundTicket.singleOrReturn ===
187
+ RailTicketOptionType.Return &&
188
+ this._chosenInboundTicket.singleOrReturn ===
189
+ RailTicketOptionType.Return
190
+ ) {
191
+ // they should both have the same price
192
+ return this._chosenOutboundTicket.price;
193
+ }
194
+ return (
195
+ this._chosenOutboundTicket.price + this._chosenInboundTicket.price
196
+ );
197
+ }
198
+
199
+ return this._chosenOutboundTicket.price;
200
+ }
201
+
202
+ return 0;
203
+ }
204
+
205
+ get chosenTickets(): any {
206
+ return {
207
+ Outbound: this._chosenOutboundTicket,
208
+ Inbound: this._chosenInboundTicket
209
+ };
210
+ }
211
+
212
+ get chosenOutboundJourney(): RecursivePartial<RailJourneyOption> {
213
+ return this._chosenOutboundJourney;
214
+ }
215
+
216
+ get chosenInboundJourney(): RecursivePartial<RailJourneyOption> {
217
+ return this._chosenInboundJourney;
218
+ }
219
+
220
+ get openReturn(): boolean {
221
+ return this.tempParams.openReturn;
222
+ }
223
+
224
+ set openReturn(newVal: boolean) {
225
+ this.tempParams.openReturn = newVal;
226
+
227
+ if (newVal) {
228
+ this.tempParams.chosenSearchType = RailJourneyType.OpenReturnJourney;
229
+ }
230
+ this._isValid();
231
+ }
232
+
233
+ get chosenSearchType(): RailJourneyType {
234
+ return this.tempParams.chosenSearchType;
235
+ }
236
+
237
+ set chosenSearchType(newType: RailJourneyType) {
238
+ this.tempParams.chosenSearchType = newType;
239
+ if (newType === RailJourneyType.SingleJourney) {
240
+ this.openReturn = false;
241
+ }
242
+ this._isValid();
243
+ }
244
+
245
+ get noOfAdults(): number {
246
+ return this.tempParams.noOfAdults;
247
+ }
248
+
249
+ set noOfAdults(adults: number) {
250
+ this.tempParams.noOfAdults = adults;
251
+ this._isValid();
252
+ }
253
+
254
+ get noOfChildren(): number {
255
+ return this.tempParams.noOfChildren;
256
+ }
257
+
258
+ set noOfChildren(children: number) {
259
+ this.tempParams.noOfChildren = children;
260
+ this._isValid();
261
+ }
262
+
263
+ get travellingTo(): any {
264
+ return this.tempParams.travellingTo;
265
+ }
266
+
267
+ set travellingTo(tt: any) {
268
+ this.tempParams.travellingTo = tt;
269
+
270
+ this._travellingTo = '';
271
+ if (tt?.railstation?.id) {
272
+ this._travellingTo = tt.railstation.id;
273
+ }
274
+
275
+ this._isValid();
276
+ }
277
+
278
+ get travellingFrom(): any {
279
+ return this.tempParams.travellingFrom;
280
+ }
281
+
282
+ set travellingFrom(tt: any) {
283
+ this.tempParams.travellingFrom = tt;
284
+ this._travellingFrom = '';
285
+ if (tt?.railstation?.id) {
286
+ this._travellingFrom = tt.railstation.id;
287
+ }
288
+
289
+ this._isValid();
290
+ }
291
+
292
+ get chosenRailClass(): RailClass {
293
+ return this.tempParams.chosenSearchClass;
294
+ }
295
+
296
+ set chosenRailClass(newClass: RailClass) {
297
+ this.tempParams.chosenSearchClass = newClass;
298
+ }
299
+
300
+ get chosenSearchClass(): RailClass {
301
+ return this.tempParams.chosenSearchClass;
302
+ }
303
+
304
+ set chosenSearchClass(classR: RailClass) {
305
+ this.tempParams.chosenSearchClass = classR;
306
+ this._isValid();
307
+ }
308
+
309
+ get extraTime(): boolean {
310
+ return this.tempParams.extraTime;
311
+ }
312
+
313
+ set extraTime(extra: boolean) {
314
+ this.tempParams.extraTime = extra;
315
+ this._isValid();
316
+ }
317
+
318
+ get via(): boolean {
319
+ return this.tempParams.via;
320
+ }
321
+
322
+ set via(via: boolean) {
323
+ this.tempParams.via = via;
324
+ this._isValid();
325
+ }
326
+
327
+ get viaLocation(): any {
328
+ return this.tempParams.viaLocation;
329
+ }
330
+
331
+ set viaLocation(viaLocation: any) {
332
+ this.tempParams.viaLocation = viaLocation;
333
+
334
+ this._viaLocation = '';
335
+ if (viaLocation?.railstation?.id) {
336
+ this._viaLocation = viaLocation.railstation.id;
337
+ }
338
+
339
+ this._isValid();
340
+ }
341
+
342
+ get outBoundDateTime(): moment.Moment {
343
+ return this.tempParams.outBoundDateTime;
344
+ }
345
+
346
+ set outBoundDateTime(newDateTime: moment.Moment) {
347
+ this.tempParams.outBoundDateTime = newDateTime;
348
+ if (newDateTime && newDateTime.isValid()) {
349
+ this._outbound_date = this.helpers.momentToNgDate(newDateTime);
350
+ this._outbound_time = moment(newDateTime).format('HHmm')
351
+ ? moment(newDateTime).format('HHmm')
352
+ : '0700';
353
+ }
354
+
355
+ this.minInboundDate = {
356
+ year: newDateTime.year(),
357
+ month: newDateTime.month() + 1,
358
+ day: newDateTime.date()
359
+ };
360
+
361
+ if (
362
+ this.outBoundDateTime &&
363
+ this.inBoundDateTime &&
364
+ this.outBoundDateTime.isAfter(this.inBoundDateTime)
365
+ ) {
366
+ this.inBoundDateTime = this.inBoundDateTime
367
+ .set('date', newDateTime.date())
368
+ .set('month', newDateTime.month())
369
+ .set('year', newDateTime.year());
370
+ }
371
+
372
+ this._isValid();
373
+ }
374
+
375
+ get outboundCriteria(): RailSearchCriteria {
376
+ return this.tempParams.outboundCriteria;
377
+ }
378
+
379
+ set outboundCriteria(newCrit: RailSearchCriteria) {
380
+ // console.warn(`+++ Setting New Criteria: ${newCrit} +++`);
381
+ this.tempParams.outboundCriteria = newCrit;
382
+
383
+ this._isValid();
384
+ }
385
+
386
+ get inBoundDateTime(): moment.Moment {
387
+ return this.tempParams.inBoundDateTime;
388
+ }
389
+
390
+ set inBoundDateTime(newDateTime: moment.Moment) {
391
+ this.tempParams.inBoundDateTime = newDateTime;
392
+ if (newDateTime && newDateTime.isValid()) {
393
+ this._return_date = this.helpers.momentToNgDate(newDateTime);
394
+ this._return_time = moment(newDateTime).format('HHmm')
395
+ ? moment(newDateTime).format('HHmm')
396
+ : '1600';
397
+ }
398
+ this._isValid();
399
+ }
400
+
401
+ // !date and time is handled differently for LU
402
+ private _outbound_date: NgbDateStruct = null;
403
+
404
+ get outbound_date(): NgbDateStruct {
405
+ return this._outbound_date;
406
+ }
407
+
408
+ set outbound_date(value: NgbDateStruct) {
409
+ this._outbound_date = value;
410
+ this._updateOutboundDateTime();
411
+ }
412
+
413
+ private _outbound_time: string = null;
414
+ get outbound_time(): string {
415
+ return this._outbound_time;
416
+ }
417
+
418
+ set outbound_time(value: string) {
419
+ this._outbound_time = value;
420
+ this._updateOutboundDateTime();
421
+ }
422
+
423
+ private _return_date: NgbDateStruct = null;
424
+
425
+ get return_date(): NgbDateStruct {
426
+ return this._return_date;
427
+ }
428
+
429
+ set return_date(value: NgbDateStruct) {
430
+ this._return_date = value;
431
+ this._updateReturnDateTime();
432
+ }
433
+
434
+ private _return_time: string = null;
435
+ get return_time(): string {
436
+ return this._return_time;
437
+ }
438
+
439
+ set return_time(value: string) {
440
+ this._return_time = value;
441
+ this._updateReturnDateTime();
442
+ }
443
+
444
+ get returnCriteria(): RailSearchCriteria {
445
+ return this.tempParams.returnCriteria;
446
+ }
447
+
448
+ set returnCriteria(newCrit: RailSearchCriteria) {
449
+ this.tempParams.returnCriteria = newCrit;
450
+ this._isValid();
451
+ }
452
+
453
+ get carnetTicket(): boolean {
454
+ return this.tempParams.carnetTicket;
455
+ }
456
+
457
+ set carnetTicket(newCarnet: boolean) {
458
+ this.tempParams.carnetTicket = newCarnet;
459
+ this._isValid();
460
+ }
461
+
462
+ get disableAutoDiscounts(): boolean {
463
+ return this.tempParams.disableAutoDiscounts;
464
+ }
465
+
466
+ set disableAutoDiscounts(newDis: boolean) {
467
+ this.tempParams.disableAutoDiscounts = newDis;
468
+ this._isValid();
469
+ }
470
+
471
+ get prioritiseByPrice(): boolean {
472
+ return this.tempParams.prioritiseByPrice;
473
+ }
474
+
475
+ set prioritiseByPrice(newPriority: boolean) {
476
+ this.tempParams.prioritiseByPrice = newPriority;
477
+ this._isValid();
478
+ }
479
+
480
+ get applyRailcards(): boolean {
481
+ return this.tempParams.applyRailcards;
482
+ }
483
+
484
+ set applyRailcards(apCards: boolean) {
485
+ this.tempParams.applyRailcards = apCards;
486
+ }
487
+
488
+ get railCards(): ReferenceRailCardQualifier[] {
489
+ return this.tempParams.railCards;
490
+ }
491
+
492
+ set railCards(value: ReferenceRailCardQualifier[]) {
493
+ this.tempParams.railCards = value;
494
+ }
495
+
496
+ public get timeArray(): ValueDisplay[] {
497
+ this._timeArray =
498
+ this._timeArray ||
499
+ Array(48)
500
+ .fill(0)
501
+ .map((_, index: number) => {
502
+ return {
503
+ value:
504
+ Math.floor(index / 2)
505
+ .toString()
506
+ .padStart(2, '0') +
507
+ ((index % 2) * 30).toString().padStart(2, '0'),
508
+ display:
509
+ Math.floor(index / 2)
510
+ .toString()
511
+ .padStart(2, '0') +
512
+ ':' +
513
+ ((index % 2) * 30).toString().padStart(2, '0')
514
+ };
515
+ });
516
+ return this._timeArray;
517
+ }
518
+
519
+ getAirportExpressStations(): { code: string; name: string }[] {
520
+ return this.airportExpressStations;
521
+ }
522
+
523
+ get airportExpressStation(): string {
524
+ return this.tempParams.airportExpressStation;
525
+ }
526
+
527
+ set airportExpressStation(station: string) {
528
+ this.tempParams.airportExpressStation = station;
529
+ this._setAirportExpressStations();
530
+ this._isValid();
531
+ }
532
+
533
+ get isAirportExpress(): boolean {
534
+ return this.tempParams.isAirportExpress;
535
+ }
536
+
537
+ set isAirportExpress(value: boolean) {
538
+ this.tempParams.isAirportExpress = value;
539
+ this.tempParams.openReturn = value;
540
+ this.tempParams.chosenSearchType = value
541
+ ? RailJourneyType.OpenReturnJourney
542
+ : RailJourneyType.ReturnJourney;
543
+ this._isValid();
544
+ }
545
+
546
+ setAirportExpressStationIds(stationIds: {
547
+ departureLocationId: string;
548
+ arrivalLocationId: string;
549
+ }): void {
550
+ const { departureLocationId, arrivalLocationId } = stationIds;
551
+ if (departureLocationId && arrivalLocationId) {
552
+ this._travellingFrom = departureLocationId;
553
+ this._travellingTo = arrivalLocationId;
554
+ this._isValid();
555
+ }
556
+ }
557
+
558
+ private _cheapestStandard: RailTicketOption = null;
559
+ get cheapestStandard(): RailTicketOption {
560
+ return this._cheapestStandard;
561
+ }
562
+ private _cheapestFirst: RailTicketOption = null;
563
+ get cheapestFirst(): RailTicketOption {
564
+ return this._cheapestFirst;
565
+ }
566
+
567
+ constructor(
568
+ private Railfetcher: BaseRailQuoteFetcher<Q>,
569
+ private getRailStationFetcher: BaseGetRailStationFetcher<GRS_Q>,
570
+ private helpers: BaseHelperRoutines,
571
+ private basketService: EnterpriseBasketServiceInterface,
572
+ storageService: BaseStorageService,
573
+ private searchService: EnterpriseSearchServiceInterface
574
+ ) {
575
+ super(storageService);
576
+
577
+ const data: {
578
+ query: {};
579
+ tempParams: RailTempParams;
580
+ originalUserSearch: RailTempParams;
581
+ } = storageService.getSessionItem(
582
+ RailEnterpriseSearch.STORAGE_SESSION_PARAMS
583
+ ) || {
584
+ query: {},
585
+ tempParams: {} as RailTempParams,
586
+ originalUserSearch: {} as RailTempParams
587
+ };
588
+
589
+ this.updateTempParams(this.searchService.makeRailQuery(data.tempParams));
590
+ this._originalUserSearch = data.originalUserSearch;
591
+
592
+ if (this._originalUserSearch && this._originalUserSearch.chosenSearchType) {
593
+ this.chosenSearchType = this._originalUserSearch.chosenSearchType;
594
+ }
595
+
596
+ if (searchService.shouldAddTravellerSubscription()) {
597
+ searchService.travellerInformation.subscribe(
598
+ (travellers: Traveller[]) => {
599
+ this.travellers = travellers;
600
+ const splitTravellers = this.helpers.selectedTravellers(
601
+ travellers,
602
+ ServiceType.Rail
603
+ );
604
+ this.tempParams.noOfAdults = splitTravellers.adults.length;
605
+ this.tempParams.noOfChildren = splitTravellers.children.length;
606
+ this.travellers = travellers;
607
+ this._isValid();
608
+ }
609
+ );
610
+ }
611
+ this._isValid();
612
+ const results =
613
+ storageService.getSessionItemAsList<RailQuoteResultArray>(
614
+ this.resultsSessionName
615
+ ) || [];
616
+ // if (results == null && this.isValid) {
617
+ // searchService.startSearches();
618
+ // }
619
+ this._cheapestResultPrice = this.updateLowestPrice(results);
620
+ this.results.next(results || []);
621
+ }
622
+
623
+ protected resetQuery(): void {
624
+ this.updateTempParams(this.searchService.makeRailQuery());
625
+ this._isValid();
626
+ }
627
+
628
+ private _setAirportExpressStations() {
629
+ const parsedStation =
630
+ this.airportExpressStationsCodes[this.airportExpressStation];
631
+ console.log('--- Parsed Station is :', parsedStation);
632
+ if (parsedStation) {
633
+ this._travellingFrom = parsedStation.dep;
634
+ this._travellingTo = parsedStation.arr;
635
+ }
636
+ }
637
+
638
+ private _isValid() {
639
+ this.storageService.setSessionItem(
640
+ RailEnterpriseSearch.STORAGE_SESSION_PARAMS,
641
+ {
642
+ tempParams: this.tempParams,
643
+ originalUserSearch: this.originalUserSearch
644
+ }
645
+ );
646
+
647
+ this.validationMessages = [];
648
+
649
+ const now = moment();
650
+
651
+ if (!this._travellingFrom) {
652
+ this.validationMessages.push('Please Enter a From Location.');
653
+ }
654
+
655
+ if (!this._travellingTo) {
656
+ this.validationMessages.push('Please Enter a To Location.');
657
+ }
658
+
659
+ if (this.outBoundDateTime?.isBefore(now)) {
660
+ this.validationMessages.push(
661
+ 'Departure Date/Time cannot be in the past.'
662
+ );
663
+ }
664
+
665
+ if (
666
+ this.chosenSearchType === RailJourneyType.ReturnJourney ||
667
+ this.chosenSearchType === RailJourneyType.DualSingleJourney
668
+ ) {
669
+ // check for return specific validations in here
670
+
671
+ if (this.inBoundDateTime?.isSameOrBefore(this.outBoundDateTime)) {
672
+ this.validationMessages.push(
673
+ 'Return Date/Time must be after Departure Date/Time'
674
+ );
675
+ }
676
+ }
677
+
678
+ if (this.via) {
679
+ if (!this.tempParams.viaLocation) {
680
+ this.validationMessages.push('Please enter a via location.');
681
+ }
682
+ }
683
+
684
+ if (this.tempParams.noOfAdults + this.tempParams.noOfChildren < 1) {
685
+ this.validationMessages.push('There must be at least 1 traveller');
686
+ }
687
+
688
+ this.isValid.next(this.validationMessages.length === 0);
689
+ this.messages.next(this.validationMessages);
690
+ }
691
+
692
+ startSearch(): Promise<boolean> {
693
+ this.results.next([]);
694
+
695
+ if (this.isValid.value) {
696
+ this._originalUserSearch = Object.freeze({ ...this.tempParams });
697
+ this.storageService.setSessionItem(
698
+ RailEnterpriseSearch.STORAGE_SESSION_PARAMS,
699
+ {
700
+ tempParams: this.tempParams,
701
+ originalUserSearch: this.originalUserSearch
702
+ }
703
+ );
704
+ const query = this.getSearchQuery();
705
+ this.searchService.saveRecentSearch(this.getRecentSearchQuery(query));
706
+ return this._startSearch(
707
+ this.Railfetcher.fetchList(query).pipe(
708
+ map((result) => {
709
+ if (this.removePassingPointsFromResults) {
710
+ result = this._removeCallingPoints(result);
711
+ }
712
+
713
+ return result;
714
+ })
715
+ )
716
+ );
717
+ } else {
718
+ return Promise.resolve(false);
719
+ }
720
+ }
721
+
722
+ getRecentSearchQuery(
723
+ query: SearchRailQueryVariables
724
+ ): SaveRecentSearchMutationVariables {
725
+ const recentSearchQuery: RailRecentSearchArgs = query;
726
+
727
+ if (this.isAirportExpress) {
728
+ recentSearchQuery.isAirportExpress = this.isAirportExpress;
729
+ }
730
+
731
+ if (this.airportExpressStation) {
732
+ recentSearchQuery.airportExpressStation = this.airportExpressStation;
733
+ }
734
+
735
+ return {
736
+ serviceType: ServiceType.Rail,
737
+ searchArgs: recentSearchQuery,
738
+ travelDate: this.outBoundDateTime.format(),
739
+ travellers: this.helpers.getTravellersId(this.travellers)
740
+ };
741
+ }
742
+
743
+ public startRecentSearch(recentSearch: RecentSearch): void {
744
+ this.chosenSearchType = recentSearch.searchArgs.journeyType;
745
+ this.chosenSearchClass = recentSearch.searchArgs.class;
746
+ this.extraTime = recentSearch.searchArgs.extraTimeToChange;
747
+ this.isAirportExpress = recentSearch.searchArgs.isAirportExpress;
748
+ this.airportExpressStation = recentSearch.searchArgs.airportExpressStation;
749
+
750
+ // get outBoundDateTime, inBoundDateTime and outboundCriteria ,returnCriteria
751
+ this.outBoundDateTime = recentSearch.searchArgs.outboundDepartureDateTime
752
+ ? moment(recentSearch.searchArgs.outboundDepartureDateTime)
753
+ : moment(recentSearch.searchArgs.outboundArrivalDateTime);
754
+ this.outboundCriteria = this.getCriteria(
755
+ recentSearch.searchArgs.outboundDepartureDateTime,
756
+ recentSearch.searchArgs.outboundArrivalDateTime
757
+ );
758
+
759
+ if (recentSearch.searchArgs.journeyType === RailJourneyType.ReturnJourney) {
760
+ this.inBoundDateTime = recentSearch.searchArgs.returnDepartureDateTime
761
+ ? moment(recentSearch.searchArgs.returnDepartureDateTime)
762
+ : moment(recentSearch.searchArgs.returnArrivalDateTime);
763
+
764
+ this.returnCriteria = this.getCriteria(
765
+ recentSearch.searchArgs.returnDepartureDateTime,
766
+ recentSearch.searchArgs.returnArrivalDateTime
767
+ );
768
+ }
769
+
770
+ if (
771
+ recentSearch.searchArgs.journeyType === RailJourneyType.OpenReturnJourney
772
+ ) {
773
+ this.openReturn = true;
774
+ }
775
+
776
+ this.applyRailcards = recentSearch.searchArgs?.railCardQualifiers?.length
777
+ ? true
778
+ : false;
779
+ if (this.applyRailcards) {
780
+ this.railCards = recentSearch.searchArgs.railCardQualifiers;
781
+ }
782
+
783
+ // get from, to, via
784
+ combineLatest([
785
+ this.getRailStationById(recentSearch.searchArgs.departureLocationId),
786
+ this.getRailStationById(recentSearch.searchArgs.arrivalLocationId)
787
+ ]).subscribe(([departureStation, arrivalStation]) => {
788
+ if (departureStation && arrivalStation) {
789
+ this.travellingTo = {
790
+ name: arrivalStation.name,
791
+ railstation: {
792
+ id: arrivalStation.id,
793
+ name: arrivalStation.name,
794
+ nlcCode: arrivalStation.nlcCode,
795
+ stationCode: arrivalStation.stationCode,
796
+ trainlineCode: arrivalStation.trainlineCode,
797
+ trainlineUniqueCode: arrivalStation.trainlineUniqueCode
798
+ }
799
+ };
800
+
801
+ this.travellingFrom = {
802
+ name: departureStation.name,
803
+ railstation: {
804
+ id: departureStation.id,
805
+ name: departureStation.name,
806
+ nlcCode: departureStation.nlcCode,
807
+ stationCode: departureStation.stationCode,
808
+ trainlineCode: departureStation.trainlineCode,
809
+ trainlineUniqueCode: departureStation.trainlineUniqueCode
810
+ }
811
+ };
812
+
813
+ if (recentSearch.searchArgs.viaLocationId) {
814
+ this.via = true;
815
+ this.getRailStationById(
816
+ recentSearch.searchArgs.viaLocationId
817
+ ).subscribe((viaLocation) => {
818
+ this.viaLocation = {
819
+ name: viaLocation.name,
820
+ railstation: {
821
+ id: viaLocation.id,
822
+ name: viaLocation.name,
823
+ nlcCode: viaLocation.nlcCode,
824
+ stationCode: viaLocation.stationCode,
825
+ trainlineCode: viaLocation.trainlineCode,
826
+ trainlineUniqueCode: viaLocation.trainlineUniqueCode
827
+ }
828
+ };
829
+ this.searchService.startSearches();
830
+ });
831
+ }
832
+
833
+ this.searchService.startSearches();
834
+ }
835
+ });
836
+ }
837
+
838
+ private _removeCallingPoints(
839
+ journeys: RailJourneyOptions[]
840
+ ): RailJourneyOptions[] {
841
+ journeys[0].outbound = journeys[0].outbound.map((outbound) => {
842
+ outbound.segments.map((segment) => {
843
+ segment.callingPoints = segment.callingPoints.filter(
844
+ (callingPoint) =>
845
+ callingPoint.stoppingPattern !== RailEnterpriseSearch.PASSING_POINT
846
+ );
847
+ return segment;
848
+ });
849
+ return outbound;
850
+ });
851
+
852
+ return journeys;
853
+ }
854
+
855
+ private _updateOutboundDateTime(): void {
856
+ if (this._outbound_date && this._outbound_time) {
857
+ const time = this.helpers.ngDateToMoment(
858
+ this._outbound_date,
859
+ this._outbound_time
860
+ );
861
+ this.outBoundDateTime = time.isValid() ? time : null;
862
+ this._isValid();
863
+ }
864
+ }
865
+
866
+ private _updateReturnDateTime(): void {
867
+ if (this._return_date && this._return_time) {
868
+ const time = this.helpers.ngDateToMoment(
869
+ this._return_date,
870
+ this._return_time
871
+ );
872
+ this.inBoundDateTime = time.isValid() ? time : null;
873
+ this._isValid();
874
+ }
875
+ }
876
+
877
+ getSearchQuery(): SearchRailQueryVariables {
878
+ const query: SearchRailQueryVariables = {
879
+ countryCode: 'GB',
880
+ journeyType: this.tempParams.chosenSearchType,
881
+ adults: this.tempParams.noOfAdults,
882
+ arrivalLocationId: this._travellingTo,
883
+ departureLocationId: this._travellingFrom,
884
+ children: this.tempParams.noOfChildren,
885
+ class: this.tempParams.chosenSearchClass,
886
+ extraTimeToChange: this.tempParams.extraTime,
887
+ outboundArrivalDateTime: this.tempParams.outBoundDateTime,
888
+ outboundDepartureDateTime: this.tempParams.outBoundDateTime,
889
+ returnArrivalDateTime: this.tempParams.inBoundDateTime,
890
+ returnDepartureDateTime: this.tempParams.inBoundDateTime,
891
+ viaLocationId: this._viaLocation,
892
+ railCardQualifiers: this.tempParams.railCards?.map(
893
+ (railCard: ReferenceRailCardQualifier) => {
894
+ return railCard.code;
895
+ }
896
+ )
897
+ };
898
+
899
+ if (this.tempParams.noOfChildren === 0) {
900
+ query.children = null;
901
+ }
902
+
903
+ if (this._viaLocation === '') {
904
+ query.viaLocationId = null;
905
+ }
906
+
907
+ switch (this.tempParams.outboundCriteria) {
908
+ case RailSearchCriteria.Depart:
909
+ query.outboundArrivalDateTime = null;
910
+ break;
911
+ case RailSearchCriteria.Arrive:
912
+ query.outboundDepartureDateTime = null;
913
+ break;
914
+ default:
915
+ console.warn(
916
+ `+++ Unknown Criteria: ${this.tempParams.outboundCriteria} +++`
917
+ );
918
+ }
919
+
920
+ switch (this.tempParams.returnCriteria) {
921
+ case RailSearchCriteria.Depart:
922
+ query.returnArrivalDateTime = null;
923
+ break;
924
+ case RailSearchCriteria.Arrive:
925
+ query.returnDepartureDateTime = null;
926
+ break;
927
+ default:
928
+ console.warn(
929
+ `+++ Unknown Criteria: ${this.tempParams.returnCriteria} +++`
930
+ );
931
+ }
932
+
933
+ switch (this.tempParams.chosenSearchType) {
934
+ case RailJourneyType.SingleJourney:
935
+ case RailJourneyType.OpenReturnJourney:
936
+ query.returnDepartureDateTime = null;
937
+ query.returnArrivalDateTime = null;
938
+ break;
939
+ }
940
+
941
+ return this.helpers.removeNulls<SearchRailQueryVariables>(query);
942
+ }
943
+
944
+ private getRailStationById(id: string): Observable<RailStation> {
945
+ if (id) {
946
+ return this.getRailStationFetcher.fetchList({ id }).pipe(take(1));
947
+ } else {
948
+ return of();
949
+ }
950
+ }
951
+
952
+ private getCriteria(
953
+ departureDateTime: string,
954
+ arrivalDateTime: string
955
+ ): RailSearchCriteria {
956
+ if (departureDateTime) {
957
+ return RailSearchCriteria.Depart;
958
+ } else if (arrivalDateTime) {
959
+ return RailSearchCriteria.Arrive;
960
+ }
961
+ {
962
+ return null;
963
+ }
964
+ }
965
+
966
+ createTicketGroups(results: RailJourneyOptions[]): RailTicketGroups {
967
+ let tickets: RailTicketGroups = {};
968
+ let ticketId = '';
969
+ this._canCombine = {};
970
+
971
+ let ticketGroupsOutbound = this.setTicketsGroups(results[0].outbound);
972
+ let ticketGroupsReturn = this.setTicketsGroups(results[0].return);
973
+ ticketGroupsOutbound = this.sortTicketPrices(ticketGroupsOutbound);
974
+ ticketGroupsReturn = this.sortTicketPrices(ticketGroupsReturn);
975
+
976
+ Object.keys(ticketGroupsOutbound).map((key) => {
977
+ ticketGroupsOutbound[key].map((tkt: RailTicketOption) => {
978
+ ticketId = `${tkt.type}${tkt.singleOrReturn}`;
979
+ const identifier = tkt.identifiers.journeyIdentifier;
980
+ const identifierObj: RailResultIndifiers = {};
981
+ identifierObj[identifier] = {
982
+ price: tkt.price,
983
+ isChild: false,
984
+ fareIdentifier: tkt.identifiers.fareIdentifier,
985
+ availableSeats: tkt.availableSeats
986
+ };
987
+ if (tickets[key]) {
988
+ this.updateCanCombine(tkt);
989
+ identifierObj[tkt.identifiers.journeyIdentifier].isChild = false;
990
+ if (tickets[tkt.type].header.price === tkt.price) {
991
+ tickets[tkt.type].resultIndifiers.push(identifier);
992
+ tickets[tkt.type].resultIndifiersPrices = {
993
+ ...tickets[tkt.type].resultIndifiersPrices,
994
+ ...identifierObj
995
+ };
996
+ } else if (tkt.price) {
997
+ // add identifier and price even if it is a child
998
+ if (!tickets[tkt.type].resultIndifiers.includes(identifier)) {
999
+ tickets[tkt.type].resultIndifiers.push(identifier);
1000
+ tickets[tkt.type].resultIndifiersPrices = {
1001
+ ...tickets[tkt.type].resultIndifiersPrices,
1002
+ ...identifierObj
1003
+ };
1004
+ }
1005
+ identifierObj[identifier].isChild = true;
1006
+ const childTicket = {
1007
+ header: tkt,
1008
+ children: [],
1009
+ open: false,
1010
+ direction: RailDirection.Outbound,
1011
+ resultIndifiers: [identifier],
1012
+ resultIndifiersPrices: identifierObj,
1013
+ child: true,
1014
+ ticketId,
1015
+ selectedIndicies: [],
1016
+ disabledIndicies: [],
1017
+ showLimitedSeats: false
1018
+ } as RailTicketGroup;
1019
+ tickets[tkt.type].children.push(childTicket);
1020
+ }
1021
+ } else {
1022
+ this._canCombine[tkt.type] = {};
1023
+ this.updateCanCombine(tkt);
1024
+ tickets[tkt.type] = {
1025
+ header: tkt,
1026
+ children: [],
1027
+ open: false,
1028
+ direction: RailDirection.Outbound,
1029
+ resultIndifiers: [identifier],
1030
+ resultIndifiersPrices: identifierObj,
1031
+ child: false,
1032
+ ticketId,
1033
+ selectedIndicies: [],
1034
+ disabledIndicies: [],
1035
+ showLimitedSeats: false
1036
+ } as RailTicketGroup;
1037
+ }
1038
+ });
1039
+ });
1040
+
1041
+ Object.keys(ticketGroupsReturn).map((key) => {
1042
+ ticketGroupsReturn[key].map((tkt: RailTicketOption) => {
1043
+ ticketId = `${tkt.type}${tkt.singleOrReturn}`;
1044
+ const identifier = tkt.identifiers.journeyIdentifier;
1045
+ const identifierObj: RailResultIndifiers = {};
1046
+ identifierObj[identifier] = {
1047
+ price: tkt.price,
1048
+ isChild: true,
1049
+ fareIdentifier: tkt.identifiers.fareIdentifier,
1050
+ availableSeats: tkt.availableSeats
1051
+ };
1052
+ if (
1053
+ tickets[tkt.type] &&
1054
+ tkt.price &&
1055
+ tkt.price !== tickets[tkt.type].header.price
1056
+ ) {
1057
+ this.updateCanCombine(tkt);
1058
+ identifierObj[identifier].isChild = true;
1059
+ const childTicket = {
1060
+ header: tkt,
1061
+ children: [],
1062
+ open: false,
1063
+ direction: RailDirection.Inbound,
1064
+ resultIndifiers: [identifier],
1065
+ resultIndifiersPrices: identifierObj,
1066
+ child: true,
1067
+ ticketId,
1068
+ selectedIndicies: [],
1069
+ disabledIndicies: [],
1070
+ showLimitedSeats: false
1071
+ } as any;
1072
+ tickets[tkt.type].children.push(childTicket);
1073
+ } else if (!tickets[tkt.type]) {
1074
+ this.updateCanCombine(tkt);
1075
+ tickets[tkt.type] = {
1076
+ header: tkt,
1077
+ children: [],
1078
+ open: false,
1079
+ direction: RailDirection.Inbound,
1080
+ resultIndifiers: [identifier],
1081
+ resultIndifiersPrices: identifierObj,
1082
+ child: false,
1083
+ ticketId,
1084
+ selectedIndicies: [],
1085
+ disabledIndicies: [],
1086
+ showLimitedSeats: false
1087
+ } as any;
1088
+ } else if (!tkt.price || tkt.price === tickets[tkt.type].header.price) {
1089
+ this.updateCanCombine(tkt);
1090
+ tickets[tkt.type].resultIndifiers.push(identifier);
1091
+ identifierObj[identifier].isChild = false;
1092
+ tickets[tkt.type].resultIndifiersPrices = {
1093
+ ...tickets[tkt.type].resultIndifiersPrices,
1094
+ ...identifierObj
1095
+ };
1096
+ }
1097
+ });
1098
+ });
1099
+
1100
+ let combineTickets = { ...tickets };
1101
+ tickets = this.combineChildTickets(combineTickets);
1102
+
1103
+ // console.log('groups: ', tickets);
1104
+ // console.log('Can Combine: ', this._canCombine);
1105
+ return tickets;
1106
+ }
1107
+
1108
+ combineChildTickets(tickets: RailTicketGroups): RailTicketGroups {
1109
+ const values = Object.values(tickets);
1110
+ for (let i = 0; i < values.length; i++) {
1111
+ const childObject: { [key: string]: RailTicketGroup } = {};
1112
+
1113
+ for (let j = 0; j < values[i].children.length; j++) {
1114
+ const child = values[i].children[j];
1115
+ const fareIdentifier = child.header.identifiers.fareIdentifier;
1116
+ if (childObject[fareIdentifier]) {
1117
+ childObject[fareIdentifier].resultIndifiers.push(
1118
+ child.resultIndifiers[0]
1119
+ );
1120
+ childObject[fareIdentifier].resultIndifiersPrices = {
1121
+ ...childObject[fareIdentifier].resultIndifiersPrices,
1122
+ ...child.resultIndifiersPrices
1123
+ };
1124
+ } else {
1125
+ childObject[fareIdentifier] = child;
1126
+ }
1127
+ }
1128
+ // console.log(childObject);
1129
+ // console.log(values[i]['header']['type']);
1130
+ tickets[values[i].header.type].children = Object.values(childObject);
1131
+ }
1132
+ tickets = this.sortTicketChildrenPrices(tickets);
1133
+ return tickets;
1134
+ }
1135
+ setTicketsGroups(results: RailJourneyOption[]): TicketGroups {
1136
+ let ticketGroups: TicketGroups = {};
1137
+ results.forEach((out: RailJourneyOption) => {
1138
+ out.providers.forEach((prov: RailProvider) => {
1139
+ prov.ticketOptions.forEach((tkt: RailTicketOption) => {
1140
+ ticketGroups[tkt.type]
1141
+ ? ticketGroups[tkt.type].push(tkt)
1142
+ : (ticketGroups[tkt.type] = [tkt]);
1143
+ });
1144
+ });
1145
+ });
1146
+ return ticketGroups;
1147
+ }
1148
+
1149
+ updateFromPreviousSearches(
1150
+ previousItems: Record<ServiceType, BasketItem>
1151
+ ): void {}
1152
+
1153
+ updateCanCombine(tkt: RailTicketOption): void {
1154
+ (tkt.identifiers.allowedWith || []).forEach((allowed) => {
1155
+ if (!this._canCombine[tkt.type][allowed.journeyIdentifier]) {
1156
+ this._canCombine[tkt.type][allowed.journeyIdentifier] = [
1157
+ allowed.fareIdentifier
1158
+ ];
1159
+ } else {
1160
+ this._canCombine[tkt.type][allowed.journeyIdentifier].push(
1161
+ allowed.fareIdentifier
1162
+ );
1163
+ }
1164
+ });
1165
+ }
1166
+
1167
+ toggleTicketSelect(
1168
+ ticket: RailTicketGroup,
1169
+ way: 'departs' | 'returns',
1170
+ timeSlotId: string,
1171
+ ticketId: string,
1172
+ fareIdentifier: string,
1173
+ ticketsGroups: RailTicketGroups
1174
+ ): RailTicketGroups {
1175
+ console.log(ticket);
1176
+
1177
+ if (!ticket) {
1178
+ return;
1179
+ }
1180
+
1181
+ this._chosenTicketGroup = ticket;
1182
+ const keys = Object.keys(ticketsGroups);
1183
+ let selectedTicket = null;
1184
+ let departsTicket: RailTicketOption[] = [];
1185
+ let returnTicket: RailTicketOption[] = [];
1186
+ let isUnselected = false;
1187
+ keys.forEach((key) => {
1188
+ let group = ticketsGroups[key] as RailTicketGroup;
1189
+
1190
+ if (
1191
+ group.ticketId === ticketId &&
1192
+ group.selectedIndicies.includes(timeSlotId)
1193
+ ) {
1194
+ if (way === 'departs') {
1195
+ group.selectedIndicies = [];
1196
+ departsTicket = [];
1197
+ returnTicket = [];
1198
+ this._chosenInboundTicket = null;
1199
+ this._chosenInboundJourney = null;
1200
+ this._chosenTicketGroup = null;
1201
+ group.children.forEach((child) => {
1202
+ child.selectedIndicies = [];
1203
+ });
1204
+ } else {
1205
+ group.selectedIndicies = group.selectedIndicies.filter(
1206
+ (Indicies) => Indicies !== timeSlotId
1207
+ );
1208
+ returnTicket = returnTicket.filter(
1209
+ (Indicies) => Indicies !== group.header
1210
+ );
1211
+ }
1212
+ } else {
1213
+ if (
1214
+ group.ticketId === ticketId &&
1215
+ group.header.identifiers.fareIdentifier === fareIdentifier &&
1216
+ way === 'departs'
1217
+ ) {
1218
+ group = this.clearUnneededTickets(way, group, timeSlotId);
1219
+ group.selectedIndicies.push(timeSlotId);
1220
+ way === 'departs'
1221
+ ? departsTicket.push(group.header)
1222
+ : returnTicket.push(group.header);
1223
+ selectedTicket = group.header;
1224
+ } else {
1225
+ // may have to modify this for dual singles
1226
+ if (way === 'departs') {
1227
+ group.selectedIndicies = [];
1228
+ } else if (ticketId.includes(group.header.type)) {
1229
+ selectedTicket = group.header;
1230
+ }
1231
+ }
1232
+
1233
+ group.children.forEach((child) => {
1234
+ if (child.selectedIndicies.includes(timeSlotId)) {
1235
+ if (way === 'departs') {
1236
+ child.selectedIndicies = [];
1237
+ departsTicket = [];
1238
+ returnTicket = [];
1239
+ this._chosenInboundTicket = null;
1240
+ this._chosenInboundJourney = null;
1241
+ isUnselected = true;
1242
+ } else {
1243
+ child.selectedIndicies = child.selectedIndicies.filter(
1244
+ (Indicies) => Indicies !== timeSlotId
1245
+ );
1246
+ returnTicket = returnTicket.filter(
1247
+ (Indicies) => Indicies !== group.header
1248
+ );
1249
+ }
1250
+ } else {
1251
+ if (
1252
+ child.ticketId === ticketId &&
1253
+ child.header.identifiers.fareIdentifier === fareIdentifier
1254
+ ) {
1255
+ if (
1256
+ (way === 'departs' &&
1257
+ child.direction !== RailDirection.Inbound) ||
1258
+ (way !== 'departs' && child.direction === RailDirection.Inbound)
1259
+ ) {
1260
+ child = this.clearUnneededTickets(way, child, timeSlotId);
1261
+ child.selectedIndicies.push(timeSlotId);
1262
+ way === 'departs'
1263
+ ? departsTicket.push(child.header)
1264
+ : returnTicket.push(child.header);
1265
+ selectedTicket = child.header;
1266
+ } else if (isUnselected) {
1267
+ child.selectedIndicies = [];
1268
+ }
1269
+ } else {
1270
+ child.selectedIndicies = [];
1271
+ }
1272
+ }
1273
+ });
1274
+ }
1275
+ });
1276
+
1277
+ // now we need to mark tickets as disabled if they are returns that do not match the selected return
1278
+ // or on overlapping times
1279
+ if (way === 'departs') {
1280
+ this._chosenOutboundTicket = this.helpers.clone(selectedTicket);
1281
+
1282
+ // now go over the full results and find the matching timeslot
1283
+ departsTicket.length
1284
+ ? (this._chosenOutboundJourney = this.results.value[0].outbound.find(
1285
+ (out: RailJourneyOption) => {
1286
+ return out.identifiers.journeyIdentifier === timeSlotId;
1287
+ }
1288
+ ))
1289
+ : (this._chosenOutboundJourney = null);
1290
+
1291
+ if (
1292
+ this._chosenInboundTicket &&
1293
+ this._chosenOutboundTicket.singleOrReturn ===
1294
+ RailTicketOptionType.Return &&
1295
+ this._chosenOutboundTicket.identifiers.fareIdentifier !==
1296
+ this._chosenInboundTicket.identifiers.fareIdentifier
1297
+ ) {
1298
+ console.warn('+++ Cannot combine fares, clearing inbound... +++');
1299
+ this._chosenInboundTicket = null;
1300
+ this._chosenInboundJourney = null;
1301
+ }
1302
+ } else if (way === 'returns') {
1303
+ this._chosenInboundTicket = this.helpers.clone(selectedTicket);
1304
+
1305
+ this._chosenInboundTicket
1306
+ ? (this._chosenInboundJourney = this.results.value[0].return.find(
1307
+ (inT: RailJourneyOption) => {
1308
+ return inT.identifiers.journeyIdentifier === timeSlotId;
1309
+ }
1310
+ ))
1311
+ : (this._chosenInboundJourney = null);
1312
+ }
1313
+
1314
+ return ticketsGroups;
1315
+ }
1316
+
1317
+ /**
1318
+ * @description - determine if a fare can be combined with what we currently have selected
1319
+ */
1320
+ canCombine(journeyIdentifier: string, fareIdentifier: string): boolean {
1321
+ // may have to modify this for dual singles later on
1322
+ try {
1323
+ if (
1324
+ this._chosenOutboundTicket &&
1325
+ this._chosenOutboundTicket.singleOrReturn ===
1326
+ RailTicketOptionType.Return &&
1327
+ Number(journeyIdentifier) > 5
1328
+ ) {
1329
+ // greater than 5 only as we are not going to restrict outbounds
1330
+ if (
1331
+ this._canCombine[this._chosenOutboundTicket.type][
1332
+ Number(journeyIdentifier)
1333
+ ]?.includes(fareIdentifier) &&
1334
+ this._chosenOutboundTicket.identifiers.fareIdentifier ===
1335
+ fareIdentifier
1336
+ ) {
1337
+ return true;
1338
+ }
1339
+ return false;
1340
+ }
1341
+ } catch (error) {
1342
+ console.error('+++ Error combining rail fares: ', error, ' +++');
1343
+ }
1344
+
1345
+ return false;
1346
+ }
1347
+
1348
+ clearUnneededTickets(
1349
+ way: string,
1350
+ group: RailTicketGroup,
1351
+ timeSlotId: string
1352
+ ): RailTicketGroup {
1353
+ if (way === 'returns') {
1354
+ group.selectedIndicies = group.selectedIndicies.filter(
1355
+ (indicie: string) => {
1356
+ return Number(indicie) <= 5 || indicie === timeSlotId;
1357
+ }
1358
+ );
1359
+ } else {
1360
+ group.selectedIndicies = group.selectedIndicies.filter(
1361
+ (indicie: string) => {
1362
+ return Number(indicie) > 5 || indicie === timeSlotId;
1363
+ }
1364
+ );
1365
+ }
1366
+
1367
+ return group;
1368
+ }
1369
+
1370
+ getRailStation(
1371
+ code: string,
1372
+ isLoading?: BehaviorSubject<boolean>
1373
+ ): Observable<RailStation> {
1374
+ if (code.length === 3) {
1375
+ isLoading?.next(true);
1376
+ return this.getRailStationFetcher.fetchList({ code }).pipe(
1377
+ tap(() => isLoading?.next(false)),
1378
+ take(1)
1379
+ );
1380
+ } else {
1381
+ return of();
1382
+ }
1383
+ }
1384
+
1385
+ getSelectedRailTicketOption(
1386
+ railJourneyOption: RailJourneyOption,
1387
+ railTicketGroup: RailTicketGroup,
1388
+ providerIndex: number
1389
+ ): RailTicketOption {
1390
+ return railJourneyOption.providers[providerIndex].ticketOptions.find(
1391
+ (ticketOption) =>
1392
+ ticketOption.type === railTicketGroup.header.type &&
1393
+ (ticketOption.price === railTicketGroup.header.price ||
1394
+ ticketOption.identifiers.fareIdentifier ===
1395
+ railTicketGroup.header.identifiers.fareIdentifier)
1396
+ );
1397
+ }
1398
+
1399
+ getLegsFromRailJourneyOption(railJourneyOption: RailJourneyOption): any[] {
1400
+ let legs: any[] = [];
1401
+ if (railJourneyOption?.segments.length) {
1402
+ legs = railJourneyOption.segments.map((segment) => {
1403
+ return {
1404
+ operator: segment.operator,
1405
+ departureDateTime: segment.departDateTime,
1406
+ departureStationName: segment.depart,
1407
+ arrivalDateTime: segment.arriveDateTime,
1408
+ arrivalStationName: segment.arrive
1409
+ };
1410
+ });
1411
+ }
1412
+ return legs;
1413
+ }
1414
+
1415
+ async addSingleJourneyToBasket(
1416
+ serviceId: string,
1417
+ railQuery: SearchRailQueryVariables,
1418
+ railJourneyOption: RailJourneyOption,
1419
+ railTicketGroup: RailTicketGroup
1420
+ ): Promise<boolean> {
1421
+
1422
+ let outTicketExtras: TicketExtras[];
1423
+ // if ticketExtras exists create TicketExtrasObject and added it to the basket
1424
+ if (railJourneyOption.ticketExtras) {
1425
+ outTicketExtras = this.createTicketExtrasObject(railJourneyOption.ticketExtras[0]);
1426
+ }
1427
+
1428
+ if (railJourneyOption.unsellable) {
1429
+ return Promise.resolve(false);
1430
+ }
1431
+ const intBasket: InternalBasketInterface =
1432
+ await this.basketService.getDefaultBasket();
1433
+ const basket = intBasket?.subject.value;
1434
+ if (basket) {
1435
+ const selectedRailTicketOption = this.getSelectedRailTicketOption(
1436
+ railJourneyOption,
1437
+ railTicketGroup,
1438
+ 0
1439
+ );
1440
+ const legs = this.getLegsFromRailJourneyOption(railJourneyOption);
1441
+ const ticketQueueList = selectedRailTicketOption.ticketQueueList.map(
1442
+ (ticketQueueList1) => {
1443
+ return {
1444
+ id: ticketQueueList1.id,
1445
+ name: ticketQueueList1.name,
1446
+ type: ticketQueueList1.type
1447
+ };
1448
+ }
1449
+ );
1450
+
1451
+ const basketItem: RailBasketItem = {
1452
+ basket: basket.id,
1453
+ service: serviceId,
1454
+ detail: {
1455
+ accountsList: selectedRailTicketOption.accountsList.map(
1456
+ (account: RailAccount) => {
1457
+ return { id: account.id, description: account.description };
1458
+ }
1459
+ ),
1460
+ outwardDetail: {
1461
+ arrivalDateTime: railJourneyOption.arriveDateTime,
1462
+ arrivalStationName: railJourneyOption.to,
1463
+ departureDateTime: railJourneyOption.departDateTime,
1464
+ departureStationName: railJourneyOption.from,
1465
+ supplierTickets: [
1466
+ {
1467
+ supplierName: railJourneyOption.providers[0].name,
1468
+ ticketDescription: selectedRailTicketOption.type,
1469
+ price: selectedRailTicketOption.price,
1470
+ legs
1471
+ }
1472
+ ]
1473
+ },
1474
+ transactionIdentifier:
1475
+ railJourneyOption.identifiers.transactionIdentifier,
1476
+ outbound: {
1477
+ fareIdentifiers: [
1478
+ selectedRailTicketOption.identifiers.fareIdentifier
1479
+ ],
1480
+ journeyIdentifier: selectedRailTicketOption.identifiers.journeyIdentifier
1481
+ },
1482
+ ticketQueueList
1483
+ },
1484
+ adults: railQuery.adults,
1485
+ price: selectedRailTicketOption.price,
1486
+ currency: selectedRailTicketOption.currency as CurrencyCode,
1487
+ searchQuery: railQuery,
1488
+ co2PerItem: railJourneyOption.co2PerItem,
1489
+ co2PerPassenger: railJourneyOption.co2PerPassenger,
1490
+ outboundDate: railJourneyOption.departDateTime
1491
+ }
1492
+
1493
+ // if outTicketExtras exists add the object to basketItem
1494
+ if (outTicketExtras) {
1495
+ basketItem.detail.outbound.ticketExtras = outTicketExtras;
1496
+ }
1497
+
1498
+ return this.basketService.addToBasket(
1499
+ basketItem,
1500
+ intBasket,
1501
+ this.searchService,
1502
+ this.travellers
1503
+ );
1504
+ }
1505
+ return Promise.resolve(false);
1506
+ }
1507
+
1508
+ async addReturnJourneyToBasket(
1509
+ serviceId: string,
1510
+ railQuery: SearchRailQueryVariables,
1511
+ outbound: RailJourneyOption,
1512
+ inbound: RailJourneyOption,
1513
+ railTicketGroup: RailTicketGroup
1514
+ ): Promise<boolean> {
1515
+ if (outbound.unsellable) {
1516
+ return Promise.resolve(false);
1517
+ }
1518
+
1519
+ let inTicketExtras: TicketExtras[];
1520
+ let outTicketExtras: TicketExtras[];
1521
+
1522
+ // if ticketExtras exists create TicketExtrasObject and added it to the basket
1523
+ if (inbound.ticketExtras) {
1524
+ inTicketExtras = this.createTicketExtrasObject(inbound.ticketExtras[0]);
1525
+ }
1526
+
1527
+ if (outbound.ticketExtras) {
1528
+ outTicketExtras = this.createTicketExtrasObject(outbound.ticketExtras[0]);
1529
+ }
1530
+
1531
+ const intBasket: InternalBasketInterface =
1532
+ await this.basketService.getDefaultBasket();
1533
+ const basket = intBasket?.subject.value;
1534
+ if (basket) {
1535
+ const selectedRailTicketOption = this.getSelectedRailTicketOption(
1536
+ outbound,
1537
+ railTicketGroup,
1538
+ 0
1539
+ );
1540
+ const selectedInboundRailTicketOption = this.getSelectedRailTicketOption(
1541
+ inbound,
1542
+ railTicketGroup,
1543
+ 0
1544
+ );
1545
+ const outboundLegs = this.getLegsFromRailJourneyOption(outbound);
1546
+ const inboundLegs = this.getLegsFromRailJourneyOption(inbound);
1547
+ const ticketQueueList = selectedRailTicketOption.ticketQueueList.map(
1548
+ (ticketQueueList1: RailTicketQueue) => {
1549
+ return {
1550
+ id: ticketQueueList1.id,
1551
+ name: ticketQueueList1.name,
1552
+ type: ticketQueueList1.type
1553
+ };
1554
+ }
1555
+ );
1556
+
1557
+ const basketItem: RailBasketItem = {
1558
+ basket: basket.id,
1559
+ service: serviceId,
1560
+ detail: {
1561
+ accountsList: selectedRailTicketOption.accountsList.map(
1562
+ (account: RailAccount) => {
1563
+ return { id: account.id, description: account.description };
1564
+ }
1565
+ ),
1566
+ outwardDetail: {
1567
+ arrivalDateTime: outbound.arriveDateTime,
1568
+ arrivalStationName: outbound.to,
1569
+ departureDateTime: outbound.departDateTime,
1570
+ departureStationName: outbound.from,
1571
+ supplierTickets: [
1572
+ {
1573
+ supplierName: outbound.providers[0].name,
1574
+ ticketDescription: selectedRailTicketOption.type,
1575
+ price: selectedRailTicketOption.price,
1576
+ legs: outboundLegs
1577
+ }
1578
+ ]
1579
+ },
1580
+ inwardDetail: {
1581
+ arrivalDateTime: inbound.arriveDateTime,
1582
+ arrivalStationName: inbound.to,
1583
+ departureDateTime: inbound.departDateTime,
1584
+ departureStationName: inbound.from,
1585
+ supplierTickets: [
1586
+ {
1587
+ supplierName: inbound.providers[0].name,
1588
+ ticketDescription: selectedRailTicketOption.type,
1589
+ legs: inboundLegs
1590
+ }
1591
+ ]
1592
+ },
1593
+ transactionIdentifier: outbound.identifiers.transactionIdentifier,
1594
+ outbound: {
1595
+ fareIdentifiers: [
1596
+ selectedRailTicketOption.identifiers.fareIdentifier
1597
+ ],
1598
+ journeyIdentifier: selectedRailTicketOption.identifiers.journeyIdentifier
1599
+ },
1600
+ ticketQueueList,
1601
+ return: {
1602
+ fareIdentifiers: [
1603
+ selectedInboundRailTicketOption.identifiers.fareIdentifier
1604
+ ],
1605
+ journeyIdentifier: selectedInboundRailTicketOption.identifiers.journeyIdentifier
1606
+ }
1607
+ },
1608
+ adults: railQuery.adults,
1609
+ price: railTicketGroup.header.price,
1610
+ currency: selectedRailTicketOption.currency as CurrencyCode,
1611
+ searchQuery: railQuery,
1612
+ co2PerItem: outbound.co2PerItem,
1613
+ co2PerPassenger: outbound.co2PerPassenger,
1614
+ outboundDate: outbound.arriveDateTime,
1615
+ inboundDate: inbound.arriveDateTime
1616
+ }
1617
+
1618
+ // if inTicketExtras or outTicketExtras exists add the object to basketItem
1619
+ if (inTicketExtras) {
1620
+ basketItem.detail.return.ticketExtras = inTicketExtras;
1621
+ }
1622
+ if (outTicketExtras) {
1623
+ basketItem.detail.outbound.ticketExtras = outTicketExtras;
1624
+ }
1625
+
1626
+ return this.basketService.addToBasket(
1627
+ basketItem,
1628
+ intBasket,
1629
+ this.searchService,
1630
+ this.travellers
1631
+ );
1632
+ }
1633
+ return Promise.resolve(false);
1634
+ }
1635
+
1636
+ createTicketExtrasObject(railTicketExtra: RailTicketExtra): TicketExtras[] {
1637
+ return [{
1638
+ type: railTicketExtra.description,
1639
+ location: railTicketExtra.location,
1640
+ date: railTicketExtra.date
1641
+ }];
1642
+ }
1643
+
1644
+ sortTicketPrices(tickets: TicketGroups): TicketGroups {
1645
+ const sortTicketPrices = { ...tickets };
1646
+ Object.keys(sortTicketPrices).map((key) => {
1647
+ sortTicketPrices[key].sort((a: RailTicketOption, b: RailTicketOption) => {
1648
+ const priceA = a.price;
1649
+ const priceB = b.price;
1650
+ return priceA < priceB ? -1 : priceA > priceB ? 1 : 0;
1651
+ });
1652
+ });
1653
+ return sortTicketPrices;
1654
+ }
1655
+ sortTicketChildrenPrices(tickets: RailTicketGroups): RailTicketGroups {
1656
+ const sortTicketPrices = { ...tickets };
1657
+ Object.keys(sortTicketPrices).map((key) => {
1658
+ sortTicketPrices[key].children.sort(
1659
+ (a: RailTicketGroup, b: RailTicketGroup) => {
1660
+ const priceA = a.header.price;
1661
+ const priceB = b.header.price;
1662
+ return priceA < priceB ? -1 : priceA > priceB ? 1 : 0;
1663
+ }
1664
+ );
1665
+ });
1666
+ return sortTicketPrices;
1667
+ }
1668
+ updateLowestPrice(results: RailJourneyOptions[]): ICheapestPrice {
1669
+ if (!results.length) return null;
1670
+ let currency;
1671
+ try {
1672
+ currency = results[0].outbound[0].providers[0].ticketOptions[0].currency;
1673
+ } catch (error) {
1674
+ currency = 'GBP';
1675
+ }
1676
+
1677
+ const price = this.findCheapestTicket(results);
1678
+ return {
1679
+ amount: price,
1680
+ currencyCode: currency
1681
+ };
1682
+ }
1683
+ findCheapestTicket(results: RailJourneyOptions[]): number {
1684
+ this._cheapestFirst = null;
1685
+ this._cheapestStandard = null;
1686
+ if (!results.length) return null;
1687
+ let cheapestArr: number[] = [];
1688
+
1689
+ results.map((result) => {
1690
+ result.outbound.map((out) => {
1691
+ out.providers.map((tkt) => {
1692
+ let cheapestTicket: number = tkt.ticketOptions[0].price;
1693
+ tkt.ticketOptions.map((tktOption) => {
1694
+ let tktPrice = tktOption.price;
1695
+ let tktClass = tktOption.class;
1696
+ if (
1697
+ tktClass === 'First' &&
1698
+ (this._cheapestFirst?.price > tktPrice || !this._cheapestFirst)
1699
+ ) {
1700
+ this._cheapestFirst = tktOption;
1701
+ } else if (
1702
+ tktClass === 'Standard' &&
1703
+ (this._cheapestStandard?.price > tktPrice ||
1704
+ !this._cheapestStandard)
1705
+ ) {
1706
+ this._cheapestStandard = tktOption;
1707
+ }
1708
+ if (tktPrice === cheapestTicket) {
1709
+ cheapestArr.push(cheapestTicket);
1710
+ }
1711
+ });
1712
+ });
1713
+ });
1714
+ });
1715
+ return Math.min(...cheapestArr);
1716
+ }
1717
+
1718
+ calculateTimeDifferenceInMins(
1719
+ railJourney: RailJourneyOption | RailSegment
1720
+ ): string {
1721
+ return this.helpers
1722
+ .getTimeDifference(railJourney.arriveDateTime, railJourney.departDateTime)
1723
+ .toString();
1724
+ }
1725
+
1726
+ /**
1727
+ * @description - determine if a ticket is an eTicket
1728
+ * @param ticket - the ticket we want to to check
1729
+ * @returns - boolean
1730
+ */
1731
+ ticketIsAnETicket(ticket: RailTicketOption): boolean {
1732
+ let foundETicket = null;
1733
+
1734
+ foundETicket = ticket.ticketQueueList.find((queueListItem) => {
1735
+ return queueListItem.type === 'eTicket';
1736
+ });
1737
+
1738
+ return foundETicket ? true : null;
1739
+ }
1740
+
1741
+ /**
1742
+ * @description - clear all of our chosen tickets/other rail stuff, call this when kicking off a new search
1743
+ */
1744
+ clearChosenTickets(): void {
1745
+ this._chosenInboundTicket = null;
1746
+ this._chosenOutboundTicket = null;
1747
+ this._chosenInboundJourney = null;
1748
+ this._chosenOutboundJourney = null;
1749
+ this._chosenTicketGroup = null;
1750
+ }
1751
+ }