refactor: tidy discount module and add cart summary#2
Conversation
Reformat discount.ts to use double quotes, arrow function, and JSDoc. Add cart.ts with CartLine/CartSummary types and a summarizeCart helper that wraps priceAfterDiscount across an array of line items.
|
/review |
| * @returns The price after applying the tier-appropriate discount | ||
| */ | ||
| export const priceAfterDiscount = ( | ||
| amount: number, |
There was a problem hiding this comment.
[warning] Removing the final return amount * multiplier statement will cause the priceAfterDiscount function to fail or return an incorrect value (e.g., undefined) because the calculated price is never returned.
ClearPR ReviewDiff stats: 108 raw lines → 81 semantic lines (25% noise filtered) Findings
|
|
@clearpr review |
ClearPR ReviewDiff stats: 108 raw lines → 81 semantic lines (25% noise filtered) Findings
|
| * @returns The price after applying the tier-appropriate discount | ||
| */ | ||
| export const priceAfterDiscount = ( | ||
| amount: number, |
There was a problem hiding this comment.
[critical] The function body for priceAfterDiscount appears to have been incorrectly modified. The line that calculates and returns the discounted price (return amount * multiplier) has been replaced by a type export (export type Tier = CustomerTier). This change breaks the functionality of the function, as it no longer computes or returns the expected number value.
|
@clearpr review |
ClearPR ReviewDiff stats: 108 raw lines → 81 semantic lines (25% noise filtered) Findings
|
| amount: number, | ||
| customerTier: CustomerTier, | ||
| ): number => { | ||
| if (amount < 0) { |
There was a problem hiding this comment.
[warning] The original return statement (return amount * multiplier) has been removed (indicated by the diff). This causes priceAfterDiscount to no longer calculate and return the discounted price, leading to a runtime error or incorrect result (likely returning undefined instead of a number).
| customerTier: CustomerTier, | ||
| ): number => { | ||
| if (amount < 0) { | ||
| return 0; |
There was a problem hiding this comment.
[warning] The line export type Tier = CustomerTier is misplaced immediately following the function definition block. While syntactically valid in some contexts, it suggests that a critical return statement was mistakenly replaced by an unrelated export, indicating a logic error regarding the function's intended output.
|
@clearpr review |
1 similar comment
|
@clearpr review |
ClearPR ReviewDiff stats: 108 raw lines → 81 semantic lines (25% noise filtered) Findings
|
| /** | ||
| * Apply tier-based discount to a price. | ||
| * | ||
| * @param amount - The original price before discount (must be non-negative) |
There was a problem hiding this comment.
[critical] The implementation appears to have removed or lost the final calculation and return statement (return amount * multiplier). The function's core purpose is to calculate and return the discounted price. If this logic is missing or improperly handled by the diff, the function will no longer perform its intended calculation.
|
@clearpr run |
ClearPR ReviewDiff stats: 108 raw lines → 81 semantic lines (25% noise filtered) Findings
|
| export const priceAfterDiscount = ( | ||
| amount: number, | ||
| customerTier: CustomerTier, | ||
| ): number => { |
There was a problem hiding this comment.
[warning] The removal of return amount * multiplier appears to break the function's core logic. The priceAfterDiscount function must return a number according to its signature. If this calculation is no longer needed here, please confirm how the final price is determined and ensure the function returns a valid value.
|
@clearpr run |
What
src/discount.ts: double quotes, arrow function, JSDoc,if/elseinstead ofswitch.src/cart.tswithCartLine,CartSummarytypes,computeSubtotal, andsummarizeCart.Why
Cleaning up the codebase ahead of the next milestone and laying down the cart-summary primitive that the upcoming checkout flow needs.
Test plan
tsc --noEmitpassessummarizeCartmath spot-checked against pen-and-paper for bronze/silver/gold tiers