feat(commerce): add product variants and size guide config#299
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR extends the product domain with support for variants (with dimensional overrides), product images with moderation status, and platform size guides. Input DTOs define nested validation contracts, the service refactors create and update flows into Prisma transactions, and a seeding script provisions default size guides. ChangesProduct variants, images, and size guides
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/backend/src/prisma/seed.ts (2)
14-17: ⚡ Quick winRename the seed constant to SCREAMING_SNAKE_CASE.
sizeGuidesToSeedshould follow the constants naming rule.Suggested change
-const sizeGuidesToSeed: Array<{ +const SIZE_GUIDES_TO_SEED: Array<{ type: GuideType; sizes: Prisma.InputJsonValue; }> = [ ... - for (const guide of sizeGuidesToSeed) { + for (const guide of SIZE_GUIDES_TO_SEED) {As per coding guidelines, "Use SCREAMING_SNAKE_CASE for enum values and constants".
Also applies to: 345-345
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/backend/src/prisma/seed.ts` around lines 14 - 17, Rename the constant sizeGuidesToSeed to SCREAMING_SNAKE_CASE (e.g., SIZE_GUIDES_TO_SEED) everywhere it's declared and referenced in the file (seed.ts) to follow the constants naming rule; update the const declaration and any uses of sizeGuidesToSeed (including the other occurrence around line 345) to the new NAME so imports/refs remain consistent.
344-344: ⚡ Quick winAvoid introducing new
console.login backend code.Use structured logging (
nestjs-pino/pino logger) instead ofconsole.logfor this new log line.As per coding guidelines, "Never use 'console.log' in production code — use NestJS Logger (pino) for backend, guarded development checks for frontend".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/backend/src/prisma/seed.ts` at line 344, Replace the console.log call that prints "Syncing platform size guides..." with a structured pino logger call: import pino (or use the existing nestjs-pino logger if available in this script), create/get a logger instance (e.g., const logger = pino() or use injected PinoLogger) and call logger.info('Syncing platform size guides...'); remove the console.log line so all backend logging uses pino/nestjs-pino instead.apps/backend/src/domains/commerce/product/dto/create-product.dto.ts (1)
131-143: ⚡ Quick winRename boolean fields to required prefixes.
includesFootwearanduseCustomSizesdon’t follow the backend boolean naming convention. Please rename them to prefixed forms (for examplehasFootwear/isUsingCustomSizes) for consistency across DTO/service contracts.As per coding guidelines, "All boolean field names must be prefixed with 'is', 'has', 'can', or 'should' (e.g. isActive, hasVariants)".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/backend/src/domains/commerce/product/dto/create-product.dto.ts` around lines 131 - 143, Rename the boolean fields in ProductSizeGuideConfigDto to follow boolean-prefix convention: change includesFootwear -> hasFootwear and useCustomSizes -> isUsingCustomSizes; update the property names and any related decorators/validation (`@IsOptional`, `@IsBoolean`) in the ProductSizeGuideConfigDto class and then update all usages (constructors, mappers, services, tests, serializers, API contracts) that read or write ProductSizeGuideConfigDto so they reference hasFootwear and isUsingCustomSizes instead of the old names to keep DTO/service contracts consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/backend/src/domains/commerce/product/product.service.ts`:
- Line 377: Replace the current logic that picks imageUrl from images[0] with
logic that finds the image marked isDefault; specifically, wherever imageUrl is
set from images[0] (the occurrences around the imageUrl assignment at lines
noted), change it to use images?.find(img => img.isDefault)?.url ?? null so the
primary image comes from the default flag and still safely falls back to null if
none exist; update both occurrences mentioned (the two imageUrl assignments) and
ensure you handle images being undefined or empty.
- Around line 567-596: When variants are rebuilt (productVariant.deleteMany +
this.createProductVariants) but images are left unchanged,
image.assignedVariantIds can reference deleted variant IDs; update the update
path in product.service.ts so that after creating new variants
(createProductVariants) and before keeping/creating images (createProductImages)
you either (a) clear assignedVariantIds on existing productImage records or (b)
remap/filter assignedVariantIds to only IDs present in the newly created
variants; implement this logic in the branch that handles variants !== null and
images === null (and the branch using createdVariants when images are provided)
by loading existing product images (tx.productImage.findMany) and updating their
assignedVariantIds with tx.productImage.updateMany / update to ensure no stale
variant IDs remain.
---
Nitpick comments:
In `@apps/backend/src/domains/commerce/product/dto/create-product.dto.ts`:
- Around line 131-143: Rename the boolean fields in ProductSizeGuideConfigDto to
follow boolean-prefix convention: change includesFootwear -> hasFootwear and
useCustomSizes -> isUsingCustomSizes; update the property names and any related
decorators/validation (`@IsOptional`, `@IsBoolean`) in the ProductSizeGuideConfigDto
class and then update all usages (constructors, mappers, services, tests,
serializers, API contracts) that read or write ProductSizeGuideConfigDto so they
reference hasFootwear and isUsingCustomSizes instead of the old names to keep
DTO/service contracts consistent.
In `@apps/backend/src/prisma/seed.ts`:
- Around line 14-17: Rename the constant sizeGuidesToSeed to
SCREAMING_SNAKE_CASE (e.g., SIZE_GUIDES_TO_SEED) everywhere it's declared and
referenced in the file (seed.ts) to follow the constants naming rule; update the
const declaration and any uses of sizeGuidesToSeed (including the other
occurrence around line 345) to the new NAME so imports/refs remain consistent.
- Line 344: Replace the console.log call that prints "Syncing platform size
guides..." with a structured pino logger call: import pino (or use the existing
nestjs-pino logger if available in this script), create/get a logger instance
(e.g., const logger = pino() or use injected PinoLogger) and call
logger.info('Syncing platform size guides...'); remove the console.log line so
all backend logging uses pino/nestjs-pino instead.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 32aac3f9-d1e7-47a6-bb0f-8d8e3dd5ff7b
📒 Files selected for processing (4)
apps/backend/src/domains/commerce/product/dto/create-product.dto.tsapps/backend/src/domains/commerce/product/dto/update-product.dto.tsapps/backend/src/domains/commerce/product/product.service.tsapps/backend/src/prisma/seed.ts
What does this PR do?
Implements B-11c — Product Variants + Size Guide Config. This extends the product flow with variant combination generation, image-to-variant assignment support, product size guide configuration, and idempotent seeding for all 7 platform-managed SizeGuide records.
Task
B-11c — Product: Variants + Size Guide Config
What changed
variantLabelbehaviorpriceOverridehandling wherenullfalls back toproduct.retailPriceKoboassignedVariantIdssupportassignedVariantIdsmeans image applies to all variantsproductSubCategoryis presentprisma/seed.tsto upsert all 7 platform SizeGuide records idempotentlyFiles changed
apps/backend/src/domains/commerce/product/dto/create-product.dto.tsapps/backend/src/domains/commerce/product/dto/update-product.dto.tsapps/backend/src/domains/commerce/product/product.service.tsapps/backend/src/prisma/seed.tsVerification
pnpm.cmd run lint— PASSnpx.cmd tsc --noEmit— PASSpnpm.cmd run build— PASSnpx.cmd prisma db seed— PASSSeed result
npx.cmd prisma db seedcompleted successfully.All 7 platform
SizeGuiderecords are upserted idempotently.The seed also printed an existing environment warning:
ADMIN_BOOTSTRAP_PASSWORDis missing, so admin creation was skipped. This is unrelated to B-11c.Scope control
POST /size-guidesendpoint added.env.localwas not staged or committedType of change
Area affected
How to test this
variantLabelvalues.assignedVariantIds.npx.cmd prisma db seed.Expected result:
priceOverride: nullfalls back to the product retail price.assignedVariantIdsapply to all variants.Pre-commit checklist
console.logleft in production code.envfiles committedanytypes addeddb pushScreenshots
N/A — backend-only PR. No UI changes.
Notes for reviewer
This task was originally assigned to Developer A but was handed over. The PR is intentionally scoped to B-11c only: variants, image assignment metadata, size guide config, and SizeGuide seed records.
Summary by CodeRabbit
Release Notes