Skip to content

Conversation

lapa182
Copy link
Contributor

@lapa182 lapa182 commented May 25, 2021

What was done?

  • Add offer_request_id argument since it's required in the API to retrieve the offers list
  • Add max_connections and sort to OfferRequest types

@lapa182 lapa182 added the bug Something isn't working label May 25, 2021
@lapa182 lapa182 self-assigned this May 25, 2021
@lapa182 lapa182 requested a review from a team as a code owner May 25, 2021 15:40
@lapa182 lapa182 requested review from igorp1 and mcdeguzman99 and removed request for a team May 25, 2021 15:40
*/
public list = (options?: PaginationMeta): Promise<DuffelResponse<Offer[]>> =>
this.request({ method: 'GET', path: this.path, params: options })
public list = (offer_request_id: string, options?: ListOffersParams): Promise<DuffelResponse<Offer[]>> =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you thinking of putting offer_request_id inside the params object instead?

The benefit of the current way is that it makes this argument "required". But it will make Offers.list look inconsistent when compared to other list functions, which only have an options parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of having it separate since we are separating a mandatory argument, which is offer_request_id from the additional options (limit, sort, etc). Even so, it diverges from the others list functions, most of the developers would understand that. Happy to hear other thoughts too! @igorp1 @mcdeguzman99 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes the library's API a little harder to reason about personally, and it will make it harder in the future for us to automatically generate code snippets in the API reference. But I'm happy for you guys to make the call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would be to keep required fields explicit and separate, and to put all of the optional fields in options

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should go inside options to be consistent with the rest of the client library interface, but it should be a required argument.

When we have an id as a separate argument (usually in get functions), it's because it's the ID of the resource that we're referring to - e.g. if you do offers.get(id), you're passing in the offer's ID. In this case we're talking about the offer request ID. This is a different but related object. A similar example can be found in SeatMaps, where you get a seatmap not by its own ID, but by the related offer's ID. Hence the offer ID is passed in as a required parameter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! ❤️

@lapa182 lapa182 requested a review from andrejak May 26, 2021 08:51
Copy link
Contributor

@andrejak andrejak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought I submitted this comment yesterday, but looks like it was stuck in pending...

*/
public list = (options?: PaginationMeta): Promise<DuffelResponse<Offer[]>> =>
this.request({ method: 'GET', path: this.path, params: options })
public list = (offer_request_id: string, options?: ListOffersParams): Promise<DuffelResponse<Offer[]>> =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should go inside options to be consistent with the rest of the client library interface, but it should be a required argument.

When we have an id as a separate argument (usually in get functions), it's because it's the ID of the resource that we're referring to - e.g. if you do offers.get(id), you're passing in the offer's ID. In this case we're talking about the offer request ID. This is a different but related object. A similar example can be found in SeatMaps, where you get a seatmap not by its own ID, but by the related offer's ID. Hence the offer ID is passed in as a required parameter.

@lapa182 lapa182 requested a review from andrejak May 27, 2021 10:35
/**
* Retrieves a generator of all offers. The results may be returned in any order.
* @param {Object.<ListOffersParams>} params - Pagination options (optional: limit, after, before)
* @param {string} params.offer_request_id - Duffel's unique identifier for the offer request, returned when it was created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {string} params.offer_request_id - Duffel's unique identifier for the offer request, returned when it was created
* @param {string} offer_request_id - Duffel's unique identifier for the offer request, returned when it was created

Since it shouldn't actually be nested inside "params"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading about it and because it's nested inside params we need to define the previous object since we are deconstructing the object. Makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah ok, I read that as you need to have it as {params: {offer_request_id: ...}}

* Retrieves a page of offers. The results may be returned in any order.
* @param {Object} [options] - Pagination options (optional: limit, after, before)
* @param {Object.<ListOffersParams>} params - Pagination options (optional: limit, after, before)
* @param {string} params.offer_request_id - Duffel's unique identifier for the offer request, returned when it was created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {string} params.offer_request_id - Duffel's unique identifier for the offer request, returned when it was created
* @param {string} offer_request_id - Duffel's unique identifier for the offer request, returned when it was created

Copy link
Contributor

@igorp1 igorp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! And just to check... looks like there's enough consensus on this discussion, right?

@lapa182 lapa182 merged commit 7400810 into main May 27, 2021
@lapa182 lapa182 deleted the fix/UXP-858 branch May 27, 2021 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants