Repository navigation
OM-356: modificar cantidades y eliminar productos del carrito. - #82
Conversation
📝 WalkthroughWalkthroughSe agrega funcionalidad para eliminar y actualizar la cantidad de artículos del carrito mediante dos nuevos servicios, controladores y rutas autenticadas. Incluye validación de permisos, verificación de inventario y pruebas unitarias exhaustivas para servicios de carrito y órdenes. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (4)
src/modules/users/cart/cart.service.js (2)
295-330: LGTM - El servicioremoveCartItemServiceestá bien implementado.La lógica de validación de pertenencia del item al carrito del usuario autenticado y el borrado lógico están correctamente implementados.
Nit menor: La variable
updateden la línea 323 no se utiliza. Podés simplificar la llamada.♻️ Eliminar variable no utilizada
//se aplica el borrado logico del item - const updated = await prisma.cartItems.update({ + await prisma.cartItems.update({ where: { id_cart_item: resolvedCartItemId }, data: { status: false } });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/modules/users/cart/cart.service.js` around lines 295 - 330, The variable `updated` in removeCartItemService is unused; remove the unnecessary assignment by calling prisma.cartItems.update(...) without assigning its result (or await it inline if needed) — keep the await to ensure the logical delete completes before calling getCartWithItems(cartItem.fk_cart); update the removeCartItemService function to drop the `updated` identifier and simply await prisma.cartItems.update({ where: { id_cart_item: resolvedCartItemId }, data: { status: false } }); before calling getCartWithItems and mapCartResponse.
337-376: El nombre de la función debería usar el verbo en presente.La función
updatedCartItemQuantityServiceusa el participio pasado "updated". Para mantener consistencia con los demás servicios (addCartItemService,removeCartItemService,getCartItemsByIdService), debería llamarseupdateCartItemQuantityService.♻️ Renombrar función para consistencia
-export const updatedCartItemQuantityService = async (authenticatedUserId, cartItemId, newQuantity) => { +export const updateCartItemQuantityService = async (authenticatedUserId, cartItemId, newQuantity) => {Nota: Recordá actualizar también el import y la llamada en
cart.controller.js.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/modules/users/cart/cart.service.js` around lines 337 - 376, The function name uses past participle; rename exported function updatedCartItemQuantityService to updateCartItemQuantityService and update all references: change the exported identifier in src/modules/users/cart/cart.service.js, update any imports and calls (e.g., in cart.controller.js) to the new name, and keep the internal logic, signature (authenticatedUserId, cartItemId, newQuantity) and related helpers (parsePositiveInteger, getCartWithItems, mapCartResponse) unchanged so existing behavior and tests remain intact.src/modules/users/cart/cart.controller.js (1)
1-6: Nota: Actualizar el nombre del import si se renombra el servicio.El import de
updatedCartItemQuantityServicedeberá actualizarse si se aplica el refactor de nombre sugerido en el servicio.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/modules/users/cart/cart.controller.js` around lines 1 - 6, El import en cart.controller.js aún referencia updatedCartItemQuantityService; si en cart.service.js renombraste la función (por ejemplo a updateCartItemQuantityService), actualiza la importación en la lista de imports (la declaración que incluye addCartItemService, getActiveCartsForUserService, getCartItemsByIdService, removeCartItemService, updatedCartItemQuantityService) para usar el nuevo identificador exacto que exporta cart.service.js, y verifica que todas las referencias en este archivo usen ese mismo nombre.tests/unit/order/order.test.js (1)
364-394: Los tests de filtros podrían ser más específicos.Los tests para filtros por
order_statusy rango de fechas solo verifican que$transactionfue llamado, pero no validan que los filtros se aplicaron correctamente en el query. Esto es aceptable para tests unitarios básicos, pero podrías considerar agregar assertions más específicas en el futuro.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/order/order.test.js` around lines 364 - 394, The tests currently only assert prisma.$transaction was called; improve them by inspecting the actual query arguments passed into the mocked prisma.$transaction to verify the filters are built correctly: after calling getStoreOrdersService, read prisma.$transaction.mock.calls[0][0] (the transaction array) and locate the orders findMany call (e.g., the first element used as findManyCall), then assert that its 'where' contains the expected order_status conditions (single value or array for comma-separated statuses) and that the date range produces a created_at (or appropriate field) filter with gte/lte for date_from/date_to; update the three tests to include these specific expect checks referencing getStoreOrdersService and prisma.$transaction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/modules/users/cart/cart.controller.js`:
- Around line 1-6: El import en cart.controller.js aún referencia
updatedCartItemQuantityService; si en cart.service.js renombraste la función
(por ejemplo a updateCartItemQuantityService), actualiza la importación en la
lista de imports (la declaración que incluye addCartItemService,
getActiveCartsForUserService, getCartItemsByIdService, removeCartItemService,
updatedCartItemQuantityService) para usar el nuevo identificador exacto que
exporta cart.service.js, y verifica que todas las referencias en este archivo
usen ese mismo nombre.
In `@src/modules/users/cart/cart.service.js`:
- Around line 295-330: The variable `updated` in removeCartItemService is
unused; remove the unnecessary assignment by calling
prisma.cartItems.update(...) without assigning its result (or await it inline if
needed) — keep the await to ensure the logical delete completes before calling
getCartWithItems(cartItem.fk_cart); update the removeCartItemService function to
drop the `updated` identifier and simply await prisma.cartItems.update({ where:
{ id_cart_item: resolvedCartItemId }, data: { status: false } }); before calling
getCartWithItems and mapCartResponse.
- Around line 337-376: The function name uses past participle; rename exported
function updatedCartItemQuantityService to updateCartItemQuantityService and
update all references: change the exported identifier in
src/modules/users/cart/cart.service.js, update any imports and calls (e.g., in
cart.controller.js) to the new name, and keep the internal logic, signature
(authenticatedUserId, cartItemId, newQuantity) and related helpers
(parsePositiveInteger, getCartWithItems, mapCartResponse) unchanged so existing
behavior and tests remain intact.
In `@tests/unit/order/order.test.js`:
- Around line 364-394: The tests currently only assert prisma.$transaction was
called; improve them by inspecting the actual query arguments passed into the
mocked prisma.$transaction to verify the filters are built correctly: after
calling getStoreOrdersService, read prisma.$transaction.mock.calls[0][0] (the
transaction array) and locate the orders findMany call (e.g., the first element
used as findManyCall), then assert that its 'where' contains the expected
order_status conditions (single value or array for comma-separated statuses) and
that the date range produces a created_at (or appropriate field) filter with
gte/lte for date_from/date_to; update the three tests to include these specific
expect checks referencing getStoreOrdersService and prisma.$transaction.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 37e7867e-264d-4143-8e92-bcf6a51c6eb3
📒 Files selected for processing (5)
src/modules/users/cart/cart.controller.jssrc/modules/users/cart/cart.routes.jssrc/modules/users/cart/cart.service.jstests/unit/cart/cart.test.jstests/unit/order/order.test.js
Summary by CodeRabbit
Notas de lanzamiento
Nuevas Funcionalidades