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

Commit

Permalink
feat: get lowest priced offers for sku
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 29, 2020
1 parent 2f8cc9e commit 599197c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
74 changes: 60 additions & 14 deletions src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,34 @@ export const GetLowestOfferListingsForASINResponse = Codec.interface({
* This has attributes instead of children, how do we handle that?
* http://docs.developer.amazonservices.com/en_CA/products/Products_Datatypes.html#OfferCount
*/
// const OfferCountType = number
const OfferCountType = Codec.interface({
OfferCount: number,
})

// const LowestPrice
const LowestPrice = Codec.interface({
LandedPrice: MoneyType,
ListingPrice: MoneyType,
Shipping: MoneyType,
Points: optional(Points),
})

// const Summary = Codec.interface({
// TotalOfferCount: number,
// NumberOfOffers: OfferCountType,
// LowestPrices: optional(ensureArray('LowestPrice', LowestPrice)),
// BuyBoxPrices: optional(ensureArray('BuyBoxPrice', BuyBoxPrice)),
// ListPrice: optional(MoneyType),
// SuggestedLowerPricePlusShipping: optional(MoneyType),
// BuyBoxEligibleOffers: optional(OfferCountType),
// OffersAvailableTime: optional(mwsDate)
// })
const BuyBoxPrice = Codec.interface({
LandedPrice: MoneyType,
ListingPrice: MoneyType,
Shipping: MoneyType,
Points: optional(Points),
})

const Summary = Codec.interface({
TotalOfferCount: number,
NumberOfOffers: OfferCountType,
LowestPrices: optional(ensureArray('LowestPrice', LowestPrice)),
BuyBoxPrices: optional(ensureArray('BuyBoxPrice', BuyBoxPrice)),
ListPrice: optional(MoneyType),
SuggestedLowerPricePlusShipping: optional(MoneyType),
BuyBoxEligibleOffers: optional(OfferCountType),
OffersAvailableTime: optional(mwsDate),
})

const Identifier = Codec.interface({
MarketplaceId: string,
Expand All @@ -234,19 +248,51 @@ const Identifier = Codec.interface({
TimeOfOfferChange: optional(mwsDate),
})

const SellerFeedbackRating = Codec.interface({
SellerPositiveFeedbackRating: optional(number),
FeedbackCount: number,
})

/**
* Does not have elements, but is defined by attributes
*/
const DetailedShippingTimeType = optional(unknown)

const ShipsFrom = Codec.interface({
State: optional(string),
Country: optional(string),
})

const Offer = Codec.interface({
MyOffer: optional(boolean),
SubCondition: string,
SellerFeedbackRating: optional(SellerFeedbackRating),
ShippingTime: DetailedShippingTimeType,
ListingPrice: MoneyType,
Points: optional(Points),
Shipping: MoneyType,
ShipsFrom: optional(ShipsFrom),
IsFulfilledByAmazon: boolean,
IsBuyBoxWinner: optional(boolean),
IsFeaturedMerchant: optional(boolean),
})

const GetLowestPricedOffersForSKU = Codec.interface({
Identifier,
Summary: unknown,
Offers: unknown,
Summary,
Offers: ensureArray('Offer', Offer),
})

export const GetLowestPricedOffersForSKUResponse = Codec.interface({
GetLowestPricedOffersForSKUResponse: Codec.interface({
GetLowestPricedOffersForSKUResult: GetLowestPricedOffersForSKU,
}),
})

/**
*
* Types derived from codecs
*
*/

export type GetMatchingProductForIdResponse = GetInterface<typeof GetMatchingProductForIdResponse>
Expand Down
23 changes: 14 additions & 9 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ Array [
"SellerSKU": "GE Product",
"TimeOfOfferChange": 2015-07-19T23:15:11.859Z,
},
"Offers": Object {
"Offer": Object {
"Offers": Array [
Object {
"IsBuyBoxWinner": true,
"IsFeaturedMerchant": true,
"IsFulfilledByAmazon": true,
Expand All @@ -409,6 +409,7 @@ Array [
"CurrencyCode": "USD",
},
"MyOffer": false,
"Points": undefined,
"SellerFeedbackRating": Object {
"FeedbackCount": 1,
"SellerPositiveFeedbackRating": 100,
Expand All @@ -418,15 +419,16 @@ Array [
"CurrencyCode": "USD",
},
"ShippingTime": "",
"ShipsFrom": undefined,
"SubCondition": "new",
},
},
],
"Summary": Object {
"BuyBoxEligibleOffers": Object {
"OfferCount": 1,
},
"BuyBoxPrices": Object {
"BuyBoxPrice": Object {
"BuyBoxPrices": Array [
Object {
"LandedPrice": Object {
"Amount": 32.99,
"CurrencyCode": "USD",
Expand All @@ -435,18 +437,19 @@ Array [
"Amount": 32.99,
"CurrencyCode": "USD",
},
"Points": undefined,
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
},
],
"ListPrice": Object {
"Amount": 58.34,
"CurrencyCode": "USD",
},
"LowestPrices": Object {
"LowestPrice": Object {
"LowestPrices": Array [
Object {
"LandedPrice": Object {
"Amount": 32.99,
"CurrencyCode": "USD",
Expand All @@ -455,15 +458,17 @@ Array [
"Amount": 32.99,
"CurrencyCode": "USD",
},
"Points": undefined,
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
},
],
"NumberOfOffers": Object {
"OfferCount": 1,
},
"OffersAvailableTime": undefined,
"SuggestedLowerPricePlusShipping": Object {
"Amount": 32.99,
"CurrencyCode": "USD",
Expand Down

0 comments on commit 599197c

Please sign in to comment.