Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
fix: expose parameters for orders
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent fc877dd commit ef1f805
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/sections/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,6 @@ export enum ConditionSubtype {
Other = 'Other',
}

interface ListOrderParameters {
CreatedAfter?: Date
CreatedBefore?: Date
LastUpdatedAfter?: Date
LastUpdatedBefore?: Date
OrderStatus?: (keyof typeof OrderStatus)[]
MarketplaceId: string[]
FulfillmentChannel?: (keyof typeof FulfillmentChannel)[]
PaymentMethod?: (keyof typeof PaymentMethod)[]
BuyerEmail?: string
SellerOrderId?: string
MaxResultsPerPage?: number
EasyShipShipmentStatus?: (keyof typeof EasyShipShipmentStatus)[]
}

const orderStatus: Codec<OrderStatus> = oneOf(Object.values(OrderStatus).map((x) => exactly(x)))
const fulfillmentChannel: Codec<FulfillmentChannel> = oneOf(
Object.values(FulfillmentChannel).map((x) => exactly(x)),
Expand Down Expand Up @@ -299,9 +284,31 @@ const ListOrderItemsByNextTokenResponse = Codec.interface({
}),
})

type Order = GetInterface<typeof Order>
type ListOrders = GetInterface<typeof ListOrders>
type ListOrderItems = GetInterface<typeof ListOrderItems>
export type Order = GetInterface<typeof Order>
export type ListOrders = GetInterface<typeof ListOrders>
export type ListOrderItems = GetInterface<typeof ListOrderItems>

export interface GetOrderParameters {
AmazonOrderId: string[]
}
export interface ListOrderParameters {
CreatedAfter?: Date
CreatedBefore?: Date
LastUpdatedAfter?: Date
LastUpdatedBefore?: Date
OrderStatus?: (keyof typeof OrderStatus)[]
MarketplaceId: string[]
FulfillmentChannel?: (keyof typeof FulfillmentChannel)[]
PaymentMethod?: (keyof typeof PaymentMethod)[]
BuyerEmail?: string
SellerOrderId?: string
MaxResultsPerPage?: number
EasyShipShipmentStatus?: (keyof typeof EasyShipShipmentStatus)[]
}

export interface ListOrderItemsParameters {
AmazonOrderId: string
}

const canonicalizeParameters = (parameters: ListOrderParameters) => {
return {
Expand All @@ -323,12 +330,6 @@ const canonicalizeParameters = (parameters: ListOrderParameters) => {
export class Orders {
constructor(private httpClient: HttpClient) {}

/**
* If BuyerEmail is specified, then FulfillmentChannel,
* OrderStatus, PaymentMethod,
* LastUpdatedAfter, LastUpdatedBefore,
* and SellerOrderId cannot be specified.
*/
async listOrders(
parameters: RequireOnlyOne<ListOrderParameters, 'CreatedAfter' | 'LastUpdatedAfter'>,
): Promise<[ListOrders, RequestMeta]> {
Expand Down Expand Up @@ -367,7 +368,7 @@ export class Orders {
})
}

async getOrder(parameters: { AmazonOrderId: string[] }): Promise<[Order[], RequestMeta]> {
async getOrder(parameters: GetOrderParameters): Promise<[Order[], RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Orders,
version: ORDERS_API_VERSION,
Expand All @@ -385,14 +386,16 @@ export class Orders {
})
}

async listOrderItems(parameters: {
AmazonOrderId: string
}): Promise<[ListOrderItems, RequestMeta]> {
async listOrderItems(
parameters: ListOrderItemsParameters,
): Promise<[ListOrderItems, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Orders,
version: ORDERS_API_VERSION,
action: 'ListOrderItems',
parameters,
parameters: {
AmazonOrderId: parameters.AmazonOrderId,
},
})

return ListOrderItemsResponse.decode(response).caseOf({
Expand Down

0 comments on commit ef1f805

Please sign in to comment.