feat: add promo code endpoint for applying percentage discounts#24
Open
Njko wants to merge 7 commits into
Open
feat: add promo code endpoint for applying percentage discounts#24Njko wants to merge 7 commits into
Njko wants to merge 7 commits into
Conversation
Generated by zava-workshop-kit/bin/bootstrap.sh. Repinning marketplace + workflow imports to your org.
The committed locks were built with compiler v0.71.5; the runtime now resolves gh-aw v0.76.1 and its frontmatter-hash check rejected the stale locks (ERR_CONFIG: lock file outdated). Recompiled both panels (0 errors) so pr-review-panel / triage-panel activate cleanly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
shared/apm.md defaults to target: all, which packs the global-only copilot-cowork harness; in isolated CI project scope apm 0.12.4 errors 'requires --global' and apm install exits 1. pr-review-panel.md already pins target: copilot for this reason — mirror it here so the triage fast path / daily sweep activate cleanly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Create new lib/promo.ts module with PromoCode type and validation functions - Add getPromoCode() to fetch codes from database with case-insensitive lookup - Add isPromoCodeValid() to validate code is active and within date range - Add calculateDiscount() to compute discount amount from percentage - Extend db module with getCart() and updateCartWithPromo() functions - Add POST /api/carts/:cartId/apply-promo endpoint with full validation: * 400 if request is malformed or promo code invalid/expired/not found * 404 if cart does not exist * Returns discount breakdown: percentage, amount, original total, new total - Add comprehensive unit tests for promo validation and discount calculation - Add integration test contract documentation for the endpoint Follows security baseline: - All database queries use parameterized statements ($1, $2, etc) - Input validation with Zod schema at request boundary - Error messages generic to clients, detailed logging for debugging - Case-insensitive promo code lookup with UPPER() in SQL All public functions documented with JSDoc including examples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add .eslintrc.json with next/core-web-vitals configuration for proper TypeScript and React linting in the project. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented
New Endpoint: POST /api/carts/:cartId/apply-promo
Applies a percentage discount to a cart using a promo code with full validation and discount tracking.
Request:
{ "promoCode": "SAVE10" }Success Response (200):
{ "cartId": "cart_123", "promoCode": "SAVE10", "discountPercentage": 10, "discountAmount": 1000, "originalTotal": 10000, "newTotal": 9000, "validFrom": "2026-01-01T00:00:00Z", "validUntil": "2026-12-31T23:59:59Z" }New Modules
Database Extensions
Validation & Error Handling
Security Baseline Compliance
✅ Input Handling
✅ Error Handling
Documentation Style Guide Compliance
✅ JSDoc Comments
Test Coverage
Unit Tests (25 total, all passing ✓)
promo.test.ts (9 tests):
apply-promo.test.ts (9 tests):
Existing Tests
Check Results
Branch
Guidelines Applied
Security Baseline (secure-coding-base.instructions.md)
Documentation Style Guide (docs-style-guide.instructions.md)
Ready for code review! All automated checks pass. ✅