Skip to content

feat: implement daily updates module with controller and validation s… - #64

Merged
JahnaviVeera merged 1 commit into
spotmies:masterfrom
JahnaviVeera:Jahnavi_Dev
Mar 24, 2026
Merged

JahnaviVeera merged 1 commit into
spotmies:masterfrom
JahnaviVeera:Jahnavi_Dev

Conversation

@JahnaviVeera

Copy link
Copy Markdown
Collaborator

…chemas for creating daily reports.

@JahnaviVeera
JahnaviVeera merged commit af0437b into spotmies:master Mar 24, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🤖 AI Code Review

🤖 AI Code Review

📌 Summary

  • The changes introduce array schemas for validating plural fields (RawMaterialArraySchema, QuantityConsumptionArraySchema, LabourWorkersArraySchema) and update their usage in the controller methods.
  • The refactor improves clarity by explicitly defining array schemas, but there are potential issues with validation logic and error handling that need attention.

💬 Inline Comments (File-wise)

src/modules/daily-updates/daily-updates.controller.ts

  • Line 93: The validateJsonInput function now uses RawMaterialArraySchema. Ensure that the incoming req.body.rawMaterials is always an array before validation, as the schema expects an array.

    • ✅ Suggestion: Add a check to verify req.body.rawMaterials is an array before passing it to validateJsonInput. If it's not, return a clear error message.
  • Line 214: Similar to the above, validateJsonInput now uses QuantityConsumptionArraySchema. Ensure req.body.quantityConsumption is an array.

    • ✅ Suggestion: Add a check to verify req.body.quantityConsumption is an array before validation.
  • Line 226: The validateJsonInput function uses LabourWorkersArraySchema. Ensure req.body.labourWorkers is an array.

    • ✅ Suggestion: Add a check to verify req.body.labourWorkers is an array before validation.
  • Line 495: The updateData.rawMaterials field is validated using RawMaterialArraySchema. Ensure req.body.rawMaterials is an array before validation.

    • ✅ Suggestion: Add a check to verify req.body.rawMaterials is an array before passing it to validateJsonInput.
  • Line 507: The updateData.quantityConsumption field is validated using QuantityConsumptionArraySchema. Ensure req.body.quantityConsumption is an array before validation.

    • ✅ Suggestion: Add a check to verify req.body.quantityConsumption is an array before passing it to validateJsonInput.
  • Line 519: The updateData.labourWorkers field is validated using LabourWorkersArraySchema. Ensure req.body.labourWorkers is an array before validation.

    • ✅ Suggestion: Add a check to verify req.body.labourWorkers is an array before passing it to validateJsonInput.

src/modules/daily-updates/daily-updates.schema.ts

  • Line 61: The validateJsonInput function no longer handles arrays explicitly, relying on the caller to pass the correct schema. This could lead to runtime errors if the caller passes a non-array schema for array data.
    • ✅ Suggestion: Consider adding a runtime check inside validateJsonInput to verify whether the schema matches the type of parsedData (e.g., array vs. object). Alternatively, document this behavior clearly to avoid misuse.

⚠️ High-Risk Issues

  • Validation Assumptions: The controller methods assume that incoming data (req.body.rawMaterials, req.body.quantityConsumption, req.body.labourWorkers) are arrays. If the client sends non-array data, the validation will fail, potentially causing unexpected behavior or errors.

    • ✅ Suggestion: Add explicit checks in the controller methods to ensure the incoming data is an array before passing it to validateJsonInput.
  • Error Handling: The error messages returned when validation fails are generic ("Invalid input"). This can make debugging difficult for clients.

    • ✅ Suggestion: Include more specific error messages that indicate which field failed validation and why.

⚠️ High-Risk Issues

  • No security vulnerabilities or crash risks identified, but validation and error handling improvements are critical for robustness.

By addressing the above suggestions, the code will be more resilient to unexpected input and easier to debug. Let me know if you need further clarification!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants