Skip to content

Commit

Permalink
Remove unecessary optional checks (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: José Carneiro <[email protected]>
  • Loading branch information
josecarneiro and José Carneiro authored Jan 2, 2025
1 parent 1bb7ac1 commit ffd8e97
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export const computePriceComponent = (
priceItemComponent: PriceItemDto,
priceItem: CompositePriceItemDto,
): PriceItem => {
const tax = priceItemComponent?.taxes?.[0]?.tax;
const tax = priceItemComponent.taxes?.[0]?.tax;
const priceMapping = priceItem.price_mappings?.find(({ price_id }) => priceItemComponent._price!._id === price_id);

const externalFeeMapping = priceItem.external_fees_mappings?.find(
({ price_id }) => priceItemComponent._price!._id === price_id,
);

const safeQuantity = isNaN(priceItemComponent?.quantity!) ? 1 : priceItemComponent?.quantity;
const safeQuantity = isNaN(priceItemComponent.quantity!) ? 1 : priceItemComponent.quantity;
const safeParentQuantity = isNaN(priceItem.quantity!) ? 1 : priceItem.quantity!;
const quantity = toDinero(String(safeQuantity)).multiply(safeParentQuantity).toUnit();

Expand Down Expand Up @@ -146,8 +146,8 @@ const ensureComponentWithValidPrice = (itemComponent: PriceItemDto): PriceItemDt
});

const getPriceComponents = (priceItem: CompositePriceItemDto): PriceComponent[] => {
if (!Array.isArray(priceItem?.item_components)) {
return Array.isArray(priceItem?._price?.price_components)
if (!Array.isArray(priceItem.item_components)) {
return Array.isArray(priceItem._price?.price_components)
? priceItem._price!.price_components.filter(isValidPrice)
: [];
}
Expand Down

0 comments on commit ffd8e97

Please sign in to comment.