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

Commit

Permalink
fix: add definitions for CanonicalizedSellerInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 3, 2020
1 parent 692af1b commit d0c8c9f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const mwsDate = Codec.custom<Date>({
decode: (x) =>
string.decode(x).chain((aString) => {
let toDecode = aString
// Temp fix. Add UTC if no letter is found in "param" passed
// Temp fix. Add UTC if no letter is found in string passed
// (crude way to check if time has timezone)
if (!/[A-Za-z]/g.test(aString)) {
toDecode += ' UTC+00:00'
}
Expand Down
48 changes: 39 additions & 9 deletions src/sections/merchant-fulfillment/type.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
// @todo define output on canonicalize functions
interface CanonicalizedSellerInputs {
AdditionalInputFieldName: string
AdditionalSellerInput: {
ValueAsString?: string
ValueAsBoolean?: boolean
ValueAsInteger?: number
ValueAsAddress?: Address
ValueAsWeight?: Weight
ValueAsTimestamp?: string
ValueAsDimension?: PackageDimensions
ValueAsCurrency?: CurrencyAmount
}
}

// @todo unit test both of these
export const canonicalizeAdditionalSellerInputs = (
inputList: AdditionalSellerInputs[] | undefined,
) => {
): CanonicalizedSellerInputs[] | undefined => {
return inputList?.map((input) => {
const { AdditionalInputFieldName, AdditionalSellerInput } = input
const {
ValueAsString,
ValueAsBoolean,
ValueAsInteger,
ValueAsAddress,
ValueAsWeight,
ValueAsTimestamp,
ValueAsDimension,
ValueAsCurrency,
} = AdditionalSellerInput

return {
AdditionalInputFieldName: input.AdditionalInputFieldName,
AdditionalInputFieldName,
AdditionalSellerInput: {
...input.AdditionalSellerInput,
ValueAsTimestamp: input.AdditionalSellerInput.ValueAsTimestamp?.toISOString(),
ValueAsString,
ValueAsBoolean,
ValueAsInteger,
ValueAsAddress,
ValueAsWeight,
ValueAsDimension,
ValueAsCurrency,
ValueAsTimestamp: ValueAsTimestamp?.toISOString(),
},
}
})
Expand All @@ -35,10 +64,11 @@ export const canonicalizeShipmentRequestDetails = (
const fixedInputsList = canonicalizeAdditionalSellerInputs(item.ItemLevelSellerInputsList)

return {
...item,
TransparencyCodeList: undefined,
OrderItemId: item.OrderItemId,
Quantity: item.Quantity,
ItemWeight: item.ItemWeight,
ItemDescription: item.ItemDescription,
'transparencyCodeList.member': item.TransparencyCodeList, // Lower case 't' because that's what' in the C# lib
ItemLevelSellerInputsList: undefined,
'ItemLevelSellerInputsList.member': fixedInputsList,
}
})
Expand Down

0 comments on commit d0c8c9f

Please sign in to comment.