Skip to content

feat: Implement initial database setup with Prisma ORM and scaffold c… - #57

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

JahnaviVeera merged 1 commit into
spotmies:masterfrom
JahnaviVeera:Jahnavi_Dev

Conversation

@JahnaviVeera

Copy link
Copy Markdown
Collaborator

…ore API modules for user, purchases, and expense management.

…ore API modules for user, purchases, and expense management.
@JahnaviVeera
JahnaviVeera merged commit eaa641d into spotmies:master Mar 21, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🤖 AI Code Review

🤖 AI Code Review

📌 Summary

  • The changes introduce several improvements, including enhanced error handling, new features, and better logging.
  • Some areas require attention for security, maintainability, and performance.
  • No critical security vulnerabilities were found, but there are opportunities for improvement.

💬 Inline Comments (File-wise)

prisma/schema.prisma

  • Line 6: Adding url = env("DATABASE_URL") is a good practice for environment-based configuration. Ensure the DATABASE_URL is securely stored and not hardcoded.

run_test.js

  • Line 3: Using execSync without sanitizing the input or handling potential command injection risks can be dangerous.
    • ✅ Suggestion: Ensure test_db.ts is a trusted file and consider using asynchronous exec for better performance and error handling.

src/config/prisma.client.ts

  • Line 9: Increasing max connections to 15 is reasonable, but ensure this aligns with your database's connection limits.
  • Line 13: The maxUses property is a good addition to prevent stale connections. However, ensure your version of pg supports this property.
  • Line 20: The keepalives and keepalives_idle options are useful for maintaining connections, but the @ts-ignore comments indicate potential type mismatches.
    • ✅ Suggestion: Update @types/pg to the latest version to avoid type issues.
  • Line 27: Logging pool errors is a good practice. Ensure sensitive information is not logged.

src/modules/expense/expense.controller.ts

  • Line 87: Logging the receipt upload error is helpful for debugging, but ensure sensitive information is not exposed in logs.
  • Line 102: Including a warning in the response for non-fatal errors is a good user experience improvement.

src/modules/purchases/purchases.controller.ts

  • Line 38: The logic for supervisors to fetch assigned projects is well-implemented. However, the nested if conditions could be refactored for better readability.
    • ✅ Suggestion: Extract the supervisor-specific logic into a helper function to simplify the controller.

src/modules/purchases/purchases.routes.ts

  • Line 14: Adding supervisor to the authorized roles for the GET route is a good addition. Ensure this aligns with your business logic and access control policies.

src/modules/purchases/purchases.services.ts

  • Line 7: The getAllPurchasesForProjects function is well-structured. However, the whereClause object could be validated to ensure it doesn't unintentionally include invalid filters.
    • ✅ Suggestion: Add a validation step for projectIds and date filters before querying the database.

src/modules/user/user.controller.ts

  • Line 1574: The regeneratePassword function exposes the new password in the response. This could be a security risk if the response is logged or intercepted.
    • ✅ Suggestion: Avoid returning the password in the response. Instead, send it securely to the user via email or another secure channel.

src/modules/user/user.services.ts

  • Line 810: The regeneratePassword function generates a random password but does not enforce complexity rules.
    • ✅ Suggestion: Use a library like crypto or bcrypt to generate secure passwords that meet complexity requirements.
  • Line 813: The new password is stored in plaintext in the response. This is a security risk.
    • ✅ Suggestion: Hash the password before storing it in the database and avoid returning it in plaintext.

⚠️ High-Risk Issues

  1. Password Exposure in regeneratePassword:

    • The new password is returned in plaintext in the response, which is a significant security risk.
    • ✅ Fix: Avoid returning the password in the response. Instead, send it securely to the user via email or another secure channel.
  2. Use of execSync in run_test.js:

    • Synchronous execution of shell commands can block the event loop and is prone to command injection risks.
    • ✅ Fix: Use asynchronous exec and sanitize inputs to mitigate risks.

🚀 Recommendations

  • Refactor complex logic in controllers into helper functions for better readability and maintainability.
  • Ensure all sensitive information, such as passwords and error details, is handled securely and not exposed in logs or responses.
  • Regularly update dependencies to avoid compatibility issues and leverage new features or fixes.

🤖 AI Code Review

📌 Summary

  • The code introduces password hashing and database updates, which are generally good practices.
  • A new test file (test_db.ts) is added for database connectivity testing.
  • No significant issues in the binary file change (test_output.txt) since it is not code-related.

💬 Inline Comments (File-wise)

src/updatePassword.ts (Assumed file name based on context)

  • Line 3: The bcrypt hashing strength is set to 10. While this is a reasonable default, consider whether this meets your application's security requirements.

    • ✅ Suggestion: Document the rationale for choosing 10 or make it configurable via environment variables for flexibility.
  • Line 7: The updatedAt field is being set to new Date(). This assumes the server's clock is accurate, which may not always be the case in distributed systems.

    • ✅ Suggestion: Consider using a centralized time source or database-generated timestamps to ensure consistency.
  • Line 10: Returning newPassword in the response could be a security risk, especially if this function is exposed externally.

    • ✅ Suggestion: Avoid returning the plaintext password. Instead, return a success message or other non-sensitive information.

test_db.ts

  • Line 3: The findFirst method is used without specifying any where condition, which could lead to unintended results if the database contains multiple users.

    • ✅ Suggestion: Add a where clause to ensure the query retrieves a specific user or meets a defined condition.
  • Line 8: The finally block ensures the Prisma client disconnects, which is good practice. However, if the await prisma.$disconnect() fails, it could leave resources hanging.

    • ✅ Suggestion: Wrap prisma.$disconnect() in a try-catch block to handle potential errors gracefully.

⚠️ High-Risk Issues

  • Returning plaintext password: In src/updatePassword.ts, returning the newPassword in the response is a security risk. If this function is exposed externally, it could lead to sensitive information leakage.
    • ✅ Fix: Remove newPassword from the return object and replace it with a generic success message.

🛠️ Additional Suggestions

  • Add unit tests for the updatePassword function to ensure the password hashing and database update logic work as expected.
  • Consider adding logging or monitoring for the database update operation to track potential issues in production.

Let me know if you need further clarification or assistance!


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