Skip to content

feat: add cart totals module and cat color helpers - #66

Open
tsah-baz wants to merge 1 commit into
mainfrom
test/prlc-4-mergerfirst
Open

feat: add cart totals module and cat color helpers#66
tsah-baz wants to merge 1 commit into
mainfrom
test/prlc-4-mergerfirst

Conversation

@tsah-baz

@tsah-baz tsah-baz commented Aug 4, 2026

Copy link
Copy Markdown

Adds a small cart totals module for the node example and colour helpers for the NestJS cats DTO.

Testing: exercised both modules by hand.

@baz-reviewer-dev

baz-reviewer-dev Bot commented Aug 4, 2026

Copy link
Copy Markdown

Generated description

Add cart calculation functions for subtotals, discounts, and final totals, with validation for discount percentages. Add cat color helpers to classify neutral colors and parse validated CatColor values.

Topics
TopicDetails
Cart totals Implement subtotal, applyDiscount, and total to calculate cart amounts and reject invalid discount percentages.
Modified files (1)
  • node/cart.js
Latest Contributors(1)
UserCommitDate
tsah@Tsahs-MacBook-Pro...feat: add cart totals ...August 04, 2026
Cat color helpers Add isNeutralColor and parseCatColor to classify white or gray cats and reject unknown color values.
Modified files (1)
  • typescript/nestjs/src/cats/dto/cat.model.ts
Latest Contributors(2)
UserCommitDate
tsah@Tsahs-MacBook-Pro...feat: add cart totals ...August 04, 2026
yuvalyacobyRevert "Revert 28 test...December 15, 2025

Merger

Needs Review

The new cart module uses ESM exports while node/package.json does not enable ESM, causing supported Node runtimes to fail on import; the unresolved NaN validation issue is also still present.

Commit f4199cd · Evaluated 2026-08-04 14:40 UTC


Review this PR on Baz | Customize your next review

@tsah-baz

tsah-baz commented Aug 4, 2026

Copy link
Copy Markdown
Author

@baz-reviewer-dev please summarize this PR

Comment thread node/cart.js
Comment on lines +1 to +2
export function subtotal(items) {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cart module fails on supported Node runtimes

cart.js uses ESM syntax but node/package.json doesn't declare "type": "module", so Node 18+ treats it as CommonJS and throws a syntax error on import — should we add "type": "module" or rewrite it as CommonJS?

Severity web_search

Want Baz to fix this for you? Activate Fixer

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In node/cart.js around
lines 1-14, the module uses ESM `export function ...` but the project’s
node/package.json likely doesn’t set ESM mode (no `

Comment thread node/cart.js
Comment on lines +6 to +8
if (percent < 0 || percent > 100) {
throw new RangeError("percent must be between 0 and 100");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NaN discount yields invalid totals

NaN passes both bounds checks since NaN < 0 and NaN > 100 are both false, so applyDiscount returns NaN and total exposes an invalid total — should we reject non-finite percentages with if (!Number.isFinite(percent) || percent < 0 || percent > 100)?

Severity

Want Baz to fix this for you? Activate Fixer

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In node/cart.js around
lines 6-8 inside the `applyDiscount(amount, percent)` function, the current range check
only handles values <0 or >100, so `percent = NaN` (or Infinity) bypasses the
comparisons and results in a `NaN` total. Refactor the guard to explicitly reject
non-finite percentages by adding a `Number.isFinite(percent)` check (and keep the
existing 0–100 bounds), then ensure the function throws a clear error for NaN/Infinity
as well as out-of-range numbers. Add/update a small unit test (or minimal coverage) to
assert that `total(items, NaN)` and `total(items, Infinity)` throw instead of returning
`NaN`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant