Skip to content

PR: cursor_new_oma_req_review → cursor_new_oma_req - #69

Merged
IM-Agents merged 1 commit into
cursor_new_oma_reqfrom
cursor_new_oma_req_review
May 5, 2026
Merged

PR: cursor_new_oma_req_review → cursor_new_oma_req#69
IM-Agents merged 1 commit into
cursor_new_oma_reqfrom
cursor_new_oma_req_review

Conversation

@IM-Agents

@IM-Agents IM-Agents commented May 5, 2026

Copy link
Copy Markdown
Owner

Auto-generated PR from branch cursor_new_oma_req_review into cursor_new_oma_req.

Created by n8n automation.

Summary by CodeRabbit

Release Notes

  • Improvements
    • Enhanced internal logging for print operations and delivery processing to improve system diagnostics and troubleshooting capabilities.

@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds debug logging statements across multiple backend controllers and services (printJobController, webhookController, timelineService) and registers a duplicate PDF download route. However, the retryDepartmentPrint logging references variables before they are declared, creating a runtime error.

Changes

Debug Logging & Route Registration

Layer / File(s) Summary
Core Logging in Controllers
backend/src/controllers/printJobController.js, backend/src/services/timelineService.js
triggerDepartmentPrint logs before calling timeline service; retryDepartmentPrint logs console output before destructuring order_id and department from req.params (causes undefined reference). logPrinterValidationFailed adds console logging of validation inputs.
Webhook Debug Logging
backend/src/controllers/webhookController.js
parseDeliveryDate logs the split parts array; extractDeliveryInfo logs each normalized attribute name during iteration.
Route Registration
backend/src/routes/orderRoutes.js
A duplicate route registration for GET /:order_id/departments/:department/download-pdf is added, creating a redundant endpoint handler mapping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • IM-Agents/Pravin-AI-2026#68: Both PRs modify the same controller, route, webhook, and timelineService logging—e.g., both change printJobController.triggerDepartmentPrint logging and duplicate the download-pdf route.

Poem

🐰 Logs are flowing, debugging deep,
But watch where variables leap!
Before you claim them, don't refer,
Or runtime errors will surely stir.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
Oma Monorepo Quality (Frontend, Backend, Desktop) ❌ Error printJobController.js has TDZ error (line 59 references undeclared variables). webhookController.js logs PII. Duplicate routes in orderRoutes.js. Move console.log after variable declaration. Remove PII logs or log metadata only. Remove duplicate route registrations.
Title check ⚠️ Warning The title 'PR: cursor_new_oma_req_review → cursor_new_oma_req' is a branch name annotation that doesn't describe the actual changes made. It appears to be auto-generated and doesn't convey what the PR implements (debug logging additions and a duplicate route). Replace the title with a descriptive summary of the actual changes, such as 'Add debug logging to print and webhook controllers' or 'Add debug logging and fix duplicate PDF download route'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 cursor_new_oma_req_review

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@backend/src/controllers/printJobController.js`:
- Around line 59-60: The console.log in printJobController.js is reading
order_id and department before they are declared, causing a TDZ ReferenceError;
move the console.log statement to after the destructuring assignment "const {
order_id, department } = req.params" (or destructure into locals earlier in the
function handling retries, e.g., inside retryDepartmentPrint handler) so the log
uses the declared variables, and ensure any other uses of order_id/department in
retryDepartmentPrint reference the same destructured variables.

In `@backend/src/controllers/webhookController.js`:
- Line 30: The console.log call that prints 'extractDeliveryInfo' along with
noteAttributes and lineItems exposes customer PII (addresses, emails, phones);
remove that raw debug log and replace it with a non-PII-safe log (e.g., log only
counts or presence flags) or mask/redact sensitive fields before logging;
specifically update the console.log('extractDeliveryInfo', noteAttributes,
lineItems) invocation (or within the extractDeliveryInfo code path) to emit only
metadata such as noteAttributes length, lineItems length, or a boolean
hasDeliveryInfo, or call a central maskPII helper to redact emails/phones before
any logging.

In `@backend/src/routes/orderRoutes.js`:
- Around line 14-16: Duplicate GET route registrations for
'/:order_id/departments/:department/download-pdf' were added using router.get
and printJobController.downloadDepartmentPdf; remove the extra two registrations
and keep a single router.get('/:order_id/departments/:department/download-pdf',
printJobController.downloadDepartmentPdf) to avoid ambiguous routing (ensure
only one occurrence remains and that the router export is unchanged).
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 297004e1-ad60-45f6-bb43-45843330438b

📥 Commits

Reviewing files that changed from the base of the PR and between 889c04c and cc9a4c8.

📒 Files selected for processing (4)
  • backend/src/controllers/printJobController.js
  • backend/src/controllers/webhookController.js
  • backend/src/routes/orderRoutes.js
  • backend/src/services/timelineService.js
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
backend/src/**/*.{js,ts}

📄 CodeRabbit inference engine (Custom checks)

backend/src/**/*.{js,ts}: Backend source code must not contain hardcoded credentials, Shopify webhook secrets, or database passwords (must use env variables and config/env.js patterns)
Backend webhook routes must not skip or weaken HMAC or Shopify authentication validation
Backend code must not build SQL queries by concatenating untrusted strings; must use parameterized queries or ORM usage
Backend async routes and services must implement proper error handling with next(err) or structured error responses instead of swallowing errors

Files:

  • backend/src/services/timelineService.js
  • backend/src/controllers/webhookController.js
  • backend/src/routes/orderRoutes.js
  • backend/src/controllers/printJobController.js
**/*.{js,mjs,cjs,ts,tsx,jsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/README.md)

**/*.{js,mjs,cjs,ts,tsx,jsx,vue}: Follow JS/TS language rules: modules, async patterns, TypeScript usage, error handling, and platform considerations
Follow JavaScript/TypeScript architectural patterns: structure, async flow, React habits, and anti-pattern avoidance

Files:

  • backend/src/services/timelineService.js
  • backend/src/controllers/webhookController.js
  • backend/src/routes/orderRoutes.js
  • backend/src/controllers/printJobController.js
backend/src/**/*.js

⚙️ CodeRabbit configuration file

backend/src/**/*.js: This path is the Node.js + Express API, MySQL access, Shopify webhooks, PDF/print services, and Socket.IO server for OMA. Blocking rules for changed lines:

  • Configuration must come from backend/src/config/env.js and environment variables—do not hardcode DB passwords, Shopify secrets, or deployment-specific hosts in source.
  • Webhook and HMAC-sensitive routes must remain protected by the existing Shopify auth middleware (shopifyAuth / HMAC validation); do not bypass verification for convenience.
  • Async route handlers and services must propagate errors to Express (next(err) or throw into async wrappers) or handle them explicitly—no empty catch blocks that hide failures.
  • Database access must use parameterized queries / the existing models layer—no string-concatenated SQL with user-controlled input.
  • New Socket.IO handlers must handle errors and avoid leaking internal stack traces to clients in production.
  • No new dependencies on eval, child_process with untrusted input, or disabling security middleware without strong justification.
  • Prefer backend/src/services/ for business logic and keep controllers thin; avoid duplicating rule/PDF/print orchestration across files.

If any of the above appears in the diff for this path, you MUST request changes and explain the fix.

Files:

  • backend/src/services/timelineService.js
  • backend/src/controllers/webhookController.js
  • backend/src/routes/orderRoutes.js
  • backend/src/controllers/printJobController.js
🔇 Additional comments (2)
backend/src/services/timelineService.js (1)

107-110: Debug log placement is safe.

The added trace at Line 108 preserves behavior and keeps useful context before the timeline write.

backend/src/controllers/printJobController.js (1)

38-39: Manual-print timeline hook placement looks correct.

The added logging + timeline call sequence is coherent and does not change endpoint semantics.

Comment on lines +59 to 60
console.log('retryDepartmentPrint', order_id, department);
const { order_id, department } = req.params;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify declaration order inside retryDepartmentPrint in a read-only way.
# Expected: destructuring declaration appears before the console.log usage.

file="backend/src/controllers/printJobController.js"
rg -n -C3 "async function retryDepartmentPrint|console\\.log\\('retryDepartmentPrint', order_id, department\\)|const \\{ order_id, department \\} = req\\.params;" "$file"

Repository: IM-Agents/Pravin-AI-2026

Length of output: 871


Move the console.log after the variable declaration to avoid TDZ crash.

Line 59 reads order_id and department before they are declared on line 60. This causes a ReferenceError at runtime and returns a 500 error for all retry requests.

Proposed fix
 async function retryDepartmentPrint(req, res) {
   try {
-    console.log('retryDepartmentPrint', order_id, department);
     const { order_id, department } = req.params;
+    console.log('retryDepartmentPrint', order_id, department);
🤖 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 `@backend/src/controllers/printJobController.js` around lines 59 - 60, The
console.log in printJobController.js is reading order_id and department before
they are declared, causing a TDZ ReferenceError; move the console.log statement
to after the destructuring assignment "const { order_id, department } =
req.params" (or destructure into locals earlier in the function handling
retries, e.g., inside retryDepartmentPrint handler) so the log uses the declared
variables, and ensure any other uses of order_id/department in
retryDepartmentPrint reference the same destructured variables.

let specificDeliveryTime = null;
let deliveryDay = null;
let deliveryLink = null;
console.log('extractDeliveryInfo', noteAttributes, lineItems);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove or redact PII from debug logging.

This log statement outputs noteAttributes and lineItems, both of which contain customer PII such as delivery addresses, contact information, emails, phone numbers, and product purchase details. Logging this data creates compliance/privacy risks under GDPR/CCPA and violates data minimization principles.

🔒 Proposed fix: Remove the PII-sensitive log statement
- console.log('extractDeliveryInfo', noteAttributes, lineItems);

If debugging is required, log only non-sensitive metadata (e.g., array lengths):

- console.log('extractDeliveryInfo', noteAttributes, lineItems);
+ console.log('extractDeliveryInfo: processing', noteAttributes.length, 'note attributes and', lineItems.length, 'line items');

As per coding guidelines, backend source code must avoid logging sensitive data like emails and other user identifiers.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log('extractDeliveryInfo', noteAttributes, lineItems);
// (preceding code remains unchanged)
Suggested change
console.log('extractDeliveryInfo', noteAttributes, lineItems);
console.log('extractDeliveryInfo: processing', noteAttributes.length, 'note attributes and', lineItems.length, 'line items');
🤖 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 `@backend/src/controllers/webhookController.js` at line 30, The console.log
call that prints 'extractDeliveryInfo' along with noteAttributes and lineItems
exposes customer PII (addresses, emails, phones); remove that raw debug log and
replace it with a non-PII-safe log (e.g., log only counts or presence flags) or
mask/redact sensitive fields before logging; specifically update the
console.log('extractDeliveryInfo', noteAttributes, lineItems) invocation (or
within the extractDeliveryInfo code path) to emit only metadata such as
noteAttributes length, lineItems length, or a boolean hasDeliveryInfo, or call a
central maskPII helper to redact emails/phones before any logging.

Comment on lines 14 to +16
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify duplicate route declarations for download-pdf.
# Expected after fix: exactly one match.

file="backend/src/routes/orderRoutes.js"
rg -n "router\\.get\\('/:order_id/departments/:department/download-pdf'" "$file"

Repository: IM-Agents/Pravin-AI-2026

Length of output: 392


Remove duplicate route registration for download-pdf.

Lines 14–16 declare the same GET route three times. Keep a single registration to avoid ambiguous routing behavior.

Proposed fix
 router.post('/:order_id/departments/:department/print', printJobController.triggerDepartmentPrint);
 router.post('/:order_id/departments/:department/retry', printJobController.retryDepartmentPrint);
 router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
-router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
-router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
router.post('/:order_id/departments/:department/print', printJobController.triggerDepartmentPrint);
router.post('/:order_id/departments/:department/retry', printJobController.retryDepartmentPrint);
router.get('/:order_id/departments/:department/download-pdf', printJobController.downloadDepartmentPdf);
🤖 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 `@backend/src/routes/orderRoutes.js` around lines 14 - 16, Duplicate GET route
registrations for '/:order_id/departments/:department/download-pdf' were added
using router.get and printJobController.downloadDepartmentPdf; remove the extra
two registrations and keep a single
router.get('/:order_id/departments/:department/download-pdf',
printJobController.downloadDepartmentPdf) to avoid ambiguous routing (ensure
only one occurrence remains and that the router export is unchanged).

@IM-Agents
IM-Agents merged commit 6d46002 into cursor_new_oma_req May 5, 2026
2 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 5, 2026
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.

2 participants