feat(F-193): completed feature

This commit is contained in:
chattie
2026-08-23 07:58:50 +02:00
parent a372e5abfb
commit 4b3a506166
18 changed files with 244 additions and 37 deletions

View File

@@ -0,0 +1,72 @@
# F-193 — Implementer Evidence
## Feature
Show product expiry and shipping weight on storefront + authoritative variant weight in shipping.
## Changes
### 1. `project/migrations/057_product_variant_weight_and_expiry.js` (new)
Adds `weight_grams` column to `catalog_product_variants`:
- `integer`, nullable, no default
- CHECK: `weight_grams IS NULL OR weight_grams > 0`
- After `ean` column
### 2. `project/src/modules/catalog/domain/variant.ts`
Added `weightGrams` to `ProductVariant`, `NewProductVariant`, and `ProductVariantPatch`.
### 3. `project/src/modules/catalog/infrastructure/pg-variant-repository.ts`
- Added `weight_grams` to `VariantRow` interface
- Added `['weightGrams', 'weight_grams']` to `UPDATABLE` array
- Updated `create()` to INSERT `weight_grams`
- Updated `toVariant()` to map `weight_grams → weightGrams`
### 4. `project/src/modules/catalog/api/catalog.routes.ts`
- Added `weightGrams` to `newVariantSchema` (zod, optional, integer >= 1)
- Added `weightGrams` to `serializeVariant()` output
### 5. `project/src/modules/checkout/application/checkout-service.ts`
- Extended `getCartWeightKg` parameter type to include `variantId`
- Updated call site to pass full `cart.items` (no mapping needed)
### 6. `project/src/modules/checkout/api/checkout.routes.ts`
- Rewrote `getCartWeightKg` to:
- Fetch variant-level `weight_grams` from `catalog_product_variants`
- Fetch product-level `unit_weight_kg` as fallback
- Prefer variant weight (g → kg) when available
- Fall back to product weight (kg) when variant weight is null
### 7. `project/frontend/src/lib/api.ts`
- Added `weightGrams: number | null` to `ProductVariant` interface
### 8. `project/frontend/src/types/api.ts`
- Added `expirationDate?: string` to `Product` interface
### 9. `project/frontend/src/app/products/[slug]/page.tsx`
Added expiry date and weight display in the price box:
- `Caduca: {date}` — when `product.expirationDate` is set
- `Peso: {X.Y kg}` or `Peso: {X g}` — from `primaryVariant.weightGrams`
### Existing (no changes needed)
- `catalog_products.expiration_date` — already exists from migration 038
- `catalog_products.unit_weight_kg` — already exists as fallback
- `ShippingService` — already takes `cartWeightKg` and filters by `maxWeightKg`
- `serializeProduct()` — already serializes `expirationDate`
## Verification
| Check | Result |
|-------|--------|
| `npx tsc --noEmit` (backend) | 0 errors |
| `npx tsc --noEmit` (frontend) | 0 errors |
| `npm test` (backend) | 269 passed, 96 skipped |
| `./scripts/verify.sh` | OK |

View File

@@ -0,0 +1,8 @@
{
"agent": "leader",
"feature_id": "F-193",
"verdict": "APPROVED",
"summary": "F-193 closed: expiry + weight on storefront + authoritative variant weight in shipping. All gates APPROVED. verify.sh green.",
"gates": { "reviewer": true, "security": true, "qa": true, "close": true },
"closed_at": "2026-08-23T05:59:15Z"
}

View File

@@ -0,0 +1,14 @@
{
"agent": "qa",
"feature_id": "F-193",
"verdict": "APPROVED",
"summary": "QA trace: all ACs satisfied. Migration reversible. Domain types complete. API correct. Checkout weight calc updated. Frontend displays both fields.",
"checks": [
{ "id": "QA-1", "description": "AC1: Product page shows expiry and weight", "result": "PASS" },
{ "id": "QA-2", "description": "AC2: weight_grams editable via variant PATCH", "result": "PASS" },
{ "id": "QA-3", "description": "AC3: Checkout uses variant weight_grams (authoritative)", "result": "PASS" },
{ "id": "QA-4", "description": "AC4: Migration reversible; nullable; no data loss", "result": "PASS" },
{ "id": "QA-5", "description": "verify.sh green, tsc (backend+frontend) 0 errors, npm test 269 passed", "result": "PASS" }
],
"reviewed_at": "2026-08-23T05:59:05Z"
}

View File

@@ -0,0 +1,14 @@
{
"agent": "reviewer",
"feature_id": "F-193",
"verdict": "APPROVED",
"summary": "AC1-AC5 implemented. Migration 057 added. Domain types updated. API updated. Checkout weight calculation prefers variant-level weight. Frontend shows expiry and weight.",
"checks": [
{ "id": "RC-1", "description": "AC1: Frontend shows expiry date and weight when available", "result": "PASS", "note": "product/[slug]/page.tsx: expiryDate + weightGrams display added" },
{ "id": "RC-2", "description": "AC2: Admin can edit weight_grams via PATCH /products/:id/variants/:vid", "result": "PASS", "note": "UPDATABLE array includes weightGrams; zod schema includes it" },
{ "id": "RC-3", "description": "AC3: Shipping uses authoritative variant weight_grams", "result": "PASS", "note": "getCartWeightKg fetches variant weight_grams; falls back to unit_weight_kg" },
{ "id": "RC-4", "description": "AC4: Migration is reversible", "result": "PASS", "note": "057 has up/down; adds nullable column, no data loss" },
{ "id": "RC-5", "description": "tsc (backend+frontend) 0 errors, npm test 269 passed, verify.sh green", "result": "PASS" }
],
"reviewed_at": "2026-08-23T05:58:45Z"
}

View File

@@ -0,0 +1,14 @@
{
"agent": "security",
"feature_id": "F-193",
"verdict": "APPROVED",
"summary": "Security review: migration adds nullable integer column with CHECK constraint. No new attack surface. SQL fully parameterized. No new secrets or auth changes.",
"checks": [
{ "id": "SC-1", "description": "No new dependencies introduced", "result": "PASS" },
{ "id": "SC-2", "description": "No new auth or endpoint changes", "result": "PASS" },
{ "id": "SC-3", "description": "SQL fully parameterized", "result": "PASS", "note": "All queries use $N placeholders" },
{ "id": "SC-4", "description": "Migration adds nullable column; no data loss on up/down", "result": "PASS" },
{ "id": "SC-5", "description": "tsc (backend+frontend) 0 errors", "result": "PASS" }
],
"reviewed_at": "2026-08-23T05:58:55Z"
}