Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %dw 2.0
- output application/json
- type Currency = String {format: "###.00"}
- type Flight = Object {class: "com.mulesoft.training.Flight"}
- //var numSeats = 400
- //var numSeats = (x=400) -> x
- /*var numSeats = (planeType: String) ->
- if (planeType contains('737'))
- 150
- else
- 300
- */
- fun getNumSeats(planeType: String) =
- if (planeType contains('737'))
- 150
- else
- 300
- fun normalizeModelName (planeType: String) =
- planeType replace /Boing/ with "Boeing"
- ---
- using (flights =
- payload..*return map (object, index) -> {
- destination: object.destination,
- price: object.price as Number as Currency,
- totalSeats: getNumSeats(object.planeType as String),
- availableSeats: object.emptySeats,
- planeType: upper(normalizeModelName(object.planeType)),
- departureDate: object.departureDate
- as Date {format: "yyyy/MM/dd"}
- as String {format: "MMM dd, yyyy"}
- } as Flight
- )
- flights orderBy $.departureDate orderBy $.price
- distinctBy $ filter ($.availableSeats != "0")
Advertisement
Add Comment
Please, Sign In to add comment