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

Commit

Permalink
feat: made listInboundShipmentItems
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 15, 2020
1 parent a4cb1be commit 35155be
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/sections/fulfillment-inbound-shipment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,27 @@ export const ListInboundShipmentsByNextTokenResponse = Codec.interface({
ListInboundShipmentsByNextTokenResult: ListInboundShipmentsByNextToken,
}),
})

const InboundShipmentItem = Codec.interface({
ShipmentId: optional(ensureString),
SellerSKU: string,
FulfillmentNetworkSKU: optional(string),
QuantityShipped: number,
QuantityReceived: optional(number),
QuantityInCase: optional(number),
PrepDetailsList: optional(ensureArray('PrepDetails', PrepDetails)),
ReleaseDate: optional(string),
})

const ListInboundShipmentItems = Codec.interface({
NextToken: optional(nextTokenCodec('ListInboundShipmentItems')),
ItemData: ensureArray('member', InboundShipmentItem),
})

export type ListInboundShipmentItems = GetInterface<typeof ListInboundShipmentItems>

export const ListInboundShipmentItemsResponse = Codec.interface({
ListInboundShipmentItemsResponse: Codec.interface({
ListInboundShipmentItemsResult: ListInboundShipmentItems,
}),
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
GetTransportContentResponse,
GetUniquePackageLabels,
GetUniquePackageLabelsResponse,
ListInboundShipmentItems,
ListInboundShipmentItemsResponse,
ListInboundShipments,
ListInboundShipmentsByNextToken,
ListInboundShipmentsByNextTokenResponse,
Expand Down Expand Up @@ -64,6 +66,7 @@ import {
GetPrepInstructionsForSKUParameters,
GetTransportContentParameters,
GetUniquePackageLabelsParameters,
ListInboundShipmentItemsParameters,
ListInboundShipmentsParameters,
PutTransportContentParameters,
VoidTransportRequestParameters,
Expand All @@ -74,13 +77,35 @@ const FULFILLMENT_INBOUND_SHIPMENT_API_VERSION = '2010-10-01'
export class FulfillmentInboundShipment {
constructor(private httpClient: HttpClient) {}

async listInboundShipmentItems(
parameters: ListInboundShipmentItemsParameters,
): Promise<[ListInboundShipmentItems, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'ListInboundShipmentItems',
parameters: {
ShipmentId: parameters.ShipmentId,
LastUpdatedAfter: parameters.LastUpdatedAfter?.toISOString(),
LastUpdatedBefore: parameters.LastUpdatedBefore?.toISOString(),
},
})

return ListInboundShipmentItemsResponse.decode(response).caseOf({
Right: (x) => [x.ListInboundShipmentItemsResponse.ListInboundShipmentItemsResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async listInboundShipmentsByNextToken(
nextToken: NextToken<'ListInboundShipments'>,
): Promise<[ListInboundShipmentsByNextToken, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentInboundShipment,
version: FULFILLMENT_INBOUND_SHIPMENT_API_VERSION,
action: 'ListInboundShipments',
action: 'ListInboundShipmentsByNextToken',
parameters: {
NextToken: nextToken.token,
},
Expand Down
9 changes: 9 additions & 0 deletions src/sections/fulfillment-inbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,12 @@ export interface ListInboundShipmentsParameters {
LastUpdatedAfter?: Date
LastUpdatedBefore?: Date
}

export type ListInboundShipmentItemsParameters = RequireOnlyOne<
{
ShipmentId?: string
LastUpdatedAfter?: Date
LastUpdatedBefore?: Date
},
'ShipmentId' | 'LastUpdatedAfter'
>
33 changes: 33 additions & 0 deletions test/unit/__snapshots__/fulfillment-inbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,39 @@ Array [
]
`;

exports[`fulfillmentInboundShipment listInboundShipmentItems returns list of item data if succesful 1`] = `
Array [
Object {
"ItemData": Array [
Object {
"FulfillmentNetworkSKU": "B000FADVPQ",
"QuantityInCase": 0,
"QuantityReceived": 0,
"QuantityShipped": 3,
"ReleaseDate": "2014-12-31",
"SellerSKU": "SampleSKU1",
"ShipmentId": "SSF85DGIZZ3OF1",
},
Object {
"FulfillmentNetworkSKU": "B0011VECH4",
"QuantityInCase": 0,
"QuantityReceived": 0,
"QuantityShipped": 10,
"SellerSKU": "SampleSKU2",
"ShipmentId": "SSF85DGIZZ3OF1",
},
],
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentInboundShipment listInboundShipments returns shipment data if succesful 1`] = `
Array [
Object {
Expand Down

0 comments on commit 35155be

Please sign in to comment.