Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Task not assigned to employee when created by an Employee #8781

Merged
merged 5 commits into from
Feb 17, 2025

Conversation

samuelmbabhazi
Copy link
Contributor

@samuelmbabhazi samuelmbabhazi commented Feb 17, 2025

PR

Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.


Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the task creation process to automatically include the current employee in the task’s members list, ensuring proper participant assignment.
    • Improved error handling during employee information retrieval, providing better logging and user feedback in case of failures.

Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes update the task creation process by enhancing how the current employee is handled. The handler now retrieves the current employee ID along with the user, fetches employee details, and checks whether the employee is already part of the task members. If not, the employee is added to the list. Error handling has been improved to manage retrieval failures. The overall structure of task creation remains unchanged.

Changes

File Path Change Summary
packages/.../task-create.handler.ts Modified logic to retrieve employee ID, fetch employee details, and ensure the current employee is added to the task's members list if missing. Improved error handling for employee retrieval.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant H as TaskCreateHandler
    participant E as EmployeeService

    C->>H: Send Create Task Request
    H->>H: Retrieve current user & employee ID
    H->>E: Fetch employee details using employee ID
    E-->>H: Return employee details
    H->>H: Check if employee exists in members list
    alt Employee not in list
        H->>H: Add employee to task members
    end
    H-->>C: Return created task
Loading

Poem

Hopping through the code with glee,
I’ve added a twist for you to see!
Employee details join the fun,
A neat new check for everyone.
Code hops on—bright as a spring spree! 🐰

With carrots crunching in each line,
My commits dance in a rhythm so fine!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 739a9af and 0574b59.

📒 Files selected for processing (1)
  • packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@samuelmbabhazi samuelmbabhazi self-assigned this Feb 17, 2025
@samuelmbabhazi samuelmbabhazi linked an issue Feb 17, 2025 that may be closed by this pull request
@samuelmbabhazi samuelmbabhazi marked this pull request as ready for review February 17, 2025 09:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (1)

63-67: Enhance employee validation and member addition logic.

While the implementation fixes the core issue, consider these improvements for better efficiency and robustness:

-const employee = await this._employeeService.findOneByIdString(employeeId);
-// Ensure the current employee is added to the members list
-if (employee && !members.some((member) => member.id === employeeId)) {
-  members.push(employee);
-}
+// Add the current employee to members list if they're not already included
+if (employeeId && !members.some((member) => member.id === employeeId)) {
+  try {
+    const employee = await this._employeeService.findOneByIdString(employeeId);
+    if (employee) {
+      members.push(employee);
+    }
+  } catch (error) {
+    this.logger.warn(
+      `Failed to add current employee (${employeeId}) to task members:`,
+      error.message
+    );
+  }
+}

Changes:

  1. Check employeeId before database lookup
  2. Only perform employee lookup if needed
  3. Add error handling for failed employee lookup
  4. Improve comment to better describe the business logic
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16d9ecc and f4bc134.

📒 Files selected for processing (1)
  • packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
🔇 Additional comments (1)
packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (1)

59-62: LGTM! Employee retrieval implementation looks good.

The changes correctly retrieve both the current user and employee ID from the request context, which is essential for proper task assignment.

Copy link

nx-cloud bot commented Feb 17, 2025

View your CI Pipeline Execution ↗ for commit 0574b59.

Command Status Duration Result
nx build desktop --base-href ./ ✅ Succeeded 1m 49s View ↗
nx build desktop-api --output-path=dist/apps/de... ✅ Succeeded 28s View ↗
nx run api:desktop-api ✅ Succeeded 1m 16s View ↗
nx run gauzy:desktop-ui --base-href ./ ✅ Succeeded 3m 31s View ↗
nx build gauzy -c=production --prod --verbose ✅ Succeeded 3m 18s View ↗
nx build api -c=production --prod ✅ Succeeded 1m 7s View ↗
nx build desktop-ui-lib --configuration=production ✅ Succeeded 29s View ↗
nx build plugin-integration-wakatime ✅ Succeeded <1s View ↗
Additional runs (56) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-17 15:13:30 UTC

const user = RequestContext.currentUser();
const employeeId = RequestContext.currentEmployeeId();

const employee = await this._employeeService.findOneByIdString(employeeId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@samuelmbabhazi What if Super Admin will create task?

Note: It will throw exception if Admin will try to create tasks as If they don't have employee record.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now everything is fine,
I just check the existence of employeeId,
if it does not exist we move on to the next instruction, no exception is throw

Copy link
Collaborator

Choose a reason for hiding this comment

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

@samuelmbabhazi I will review PR soon.

@rahul-rocket rahul-rocket merged commit cce9e19 into develop Feb 17, 2025
11 of 14 checks passed
@rahul-rocket rahul-rocket deleted the fix/#8780-employee-assignment branch February 17, 2025 14:23
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.

[Bug] Task not assigned to employee when created by an Employee
2 participants