Skip to content

Backend changes - #46

Merged
JahnaviVeera merged 3 commits into
spotmies:masterfrom
JahnaviVeera:master
Mar 11, 2026
Merged

JahnaviVeera merged 3 commits into
spotmies:masterfrom
JahnaviVeera:master

Conversation

@JahnaviVeera

Copy link
Copy Markdown
Collaborator

No description provided.

@JahnaviVeera
JahnaviVeera merged commit 40d8711 into spotmies:master Mar 11, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🤖 AI Code Review

🤖 AI Code Review

📌 Summary

  • The diff primarily updates the package-lock.json file by replacing "dev": true with "devOptional": true for various dependencies and adding "peer": true for some dependencies.
  • No functional code changes are present, but the modifications could impact dependency resolution and build behavior.
  • Overall, the changes appear to align with npm's support for devOptional and peer fields, but careful testing is recommended to ensure compatibility.

💬 Inline Comments (File-wise)

package-lock.json

  • Line 115: "devOptional": true replaces "dev": true. This change indicates that the dependency is optional for development. Ensure that this aligns with your project's requirements and build process.

    • ✅ Suggestion: Verify that all dependencies marked as devOptional are indeed optional and won't cause issues during development or testing.
  • Line 185: "peer": true added for @electric-sql/pglite. Peer dependencies require the consuming project to install the dependency explicitly. Ensure that this change is intentional and documented for developers using the project.

    • ✅ Suggestion: Update documentation or README to inform users about required peer dependencies.
  • Line 656: "peer": true added for @types/body-parser. Similar to the above, ensure that this change is intentional and won't cause runtime issues if the peer dependency is missing.

    • ✅ Suggestion: Test the project thoroughly to confirm that peer dependencies are correctly resolved.
  • Line 721: "peer": true added for @types/node. This change could impact projects relying on specific Node.js type definitions. Ensure compatibility with the project's TypeScript configuration.

    • ✅ Suggestion: Confirm that the consuming project explicitly installs compatible versions of @types/node.
  • Line 757: New dependency @types/react added with "peer": true. This addition introduces a peer dependency for React types. Ensure that this aligns with the project's requirements.

    • ✅ Suggestion: Verify compatibility with existing React versions in the project.
  • Line 1453: New dependency csstype added with "devOptional": true. This dependency is likely used for TypeScript type definitions related to CSS. Ensure it is correctly integrated into the development workflow.

    • ✅ Suggestion: Confirm that csstype is compatible with the project's TypeScript configuration.

⚠️ High-Risk Issues

  • Peer Dependency Management: Adding "peer": true for dependencies like @electric-sql/pglite, @types/node, and @types/react could lead to runtime errors if the consuming project does not explicitly install these dependencies. Peer dependencies are not automatically installed by npm, so this change requires careful documentation and testing.

    • ✅ Suggestion: Update the project's documentation to list all required peer dependencies and their compatible versions. Test the project in environments where these peer dependencies are explicitly installed and where they are missing.
  • Build and Development Workflow Impact: Replacing "dev": true with "devOptional": true may affect how dependencies are handled during development. If any of these dependencies are critical for development or testing, this change could lead to unexpected issues.

    • ✅ Suggestion: Run a full build and test suite to ensure that marking dependencies as devOptional does not break the development workflow.

Final Notes

  • While the changes appear to be valid and align with npm's dependency management features, they could have subtle impacts on dependency resolution and project behavior. Testing and documentation updates are crucial to mitigate risks.
  • No immediate bugs or security vulnerabilities are evident, but the dependency changes should be carefully validated in the project's environment.

🤖 AI Code Review

📌 Summary

  • The changes primarily involve replacing "dev": true with "devOptional": true in the package-lock.json file and adding new dependencies with the peer and devOptional flags.
  • No critical issues were found, but there are some considerations for maintainability and dependency management.

💬 Inline Comments (File-wise)

package-lock.json

  • Line 1-3722: The replacement of "dev": true with "devOptional": true indicates a shift in how development dependencies are being categorized. This change is valid but requires careful consideration of its implications:

    • ✅ Suggestion: Ensure that all tools and scripts relying on these dependencies are compatible with the devOptional flag. Test the build and development workflows to confirm no unintended side effects.
  • Lines 2192, 3032, 3585, etc.: New dependencies such as openapi-types, react, react-dom, and scheduler have been added with the peer and devOptional flags.

    • ✅ Suggestion: Verify that these new dependencies are necessary and correctly categorized. For example, peer dependencies should be explicitly required by the consuming project or its consumers.
  • Line 2192: The addition of "peer": true for hono and other dependencies like pg, prisma, and react suggests these are expected to be installed by the end-user or consuming project.

    • ✅ Suggestion: Ensure that the documentation for your project clearly specifies the required peer dependencies to avoid runtime errors for users.

⚠️ High-Risk Issues

No high-risk issues found. However, the following points should be considered to avoid potential problems:

  1. Dependency Compatibility: Ensure that the new peer dependencies (react, react-dom, etc.) are compatible with the rest of the project and its consumers.
  2. Workflow Testing: Test all development workflows (e.g., build, test, lint) to confirm that the devOptional flag does not introduce issues.
  3. Peer Dependency Warnings: Peer dependencies can cause warnings or errors if not properly installed by the consuming project. Ensure this is documented.

Final Notes

  • The changes appear to be part of a broader effort to refine dependency management. While no immediate issues are apparent, thorough testing and documentation updates are recommended to ensure smooth adoption.
  • If this change is part of a larger migration or policy shift, consider communicating the rationale and implications to the team or contributors.

🤖 AI Code Review

📌 Summary

  • The changes introduce several improvements, including dual-approval workflows, schema updates, and controller refactoring. However, there are some issues related to maintainability, potential bugs, and missing validations that need attention.

💬 Inline Comments (File-wise)

package.json

  • Line 6: Duplicate "dev" script key detected.
    • ✅ Suggestion: Remove the duplicate "dev" key to avoid conflicts. Ensure the correct script is retained.

prisma/schema.prisma

  • Line 73: The DocumentType enum has been removed and replaced with a free-text string.

    • ✅ Suggestion: Consider using a constrained string type or a validation mechanism to ensure data consistency and prevent invalid document types.
  • Line 315: New fields (adminApproved, customerApproved, customerFeedback) added to the DailyUpdate model.

    • ✅ Suggestion: Ensure these fields are indexed if they will be frequently queried or filtered.
  • Line 339: The documentType field in the Document model has been changed from an enum to a string.

    • ✅ Suggestion: If the enum was removed to allow flexibility, consider adding a validation layer to ensure valid document types are used.
  • Line 514: New fields (vendorDetails, dateOfPurchase, quantity, unit) added to the Purchase model.

    • ✅ Suggestion: Validate dateOfPurchase to ensure it follows a proper date format. Consider using a DateTime type instead of String for better type safety.

src/app.ts

  • Line 77: Duplicate route /api/project and /api/projects both point to projectRoutes.
    • ✅ Suggestion: Ensure this duplication is intentional. If not, remove one of the routes to avoid confusion or unintended behavior.

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

  • Line 872: The approveDailyUpdate function has been renamed to adminApproveUpdate, but the Swagger documentation still references "Customer".

    • ✅ Suggestion: Update the Swagger documentation to reflect the correct role (Admin).
  • Line 887: Email notifications for approvals have been removed.

    • ✅ Suggestion: If email notifications are no longer required, ensure stakeholders are aware of this change. If still needed, reintroduce the email logic in a separate service for better modularity.
  • Line 1009: The rejectDailyUpdate function has been renamed to customerRejectUpdate, but the Swagger documentation references "Daily update rejected successfully" without specifying the role.

    • ✅ Suggestion: Update the Swagger documentation to clarify that the rejection is performed by the Customer.
  • Line 1009: Missing validation for feedback in customerRejectUpdate.

    • ✅ Suggestion: Add validation to ensure feedback is provided and meets any required constraints (e.g., length, format).

⚠️ High-Risk Issues

  1. Schema Changes Without Validation:

    • The removal of the DocumentType enum and its replacement with a free-text string introduces a risk of inconsistent or invalid data.
    • ✅ Suggestion: Add validation logic in the application layer or database constraints to enforce valid document types.
  2. Duplicate Script in package.json:

    • The duplicate "dev" script key can cause unexpected behavior during script execution.
    • ✅ Suggestion: Remove the duplicate key and retain the correct script.
  3. Potential Data Integrity Issues in Purchase Model:

    • The dateOfPurchase field is a String, which may lead to invalid date formats being stored.
    • ✅ Suggestion: Use a DateTime type for better type safety and consistency.
  4. Missing Authorization Checks in Controllers:

    • The adminApproveUpdate and adminRejectUpdate functions do not validate the user's role to ensure they are an Admin.
    • ✅ Suggestion: Add role-based authorization checks to prevent unauthorized access.

⚠️ High-Risk Issues Summary

  • Schema changes (e.g., DocumentType enum removal) may lead to data inconsistency.
  • Duplicate "dev" script in package.json could cause runtime issues.
  • Missing validation for new fields (e.g., dateOfPurchase, feedback) risks data integrity.
  • Lack of role-based authorization in controller methods could lead to security vulnerabilities.

🤖 AI Code Review

📌 Summary

  • The refactored code introduces a more modular approach to handling daily update approvals and rejections, separating admin and customer actions.
  • Improved maintainability by centralizing notification logic and reducing redundant code.
  • Some potential issues with error handling, security, and performance were identified.

💬 Inline Comments (File-wise)

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

  • Line 1-20: The removal of email notification logic simplifies the controller but shifts responsibility to the service layer. Ensure the service layer handles notifications effectively to avoid missing critical alerts.
    • ✅ Suggestion: Verify that the customerRejectUpdate method in the service layer includes robust notification handling.

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

  • Line 8-16: The route changes for admin and customer actions are clear, but the naming conventions (customer-approve, customer-reject) could be more consistent with RESTful practices.
    • ✅ Suggestion: Consider using approve/customer and reject/customer for better readability and alignment with RESTful standards.

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

  • Line 118: The addition of DailyUpdateStatus.draft is a good improvement for tracking updates in progress. However, ensure that draft updates are excluded from any production-related calculations or notifications.

    • ✅ Suggestion: Add explicit checks to exclude drafts from progress calculations and notifications.
  • Line 137-311: The modularization of admin and customer approval/rejection logic improves maintainability. However, the error messages for unauthorized actions (e.g., "Unauthorized: You can only approve updates for your own projects") could be more descriptive for debugging purposes.

    • ✅ Suggestion: Include additional context in error messages, such as the user ID and project ID involved.
  • Line 931-311: The notification logic is well-structured but could benefit from rate-limiting or batching to avoid overwhelming the notification system during high activity periods.

    • ✅ Suggestion: Implement a queuing mechanism for notifications to ensure scalability.

⚠️ High-Risk Issues

  1. Error Handling in Notifications:

    • The notification logic does not appear to handle failures robustly. For example, if notifyAdmins or notifyUser fails, the system logs the error but does not retry or provide fallback mechanisms.
    • ✅ Suggestion: Implement retry logic with exponential backoff for failed notifications and consider adding a fallback mechanism (e.g., logging to a monitoring system).
  2. Authorization Checks:

    • The authorization checks for customer actions rely on matching userId with project.customerId. If customerId is null or improperly set, unauthorized actions could occur.
    • ✅ Suggestion: Add a stricter validation mechanism to ensure customerId is correctly set and verified before proceeding.
  3. Performance Concerns with updateProjectProgress:

    • The updateProjectProgress function could become a bottleneck if called frequently, especially for large projects with many updates.
    • ✅ Suggestion: Optimize updateProjectProgress by caching progress calculations or batching updates.

⚠️ High-Risk Issues

  • No high-risk security vulnerabilities found, but improvements in error handling and authorization checks are recommended to mitigate potential risks.

This review highlights areas for improvement while acknowledging the positive changes made to the codebase. Let me know if you need further clarification or assistance!


🤖 AI Code Review

📌 Summary

  • The changes introduce new functionality for handling customer rejections, approvals, and notifications in a daily update workflow.
  • Several helper functions were added to improve modularity and maintainability.
  • Some areas need attention for error handling, security, and performance optimization.

💬 Inline Comments (File-wise)

src/modules/dailyUpdates/dailyUpdates.service.ts

  • Line 5: The feedback parameter is validated for being non-empty, but there is no length or content validation. This could lead to issues if excessively long or inappropriate feedback is submitted.

    • ✅ Suggestion: Add a maximum length validation and sanitize the input to prevent potential abuse.
  • Line 12: The include clause in the Prisma query fetches the entire customer object. This could lead to over-fetching of data if only specific fields are needed.

    • ✅ Suggestion: Limit the fields fetched for customer to only those required for the operation.
  • Line 20: The error message "Unauthorized: You can only reject updates for your own projects" could expose sensitive information about project ownership.

    • ✅ Suggestion: Use a generic error message like "Unauthorized action" to avoid leaking details.
  • Line 40: The notifyRejectionFinal function is called without any error handling. If the notification fails, the rejection process will still proceed without informing the user.

    • ✅ Suggestion: Wrap the notification logic in a try-catch block and log any errors for debugging.
  • Line 63: The updateProjectProgress function assumes a fixed total of 6 stages. If the number of stages changes in the future, this hardcoded value will need to be updated.

    • ✅ Suggestion: Fetch the total number of stages dynamically from the database or configuration.
  • Line 105: The notifyApprovalSuccess function emits notifications to multiple parties but does not handle failures gracefully.

    • ✅ Suggestion: Add error handling for each notification step to ensure partial failures do not disrupt the entire process.
  • Line 180: The notifyRejectionFinal function uses the rejectedBy parameter to determine the recipient of the notification. This logic could become error-prone if more roles are added in the future.

    • ✅ Suggestion: Use a more robust role-based notification system to handle such cases dynamically.

src/modules/documents/documents.controller.ts

  • Line 34: The removal of the enum for documentType reduces the clarity of acceptable values for this field.

    • ✅ Suggestion: Retain the enum or document the acceptable values elsewhere to ensure consistency and validation.
  • Line 192: The example value for documentType was changed to "Building Layout," which may not align with the original intent of the field.

    • ✅ Suggestion: Ensure the example value accurately reflects the intended use of the field.

⚠️ High-Risk Issues

  1. Line 5 (dailyUpdates.service.ts): Lack of input sanitization for feedback could lead to security vulnerabilities like injection attacks.

    • ✅ Suggestion: Sanitize and validate the feedback input to prevent malicious content.
  2. Line 12 (dailyUpdates.service.ts): Over-fetching data in the Prisma query could lead to performance issues and potential data exposure.

    • ✅ Suggestion: Fetch only the necessary fields for the operation.
  3. Line 40 (dailyUpdates.service.ts): Missing error handling for notifications could result in silent failures, leaving stakeholders uninformed.

    • ✅ Suggestion: Add robust error handling and logging for notification failures.

Final Notes

  • The refactoring and modularization efforts are commendable, as they improve code readability and maintainability.
  • Addressing the highlighted issues will enhance the security, performance, and reliability of the system.

🤖 AI Code Review

📌 Summary

  • Removal of hardcoded document type validation improves flexibility but introduces risks if invalid types are passed.
  • Added validations for project budget and dates enhance data integrity.
  • Updates to purchase services and controller improve functionality but require additional validation for new fields.
  • Routes in project.routes.ts are duplicated, which could lead to maintenance issues.

💬 Inline Comments (File-wise)

src/modules/documents/documents.services.ts

  • Line 39: Removal of hardcoded validTypes validation for documentType could allow invalid or unexpected values to be stored in the database.
    • ✅ Suggestion: Consider validating documentType against a predefined list or schema to ensure data consistency.
  • Line 445: Dynamically mapping document counts is flexible, but the fallback for missing types (Unknown) may lead to unexpected results.
    • ✅ Suggestion: Ensure Unknown is handled appropriately in downstream processes or explicitly document its usage.

src/modules/project/project.routes.ts

  • Lines 6-20: Duplicate routes (e.g., /createproject and /) for the same functionality may cause confusion and increase maintenance overhead.
    • ✅ Suggestion: Consolidate routes to avoid redundancy, or clearly document the purpose of each route.

src/modules/project/project.services.ts

  • Line 60: Validation for totalBudget and dates is a good addition, but the error messages could be more descriptive for debugging purposes.
    • ✅ Suggestion: Include the invalid value in the error message for better traceability.
  • Line 418: Validation for startDate and expectedCompletion in updateProject is robust, but consider logging the invalid values for debugging.
    • ✅ Suggestion: Add logging or error details to help identify issues during runtime.

src/modules/purchases/purchases.controller.ts

  • Line 6: New fields (vendorDetails, dateOfPurchase, quantity, unit) are added but lack validation in the controller.
    • ✅ Suggestion: Validate these fields in the controller before passing them to the service layer to ensure data integrity.

src/modules/purchases/purchases.services.ts

  • Line 7: dateOfPurchase is marked as required but lacks validation for format or range.
    • ✅ Suggestion: Validate dateOfPurchase to ensure it is a valid date and falls within acceptable ranges.
  • Line 35: Conversion of quantity to Number is helpful, but ensure that unit is validated to avoid unexpected values.
    • ✅ Suggestion: Add validation for unit to ensure it matches expected formats or values.

⚠️ High-Risk Issues

  1. Document Type Validation Removed:

    • Risk: Removing validation for documentType could allow invalid or unexpected values to be stored in the database, potentially causing downstream issues.
    • ✅ Suggestion: Reintroduce validation using a schema or predefined list of valid types.
  2. Duplicate Routes in project.routes.ts:

    • Risk: Duplicate routes (e.g., /createproject and /) may lead to confusion or unintended behavior during routing.
    • ✅ Suggestion: Consolidate routes or clearly document their purpose to avoid ambiguity.
  3. Missing Validation for New Purchase Fields:

    • Risk: Newly added fields (vendorDetails, dateOfPurchase, quantity, unit) lack validation, which could lead to invalid data being stored.
    • ✅ Suggestion: Add validation for these fields in both the controller and service layers.

⚠️ High-Risk Issues Summary

  • Document type validation removed.
  • Duplicate routes in project.routes.ts.
  • Missing validation for new purchase fields.

By addressing these issues, the codebase will be more robust, maintainable, and secure.


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.

1 participant