Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. const generateStatePassenger = (total, field, callback) => {
  2. let data = {
  3. adult: [],
  4. child: [],
  5. infant: []
  6. };
  7. for (let i = 0; i < total; i++) {
  8. let title = "MR";
  9. if (field != "adult") {
  10. title = "MSTR";
  11. }
  12. data[field].push({
  13. titleIndex: 1,
  14. title: title,
  15. fullName: "",
  16. dateOfBirth: ""
  17. });
  18. }
  19. callback(data[field]);
  20. };
  21.  
  22. const generatePayloadTravelers = (
  23. field,
  24. value,
  25. dataPassenger,
  26. index,
  27. callback
  28. ) => {
  29. let validDob = true;
  30. let tempArr = [];
  31. dataPassenger[field].map((item, i) => {
  32. let tempObj = {};
  33. let salutation = i === index ? value : item.title;
  34. if (item.fullName !== "") {
  35. if (field !== "adult" && item.dateOfBirth === "") {
  36. validDob = false;
  37. alert("Please enter data correctly");
  38. } else {
  39. validDob = true;
  40. let dobb = item.dateOfBirth;
  41. if (field === "adult") {
  42. dobb = "1988-04-04";
  43. }
  44. getFirstNameLastname(item.fullName, res => {
  45. (tempObj.first_name = res.firstName),
  46. (tempObj.last_name = res.lastName);
  47. });
  48. (tempObj.birth_date = dobb), (tempObj.salutation = salutation);
  49. tempArr.push(tempObj);
  50. }
  51. }
  52. });
  53. const response = {
  54. validDob,
  55. tempArr
  56. };
  57. callback(response);
  58. };
  59.  
  60. const generatePayloadGuest = (field, value, dataPassenger, index, callback) => {
  61. let tempArr = [];
  62. dataPassenger[field].map((item, i) => {
  63. let tempObj = {};
  64. let salutation = i === index ? value : item.title;
  65. if (item.fullName !== "") {
  66. getFirstNameLastname(item.fullName, res => {
  67. (tempObj.first_name = res.firstName),
  68. (tempObj.last_name = res.lastName);
  69. });
  70. (tempObj.birth_date = "01-01-1990"), (tempObj.title = salutation);
  71. tempArr.push(tempObj);
  72. }
  73. });
  74. callback(tempArr);
  75. };
  76.  
  77. const generatePayloadPassenger = (
  78. field,
  79. value,
  80. dataPassenger,
  81. contact,
  82. index,
  83. callback
  84. ) => {
  85. let validDob = true;
  86. let tempArr = [];
  87. dataPassenger[field].map((item, i) => {
  88. let tempObj = {};
  89. let salutation = i === index ? value : item.title;
  90. if (item.fullName !== "") {
  91. if (field !== "adult" && item.dateOfBirth === "") {
  92. validDob = false;
  93. alert("Please enter data correctly");
  94. } else {
  95. validDob = true;
  96. let primaryData = false;
  97. let dobb = item.dateOfBirth;
  98. if (field === "adult") {
  99. if (i === 0) {
  100. primaryData = true;
  101. }
  102. dobb = "1988-04-04";
  103. }
  104. getFirstNameLastname(item.fullName, res => {
  105. (tempObj.first_name = res.firstName),
  106. (tempObj.last_name = res.lastName);
  107. });
  108. // item.dateOfBirth
  109. (tempObj.email = contact.email),
  110. (tempObj.phone = contact.phone),
  111. (tempObj.birth_date = dobb),
  112. (tempObj.primary = primaryData),
  113. (tempObj.salutation = salutation),
  114. (tempObj.type = field),
  115. (tempObj.seat = ""),
  116. (tempObj.nationality = "ID"),
  117. (tempObj.card_number = "123232323"),
  118. (tempObj.card_issue_date = "2017-01-01"),
  119. (tempObj.card_expire_date = "2022-01-01"),
  120. (tempObj.luggage = 1);
  121. tempArr.push(tempObj);
  122. }
  123. }
  124. });
  125. const response = {
  126. validDob,
  127. tempArr
  128. };
  129. callback(response);
  130. };
  131.  
  132. const payloadTour = (req, callback) => {
  133. let response = {
  134. tour: {
  135. trip_date_id: req.tour.trip_date.id,
  136. contact_detail: req.contact,
  137. travelers: req.travelers
  138. },
  139. addons: {
  140. hotel:
  141. req.hotel === null
  142. ? null
  143. : {
  144. check_in: "2020-02-17",
  145. check_out: "2020-02-18",
  146. rate_types: ["PAY_NOW"],
  147. rooms: [
  148. {
  149. num_of_adult: 2,
  150. guests: req.guest
  151. }
  152. ],
  153. search_id: "",
  154. affiliate_confirmation_ids: "",
  155. expected_total_chargeable_rates: {
  156. currency_code: "IDR",
  157. amount: 507000
  158. },
  159. user_contact: {
  160. phones: [req.contact.phone],
  161. email: req.contact.email,
  162. title: req.contact.salutation,
  163. first_name: req.guest[0].first_name,
  164. last_name: req.guest[0].last_name
  165. },
  166. affiliate_contact: {
  167. affiliate_phone_number: [req.contact.phone],
  168. affiliate_email: req.contact.email
  169. },
  170. user_payment_method: "",
  171. special_request: "",
  172. metadata: {
  173. customer_session_id: "",
  174. customer_ipaddress: "",
  175. customer_useragent: "mobile-traveloka",
  176. locale: "id_ID",
  177. currency_code: "IDR",
  178. client_interface: "DESKTOP_WEB"
  179. }
  180. },
  181. flight:
  182. req.flight === null
  183. ? null
  184. : {
  185. command: "BOOKING",
  186. product: "FLIGHT",
  187. data: {
  188. departure_code: req.flight.params.from.airport_code,
  189. partner_trxid: "PARTNER-001",
  190. arrival_code: req.flight.params.to.airport_code,
  191. date: req.flight.params.date,
  192. return_date: req.flight.params.date_return,
  193. adult: req.flight.params.passenger.adult,
  194. infant: req.flight.params.passenger.child,
  195. child: req.flight.params.passenger.infant,
  196. schedule_id: req.flight.departure_flight.schedule_id,
  197. return_schedule_id: req.flight.return_flight.schedule_id,
  198. class: "",
  199. sub_class: "",
  200. return_class: "",
  201. contact_detail: req.contact,
  202. passengers: req.passengers
  203. }
  204. }
  205. },
  206. tourId: req.tour.tour_package.id,
  207. propertyId: req.hotel === null ? "" : 71864,
  208. roomId: req.hotel === null ? "" : 11545762,
  209. apiKey: "4OGG3-U8RDM-29NXL-KYE6S-MWW15"
  210. };
  211. callback(response);
  212. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement