-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d18fad0
commit 7c05006
Showing
17 changed files
with
242 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const { | ||
DEFAULT_CURRENCY = "NZD" | ||
} = process.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {listOrderItems, listOrderProducts} from "./list-order-items"; | ||
import {isOrderOfferItem} from "./is"; | ||
import {getOffer, DEFAULT_CURRENCY} from "../offer"; | ||
import {ok} from "../../is"; | ||
|
||
|
||
export async function getOrderPrice(orderId: string) { | ||
const items = await listOrderItems(orderId); | ||
const offerItems = items.filter(isOrderOfferItem); | ||
const offerIds = [...new Set( | ||
offerItems.map(item => item.offerId) | ||
)]; | ||
const offerQuantities = new Map( | ||
offerIds.map( | ||
offerId => { | ||
const matching = offerItems.filter(item => item.offerId === offerId); | ||
const quantity = matching.reduce( | ||
(sum, offer) => { | ||
return sum + (offer.quantity ?? 1); | ||
}, | ||
0 | ||
); | ||
return [offerId, quantity] as const; | ||
} | ||
) | ||
) | ||
const offers = await Promise.all( | ||
offerIds.map(offerId => getOffer(offerId)) | ||
); | ||
const offerMap = new Map( | ||
offers.map( | ||
offer => [offer.offerId, offer] as const | ||
) | ||
) | ||
const currencies = [...new Set( | ||
offers.map(item => item.currency || DEFAULT_CURRENCY) | ||
)]; | ||
// TODO if this is required... | ||
ok(currencies.length === 1, "Expected same currency across offers"); | ||
|
||
const price = offerIds.reduce( | ||
(sum, offerId) => { | ||
return sum + (offerQuantities.get(offerId) * (+offerMap.get(offerId).price)) | ||
}, | ||
0 | ||
) | ||
|
||
return { | ||
price, | ||
currency: currencies[0] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {OrderItem, OrderOfferItem, OrderProductItem} from "./types"; | ||
import {OfferItem, ProductOfferItem} from "../offer"; | ||
|
||
export function isOrderProductItem(item: OrderItem): item is OrderProductItem { | ||
return !!item.productId; | ||
} | ||
|
||
export function isOrderOfferItem(item: OrderItem): item is OrderOfferItem { | ||
return !!item.offerId; | ||
} | ||
|
||
export function isProductOfferItem(item: OfferItem): item is ProductOfferItem { | ||
return item.type === "product"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
// File generated by scripts/pre-build.js | ||
|
||
export const commit = "436cb724c806de87b61f94031282ef07934866eb"; | ||
export const commitShort = "436cb72"; | ||
export const commit = "d18fad03a5ca39ce42fb70d76c0aef5a313d14f1"; | ||
export const commitShort = "d18fad0"; | ||
export const commitAuthor = "Fabian Cook"; | ||
export const commitEmail = "[email protected]"; | ||
export const commitMessage = "1.0.0-alpha.25"; | ||
export const commitAt = "2023-06-18T10:50:23.000Z"; | ||
export const secondsBetweenCommitAndBuild = 590; | ||
export const minutesBetweenCommitAndBuild = 9.83; | ||
export const timeBetweenCommitAndBuild = "9 minutes and 49 seconds"; | ||
export const commitMessage = "1.0.0-alpha.26"; | ||
export const commitAt = "2023-06-18T11:01:05.000Z"; | ||
export const secondsBetweenCommitAndBuild = 44825.99; | ||
export const minutesBetweenCommitAndBuild = 747.1; | ||
export const timeBetweenCommitAndBuild = "747 minutes and 5 seconds"; | ||
// Variables to be replaced after tests | ||
export const secondsBetweenCommitAndTestCompletion = "629.48"; | ||
export const minutesBetweenCommitAndTestCompletion = "10.49"; | ||
export const timeBetweenCommitAndTestCompletion = "10 minutes and 29 seconds"; | ||
export const secondsBetweenCommitAndTestCompletion = "44838.79"; | ||
export const minutesBetweenCommitAndTestCompletion = "747.31"; | ||
export const timeBetweenCommitAndTestCompletion = "747 minutes and 18 seconds"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.