|
| 1 | +import { PRICE_TYPE_OPTIONS } from "../../common/constants.mjs"; |
| 2 | +import { throwError } from "../../common/utils.mjs"; |
| 3 | +import limoexpress from "../../limoexpress.app.mjs"; |
| 4 | + |
| 5 | +export default { |
| 6 | + key: "limoexpress-create-booking", |
| 7 | + name: "Create Limo Booking", |
| 8 | + description: "Creates a new limo booking with specified details. [See the documentation](https://api.limoexpress.me/api/docs/v1#/Bookings/createBooking)", |
| 9 | + version: "0.0.1", |
| 10 | + type: "action", |
| 11 | + props: { |
| 12 | + limoexpress, |
| 13 | + bookingTypeId: { |
| 14 | + propDefinition: [ |
| 15 | + limoexpress, |
| 16 | + "bookingTypeId", |
| 17 | + ], |
| 18 | + }, |
| 19 | + bookingStatusId: { |
| 20 | + propDefinition: [ |
| 21 | + limoexpress, |
| 22 | + "bookingStatusId", |
| 23 | + ], |
| 24 | + optional: true, |
| 25 | + }, |
| 26 | + fromLocationName: { |
| 27 | + type: "string", |
| 28 | + label: "From Location Name", |
| 29 | + description: "The pickup location name.", |
| 30 | + }, |
| 31 | + fromLocationFullAddress: { |
| 32 | + type: "string", |
| 33 | + label: "From Location Full Address", |
| 34 | + description: "The pickup location full address.", |
| 35 | + }, |
| 36 | + fromLocationLatitude: { |
| 37 | + type: "string", |
| 38 | + label: "From Location Latitude", |
| 39 | + description: "The pickup location latitude.", |
| 40 | + optional: true, |
| 41 | + }, |
| 42 | + fromLocationLongitude: { |
| 43 | + type: "string", |
| 44 | + label: "From Location Longitude", |
| 45 | + description: "The pickup location longitude.", |
| 46 | + optional: true, |
| 47 | + }, |
| 48 | + toLocationName: { |
| 49 | + type: "string", |
| 50 | + label: "To Location Name", |
| 51 | + description: "The dropoff location name.", |
| 52 | + }, |
| 53 | + toLocationFullAddress: { |
| 54 | + type: "string", |
| 55 | + label: "To Location Full Address", |
| 56 | + description: "The dropoff location full address.", |
| 57 | + }, |
| 58 | + toLocationLatitude: { |
| 59 | + type: "string", |
| 60 | + label: "To Location Latitude", |
| 61 | + description: "The dropoff location latitude.", |
| 62 | + optional: true, |
| 63 | + }, |
| 64 | + toLocationLongitude: { |
| 65 | + type: "string", |
| 66 | + label: "To Location Longitude", |
| 67 | + description: "The dropoff location longitude.", |
| 68 | + optional: true, |
| 69 | + }, |
| 70 | + pickupTime: { |
| 71 | + type: "string", |
| 72 | + label: "Pickup Time", |
| 73 | + description: "The time scheduled for pickup. **Format: YYYY-MM-DD HH:MM:SS**", |
| 74 | + }, |
| 75 | + expectedDropOffTime: { |
| 76 | + type: "string", |
| 77 | + label: "Expected Drop Off Time", |
| 78 | + description: "The expected drop off time. **Format: YYYY-MM-DD HH:MM:SS**", |
| 79 | + optional: true, |
| 80 | + }, |
| 81 | + expectedComebackTime: { |
| 82 | + type: "string", |
| 83 | + label: "Expected Comeback Time", |
| 84 | + description: "The expected comeback time. **Format: YYYY-MM-DD HH:MM:SS**", |
| 85 | + optional: true, |
| 86 | + }, |
| 87 | + vehicleClassId: { |
| 88 | + propDefinition: [ |
| 89 | + limoexpress, |
| 90 | + "vehicleClassId", |
| 91 | + ], |
| 92 | + withLabel: true, |
| 93 | + optional: true, |
| 94 | + }, |
| 95 | + vehicleId: { |
| 96 | + propDefinition: [ |
| 97 | + limoexpress, |
| 98 | + "vehicleId", |
| 99 | + ({ vehicleClassId }) => ({ |
| 100 | + vehicleClassId: vehicleClassId.label, |
| 101 | + }), |
| 102 | + ], |
| 103 | + optional: true, |
| 104 | + }, |
| 105 | + price: { |
| 106 | + type: "string", |
| 107 | + label: "Price", |
| 108 | + description: "The price of the booking.", |
| 109 | + optional: true, |
| 110 | + }, |
| 111 | + priceType: { |
| 112 | + type: "string", |
| 113 | + label: "Price Type", |
| 114 | + description: "The type of price for the booking.", |
| 115 | + options: PRICE_TYPE_OPTIONS, |
| 116 | + optional: true, |
| 117 | + }, |
| 118 | + commissionAmount: { |
| 119 | + type: "string", |
| 120 | + label: "Commission Amount", |
| 121 | + description: "The commission amount for the booking.", |
| 122 | + optional: true, |
| 123 | + }, |
| 124 | + currencyId: { |
| 125 | + propDefinition: [ |
| 126 | + limoexpress, |
| 127 | + "currencyId", |
| 128 | + ], |
| 129 | + optional: true, |
| 130 | + }, |
| 131 | + vatPercentage: { |
| 132 | + type: "string", |
| 133 | + label: "VAT Percentage", |
| 134 | + description: "The VAT percentage for the booking.", |
| 135 | + optional: true, |
| 136 | + }, |
| 137 | + paymentMethodId: { |
| 138 | + propDefinition: [ |
| 139 | + limoexpress, |
| 140 | + "paymentMethodId", |
| 141 | + ], |
| 142 | + optional: true, |
| 143 | + }, |
| 144 | + distance: { |
| 145 | + type: "integer", |
| 146 | + label: "Distance", |
| 147 | + description: "Number of kilometers/miles that booking will take.", |
| 148 | + optional: true, |
| 149 | + }, |
| 150 | + duration: { |
| 151 | + type: "string", |
| 152 | + label: "Duration", |
| 153 | + description: "Number of hours and minutes that booking will take. **Format: HH:MM**", |
| 154 | + optional: true, |
| 155 | + }, |
| 156 | + paid: { |
| 157 | + type: "boolean", |
| 158 | + label: "Paid", |
| 159 | + description: "Flag that says is the booking paid or not.", |
| 160 | + optional: true, |
| 161 | + }, |
| 162 | + confirmed: { |
| 163 | + type: "boolean", |
| 164 | + label: "Confirmed", |
| 165 | + description: "Flag that says is the booking confirmed or not.", |
| 166 | + optional: true, |
| 167 | + }, |
| 168 | + roundTrip: { |
| 169 | + type: "boolean", |
| 170 | + label: "Round Trip", |
| 171 | + description: "Flag that says is the booking a round trip or not.", |
| 172 | + optional: true, |
| 173 | + }, |
| 174 | + note: { |
| 175 | + type: "string", |
| 176 | + label: "Note", |
| 177 | + description: "Note for the dispatcher.", |
| 178 | + optional: true, |
| 179 | + }, |
| 180 | + noteForDriver: { |
| 181 | + type: "string", |
| 182 | + label: "Note for Driver", |
| 183 | + description: "Note for the driver.", |
| 184 | + optional: true, |
| 185 | + }, |
| 186 | + flightNumber: { |
| 187 | + type: "string", |
| 188 | + label: "Flight Number", |
| 189 | + description: "Flight number for the booking.", |
| 190 | + optional: true, |
| 191 | + }, |
| 192 | + numOfWaitingHours: { |
| 193 | + type: "integer", |
| 194 | + label: "Number of Waiting Hours", |
| 195 | + description: "Number of waiting hours.", |
| 196 | + optional: true, |
| 197 | + }, |
| 198 | + clientId: { |
| 199 | + propDefinition: [ |
| 200 | + limoexpress, |
| 201 | + "clientId", |
| 202 | + ], |
| 203 | + optional: true, |
| 204 | + }, |
| 205 | + waitingBoardText: { |
| 206 | + type: "string", |
| 207 | + label: "Waiting Board Text", |
| 208 | + description: "Text that will be places on the waiting board.", |
| 209 | + optional: true, |
| 210 | + }, |
| 211 | + babySeatCount: { |
| 212 | + type: "integer", |
| 213 | + label: "Baby Seat Count", |
| 214 | + description: "Number of baby seats that will be used for the booking.", |
| 215 | + optional: true, |
| 216 | + }, |
| 217 | + suitcaseCount: { |
| 218 | + type: "integer", |
| 219 | + label: "Suitcase Count", |
| 220 | + description: "Number of suitcases that will be used for the booking.", |
| 221 | + optional: true, |
| 222 | + }, |
| 223 | + checkpoints: { |
| 224 | + type: "string[]", |
| 225 | + label: "Checkpoints", |
| 226 | + description: "List of objects of checkpoints location and time. **Format: [{\"location\": { \"name\": string, \"full_address\": string, \"coordinates\": { \"lat\": number, \"lng\": number } }, \"time\": \"01:14\"}]**", |
| 227 | + optional: true, |
| 228 | + }, |
| 229 | + passengers: { |
| 230 | + type: "string[]", |
| 231 | + label: "Passengers", |
| 232 | + description: "List of objects of passengers. **Format: [{\"first_name\": string, \"last_name\": string, \"phone\": string, \"email\": string, \"nationality\": string, \"passport\": string, \"country_id\": UUID }]", |
| 233 | + optional: true, |
| 234 | + }, |
| 235 | + }, |
| 236 | + async run({ $ }) { |
| 237 | + try { |
| 238 | + const response = await this.limoexpress.createBooking({ |
| 239 | + $, |
| 240 | + data: { |
| 241 | + booking_type_id: this.bookingTypeId, |
| 242 | + booking_status_id: this.bookingStatusId, |
| 243 | + from_location: { |
| 244 | + name: this.fromLocationName, |
| 245 | + full_address: this.fromLocationFullAddress, |
| 246 | + coordinates: { |
| 247 | + lat: this.fromLocationLatitude, |
| 248 | + lng: this.fromLocationLongitude, |
| 249 | + }, |
| 250 | + }, |
| 251 | + to_location: { |
| 252 | + name: this.toLocationName, |
| 253 | + full_address: this.toLocationFullAddress, |
| 254 | + coordinates: { |
| 255 | + lat: this.toLocationLatitude, |
| 256 | + lng: this.toLocationLongitude, |
| 257 | + }, |
| 258 | + }, |
| 259 | + pickup_time: this.pickupTime, |
| 260 | + expected_drop_off_time: this.expectedDropOffTime, |
| 261 | + expected_comeback_time: this.expectedComebackTime, |
| 262 | + vehicle_class_id: this.vehicleClassId.value, |
| 263 | + vehicle_id: this.vehicleId, |
| 264 | + price: this.price && parseFloat(this.price), |
| 265 | + price_type: this.priceType, |
| 266 | + commission_amount: this.commissionAmount && parseFloat(this.commissionAmount), |
| 267 | + currency_id: this.currencyId, |
| 268 | + vat_percentage: this.vatPercentage && parseFloat(this.vatPercentage), |
| 269 | + payment_method_id: this.paymentMethodId, |
| 270 | + distance: this.distance, |
| 271 | + duration: this.duration, |
| 272 | + paid: this.paid, |
| 273 | + confirmed: this.confirmed, |
| 274 | + round_trip: this.roundTrip, |
| 275 | + note: this.note, |
| 276 | + note_for_driver: this.noteForDriver, |
| 277 | + flight_number: this.flightNumber, |
| 278 | + num_of_waiting_hours: this.numOfWaitingHours, |
| 279 | + client_id: this.clientId, |
| 280 | + waiting_board_text: this.waitingBoardText, |
| 281 | + baby_seat_count: this.babySeatCount, |
| 282 | + suitcase_count: this.suitcaseCount, |
| 283 | + checkpoints: this.checkpoints, |
| 284 | + passengers: this.passengers, |
| 285 | + }, |
| 286 | + }); |
| 287 | + |
| 288 | + $.export("$summary", `Successfully created booking with ID ${response.data.id}`); |
| 289 | + return response; |
| 290 | + } catch ({ response }) { |
| 291 | + throwError(response); |
| 292 | + } |
| 293 | + }, |
| 294 | +}; |
0 commit comments