Repository navigation
Se pueden editar las categorías siendo Admin - #105
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 57 seconds. ⌛ 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: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughRecorridoSe añadió una operación de actualización de categorías de producto en el módulo admin: nuevo controlador y ruta PUT protegida, servicio con validación/normalización y reintento para compatibilidad de esquema Prisma, y pruebas unitarias actualizadas que cubren validación, 404 y flujo exitoso. Cambios
Diagrama de SecuenciasequenceDiagram
actor Cliente
participant Router as Enrutador (Rutas)
participant Ctrl as Controlador
participant Service as Servicio
participant DB as Prisma/BD
Cliente->>Router: PUT /api/admin/categories/:id
Router->>Router: authenticate + requireRole(ADMIN)
Router->>Ctrl: updateAdminProductCategory(req)
Ctrl->>Ctrl: validateId(req.params.id)
Ctrl->>Service: updateAdminProductCategoryService(id, body)
Service->>Service: validar y normalizar payload
Service->>DB: findUnique(where: id_product_category)
DB-->>Service: categoría o null
alt no existe
Service-->>Ctrl: lanza error 404
else existe
Service->>DB: update(where, data)
alt update falla por campo `description`
Service->>DB: update(where, data sin description)
DB-->>Service: resultado
else éxito
DB-->>Service: resultado
end
Service-->>Ctrl: retorna entidad serializada
end
Ctrl-->>Cliente: 200 JSON / 4xx
Esfuerzo Estimado de Revisión🎯 4 (Complex) | ⏱️ ~45 minutes Revisores Sugeridos
Poema
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/modules/admin/categories/admin-category.routes.js`:
- Around line 45-87: Fix the mojibake in the Swagger block by replacing the
bad-encoded word "categoría" with the correctly encoded "categoría" in the put
operation summary for the /api/admin/categories/{id} route; update any other
occurrences in that Swagger block (e.g., summary or description fields) and
ensure the file is saved in UTF-8 encoding so the accent renders properly in
generated docs.
In `@src/modules/admin/categories/admin-category.service.js`:
- Around line 80-85: The code silently drops payload.description for
ProductCategories (per prisma model) which breaks the API contract; instead,
when payload.description is provided (payload.description !== undefined) reject
the request with a ValidationError explaining that description is not a valid
field for ProductCategories; update the handling around payload.description and
the data.description assignment in admin-category.service.js (the block using
payload.description, data.description, and ValidationError) to validate presence
against the Prisma model and throw a clear ValidationError rather than
trimming/falling back to null so clients are not misled.
- Around line 113-132: The code reads updated.description after calling
prisma.productCategories.update(select: {...}) but the Prisma model
ProductCategories doesn't define description, so either add description to the
Prisma model and include it in the update/select or remove all references to
description from the update flow; specifically, if description is needed, add a
description field to the ProductCategories model in schema.prisma, run a
migration, then include description in the select of
prisma.productCategories.update and return it in the response (reference:
prisma.productCategories.update and updated.description), otherwise remove
description from the update payload/validation and from the response mapping
(remove updated.description ?? null) and any related validators/handlers that
expect it.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 35e8fd40-73ff-40a0-ac70-537b84cab2fd
📒 Files selected for processing (4)
src/modules/admin/categories/admin-category.controller.jssrc/modules/admin/categories/admin-category.routes.jssrc/modules/admin/categories/admin-category.service.jstests/unit/admin/admin-category.test.js
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/modules/admin/categories/admin-category.routes.js (1)
135-139:⚠️ Potential issue | 🟡 MinorCorregir mojibake en Swagger del PUT.
En Line 139 sigue apareciendo
categoríamal codificado; en la documentación se va a renderizar con caracteres rotos.Diff sugerido
- * summary: Editar categoría de productos (Admin) + * summary: Editar categoría de productos (Admin)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/modules/admin/categories/admin-category.routes.js` around lines 135 - 139, The Swagger JSDoc block for the PUT route "/api/admin/categories/{id}" has mojibake in the summary ("categoría"); update the summary string in the admin-category.routes.js Swagger comment for the PUT operation to the correct UTF-8 word "categoría" so the generated docs render properly (locate the JSDoc block for the PUT under /api/admin/categories/{id} and edit the summary line).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/modules/admin/categories/admin-category.routes.js`:
- Around line 135-139: The Swagger JSDoc block for the PUT route
"/api/admin/categories/{id}" has mojibake in the summary ("categoría"); update
the summary string in the admin-category.routes.js Swagger comment for the PUT
operation to the correct UTF-8 word "categoría" so the generated docs render
properly (locate the JSDoc block for the PUT under /api/admin/categories/{id}
and edit the summary line).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26f668de-fed5-415a-ac39-d2afca570252
📒 Files selected for processing (4)
src/modules/admin/categories/admin-category.controller.jssrc/modules/admin/categories/admin-category.routes.jssrc/modules/admin/categories/admin-category.service.jstests/unit/admin/admin-category.test.js
🚧 Files skipped from review as they are similar to previous changes (3)
- src/modules/admin/categories/admin-category.controller.js
- tests/unit/admin/admin-category.test.js
- src/modules/admin/categories/admin-category.service.js
Summary by CodeRabbit
Notas de Lanzamiento