Skip to content

OM-318: correccion rabbit v5 - #113

Merged
CrisNAC merged 3 commits into
devfrom
OM-318
Apr 20, 2026
Merged

CrisNAC merged 3 commits into
devfrom
OM-318

Conversation

@leoAchu16

@leoAchu16 leoAchu16 commented Apr 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Mejorado el manejo de actualizaciones concurrentes en reportes de productos para evitar inconsistencias por cambios simultáneos.
    • Ahora las actualizaciones solo se aplican si el reporte está activo y coincide con el estado leído previamente, y además pertenecen al comercio correspondiente.
    • Cuando se detecta un conflicto de concurrencia se muestra un mensaje claro indicando que el reporte fue modificado por otro proceso y debe intentarse de nuevo.

@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2482bde9-9275-4d26-a790-ca269940b453

📥 Commits

Reviewing files that changed from the base of the PR and between 27a1ade and 9a1559f.

📒 Files selected for processing (1)
  • src/modules/global/reports/product/product-report.service.js

📝 Walkthrough

Walkthrough

Se ajusta updateProductReportService para usar validación de estado previo en la cláusula where, ampliar la condición para pertenencia a la tienda y envolver el prisma.update en try/catch; se detecta el error P2025 y se lanza un NotFoundError con mensaje de concurrencia. La función ahora retorna el updatedReport calculado internamente.

Cambios

Cohort / File(s) Summary
Servicio de reportes de producto
src/modules/global/reports/product/product-report.service.js
Se refina la cláusula where del prisma.productReports.update para requerir status: true, report_status: currentStatus y que pertenezca a la tienda del vendedor; la llamada de update está envuelta en try/catch. En caso de P2025 se lanza un NotFoundError indicando modificación por otro proceso; se asigna y retorna updatedReport. Atención a mensajes de error y a pruebas de concurrencia.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Cliente as Cliente
    participant Service as ProductReportService
    participant DB as PrismaDB
    rect rgba(100,150,240,0.5)
    Cliente->>Service: solicitar actualización de reporte (id, nuevos datos)
    Service->>DB: leer reporte actual (select)
    DB-->>Service: reporte con `currentStatus`, `fk_store`
    Service->>DB: update ... where { id, status: true, report_status: currentStatus, product.fk_store }
    alt update exitoso
      DB-->>Service: registro actualizado
      Service-->>Cliente: retorna `updatedReport`
    else P2025 (no rows afectadas)
      DB--xService: error P2025
      Service-->>Cliente: lanza NotFoundError ("modificado por otro proceso")
    else otro error
      DB--xService: error
      Service-->>Cliente: re-lanza error
    end
    end
Loading

Esfuerzo estimado de revisión de código

🎯 4 (Complexo) | ⏱️ ~45 minutos

PRs posiblemente relacionados

Revisores sugeridos

  • CrisNAC
  • SebaKisser

Poema

🐰 Salté entre filas y registros con destreza,
leí el estado primero, después intenté cambiar,
si otro saltó antes, dije con nobleza:
"NotFoundError — ya lo debes revisar",
y con zanahorias celebramos la concurrencia. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive El título es vago y genérico. Solo menciona "correccion rabbit v5" sin especificar claramente qué se corrigió o cuál es el cambio principal en el código. Reemplazar el título con una descripción más específica del cambio, por ejemplo: "OM-318: Add concurrency handling and store validation to product report updates" o similar en español que refleje claramente la adición de validaciones y manejo de errores.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch OM-318

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/global/reports/product/product-report.service.js`:
- Around line 168-202: The update is only guarded by id_product_report and
report_status, allowing a TOCTOU if the report gets deactivated or moved to
another store; fix it by extending the atomic where clause in
prisma.productReports.update to also require status: true and the product's
store match (e.g. add status: true and product: { fk_store: storeId } alongside
id_product_report: resolvedReportId and report_status: currentStatus), keeping
the same data/select and P2025 handling so the update fails if those conditions
changed.
🪄 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: 71f85c82-43d7-4392-832a-646ec22990b7

📥 Commits

Reviewing files that changed from the base of the PR and between 58fcd3b and 27a1ade.

📒 Files selected for processing (1)
  • src/modules/global/reports/product/product-report.service.js

Comment thread src/modules/global/reports/product/product-report.service.js
@CrisNAC
CrisNAC merged commit 5467ffe into dev Apr 20, 2026
1 of 3 checks passed
@Andoumeda
Andoumeda deleted the OM-318 branch April 23, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants