Repository: Learnathon-By-Geeky-Solutions/3-brain-cell
Pull request #35: feat(coordinator): add endpoint to close disasters
Author: login: mehedi-hasan-2302
Created: 2025-04-09T07:07:39Z | Merged: 2025-04-09T07:10:08Z

Implemented closeDisaster service function to update the disaster status to 'Closed' and set the endDate. Added PATCH in the coordinator controller with authorization checks and error handling.


Diff:
diff --git a/backend/src/controllers/coordinatorController.js b/backend/src/controllers/coordinatorController.js
index fe06033..6f59bf0 100644
--- a/backend/src/controllers/coordinatorController.js
+++ b/backend/src/controllers/coordinatorController.js
@@ -20,7 +20,19 @@ const getDisasters = async (req, res) => {
     const result = await coordinatorService.getDisasters(offset, parseInt(limit));
     return sendSuccessResponse(res, result, 'Disasters retrieved successfully');
   } catch (error) {
-    console.error('getDisasters error:', error);
+    return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
+  }
+};
+
+const closeDisaster = async (req, res) => {
+  try {
+    const coordinatorId = req.user.id;
+    const { disasterId } = req.params;
+    
+    const result = await coordinatorService.closeDisaster(coordinatorId, disasterId);
+    
+    return sendSuccessResponse(res, result, 'Disaster turned off successfully');
+  } catch (error) {
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -31,7 +43,6 @@ const approveOrganization = async (req, res) => {
     const result = await coordinatorService.approveOrganization(orgId);
     return sendSuccessResponse(res, result, 'Organization approved successfully');
   } catch (error) {
-    console.error('approveOrganization error:', error);
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -43,7 +54,6 @@ const getAllTeams = async (req, res) => {
     const result = await coordinatorService.getAllTeams(offset, parseInt(limit));
     return sendSuccessResponse(res, result, 'Teams retrieved successfully');
   } catch (error) {
-    console.error('getAllTeams error:', error);
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -56,7 +66,6 @@ const assignDisasterToTeam = async (req, res) => {
     const result = await coordinatorService.assignDisasterToTeam(teamId, disasterId, teamDetails);
     return sendSuccessResponse(res, result, 'Disaster assigned to team successfully');
   } catch (error) {
-    console.error('assignDisasterToTeam error:', error);
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -68,7 +77,6 @@ const getDisasterStats = async (req, res) => {
     const result = await coordinatorService.getDisasterStats(disasterId);
     return sendSuccessResponse(res, result, 'Disaster statistics retrieved successfully');
   } catch (error) {
-    console.error('getDisasterStats error:', error);
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -106,7 +114,6 @@ const sendEmergencyNotification = async (req, res) => {
     const result = await coordinatorService.sendEmergencyNotification(req.body.subject, req.body.message);
     return sendSuccessResponse(res, result, 'Emergency notification sent successfully');
   } catch (error) {
-    console.error('sendEmergencyNotification error:', error);
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
@@ -114,6 +121,7 @@ const sendEmergencyNotification = async (req, res) => {
 module.exports = {
   createDisaster,
   getDisasters,
+  closeDisaster,
   approveOrganization,
   getAllTeams,
   assignDisasterToTeam,
diff --git a/backend/src/routes/coordinatorRoutes.js b/backend/src/routes/coordinatorRoutes.js
index bccf58d..d4c8e5c 100644
--- a/backend/src/routes/coordinatorRoutes.js
+++ b/backend/src/routes/coordinatorRoutes.js
@@ -12,6 +12,7 @@ const {
  const {
     createDisaster,
     getDisasters,
+    closeDisaster,
     approveOrganization,
     getAllTeams,
     assignDisasterToTeam,
@@ -33,6 +34,8 @@ router.post('/disasters', validateRequestBody(createDisasterSchema), createDisas
 
 router.get('/disasters', getDisasters);
 
+router.patch('/disasters/:disasterId/close', closeDisaster);
+
 
 router.patch('/organizations/:orgId/approve', approveOrganization);
 
diff --git a/backend/src/services/coordinatorService.js b/backend/src/services/coordinatorService.js
index bdfd019..c4d3fc7 100644
--- a/backend/src/services/coordinatorService.js
+++ b/backend/src/services/coordinatorService.js
@@ -64,7 +64,38 @@ const getDisasters = async (offset, limit) => {
     return { total, disasters: formattedDisasters };
   };
   
-
+  //Close a Disaster Event
+  const closeDisaster = async (coordinatorId, disasterId) => {
+    const disasterRepository = AppDataSource.getRepository(Disaster);
+    
+    const disaster = await disasterRepository.findOne({
+      where: { disaster_id: disasterId },
+      relations: ['coordinator', 'coordinator.user']
+    });
+  
+    if (!disaster) {
+      throw new Error('Disaster not found');
+    }
+  
+    // Ensure the coordinator attempting the closure is the owner
+    if (disaster.coordinator.user.userId !== coordinatorId) {
+      throw new InvalidCoordinatorActionError('Coordinator not authorized to turn off this disaster.');
+    }
+    
+    if (disaster.status === 'Closed') {
+      throw new InvalidCoordinatorActionError('Disaster is already closed.');
+    }
+    
+    // Update status and set endDate to now
+    disaster.status = 'Closed';
+    disaster.endDate = new Date();
+  
+    const updatedDisaster = await disasterRepository.save(disaster);
+  
+    const { coordinator: coordinatorData, ...disasterWithoutCoordinator } = updatedDisaster;
+    
+    return disasterWithoutCoordinator;
+  };
 
 const approveOrganization = async (orgId) => {
   const organizationRepository = AppDataSource.getRepository(Organization);
@@ -123,11 +154,9 @@ const assignDisasterToTeam = async (teamId, disasterId, teamDetails = {}) => {
     throw new InvalidCoordinatorActionError('Disaster not found.');
   }
   
-  // Assign the disaster
   team.disaster = disaster;
   team.assignmentStatus = 'assigned';
-  
-  // Also update location and responsibility if provided
+
   if (teamDetails.location) {
     team.location = teamDetails.location;
   }
@@ -136,7 +165,6 @@ const assignDisasterToTeam = async (teamId, disasterId, teamDetails = {}) => {
     team.responsibility = teamDetails.responsibility;
   }
   
-  // Update the assignment timestamp
   team.assignedAt = new Date();
   
   const updatedTeam = await teamRepository.save(team);
@@ -204,6 +232,7 @@ const sendEmergencyNotification = async (subject, message) => {
 module.exports = {
   createDisaster,
   getDisasters,
+  closeDisaster,
   approveOrganization,
   getAllTeams,
   assignDisasterToTeam,
diff --git a/backend/src/utils/errors.js b/backend/src/utils/errors.js
index 2e985df..24220c7 100644
--- a/backend/src/utils/errors.js
+++ b/backend/src/utils/errors.js
@@ -74,6 +74,8 @@ class BaseError extends Error {
       super(message, 404);
     }
   }
+
+
   
   module.exports = {
     UserAlreadyExistsError,


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 2**

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: ASSERTIVE**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 0708fc7eb5957382486677c3f15b2031c145e2cd and eb713cbcbebff5ff41da9b9dd70c0f117a47477b.

</details>

<details>
<summary>📒 Files selected for processing (4)</summary>

* `backend/src/controllers/coordinatorController.js` (2 hunks)
* `backend/src/routes/coordinatorRoutes.js` (2 hunks)
* `backend/src/services/coordinatorService.js` (3 hunks)
* `backend/src/utils/errors.js` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (2)</summary>

<details>
<summary>backend/src/services/coordinatorService.js (1)</summary><blockquote>

<details>
<summary>backend/src/config/database.js (1)</summary>

* `AppDataSource` (14-34)

</details>

</blockquote></details>
<details>
<summary>backend/src/controllers/coordinatorController.js (1)</summary><blockquote>

<details>
<summary>backend/src/utils/responseHelper.js (2)</summary>

* `sendErrorResponse` (9-14)
* `sendSuccessResponse` (1-7)

</details>

</blockquote></details>

</details>

</details>

<details>
<summary>🔇 Additional comments (9)</summary><blockquote>

<details>
<summary>backend/src/utils/errors.js (1)</summary>

`77-78`: **FORMATTING DETECTED: BLANK LINES ADDED.**

OBSERVATION: TWO BLANK LINES ADDED AT END OF FILE. THIS MODIFICATION IS COSMETIC AND DOES NOT ALTER FUNCTIONALITY OF ERROR HANDLING SYSTEM.

</details>
<details>
<summary>backend/src/routes/coordinatorRoutes.js (2)</summary>

`15-15`: **IMPORT STATEMENT MODIFIED: FUNCTION ADDED.**

NEW CONTROLLER FUNCTION 'closeDisaster' SUCCESSFULLY IMPORTED. FOLLOWS ESTABLISHED PATTERN FOR CONTROLLER IMPORTS.

---

`37-38`: **ENDPOINT CREATION: DISASTER CLOSURE FUNCTIONALITY.**

NEW PATCH ENDPOINT CREATED FOR DISASTER CLOSURE. ENDPOINT FOLLOWS RESTFUL CONVENTION. ROUTE PATTERN '/disasters/:disasterId/close' CORRECTLY IDENTIFIES RESOURCE AND ACTION.

</details>
<details>
<summary>backend/src/services/coordinatorService.js (4)</summary>

`67-68`: **FUNCTION IMPLEMENTATION: DISASTER CLOSURE.**

FUNCTION COMMENT CORRECTLY DESCRIBES PURPOSE: "CLOSE A DISASTER EVENT".

---

`80-87`: **AUTHORIZATION AND STATUS VALIDATION.**

AUTHORIZATION CHECK IMPLEMENTED CORRECTLY. FUNCTION VERIFIES:
1. COORDINATOR IS OWNER OF DISASTER
2. DISASTER IS NOT ALREADY CLOSED

SECURITY MEASURES SATISFACTORY.

---

`89-97`: **STATUS UPDATE AND RESPONSE PREPARATION.**

DISASTER STATUS TRANSITION TO 'Closed' AND SETTING OF endDate TO CURRENT TIME IMPLEMENTED CORRECTLY. COORDINATOR DATA PROPERLY REMOVED FROM RESPONSE.

---

`235-235`: **MODULE EXPORTS UPDATED.**

NEW FUNCTION 'closeDisaster' SUCCESSFULLY ADDED TO MODULE EXPORTS.

</details>
<details>
<summary>backend/src/controllers/coordinatorController.js (2)</summary>

`23-25`: **ERROR HANDLING STANDARDIZATION.**

ERROR HANDLING IN getDisasters FUNCTION UPDATED TO USE sendErrorResponse FUNCTION CONSISTENTLY. MODIFICATION IMPROVES ERROR HANDLING CONSISTENCY.

---

`124-124`: **MODULE EXPORTS UPDATED.**

NEW FUNCTION 'closeDisaster' SUCCESSFULLY ADDED TO MODULE EXPORTS.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T07:09:56Z

Review comments:
diff_hunk: @@ -64,7 +64,38 @@ const getDisasters = async (offset, limit) => {
     return { total, disasters: formattedDisasters };
   };
   
-
+  //Close a Disaster Event
+  const closeDisaster = async (coordinatorId, disasterId) => {
+    const disasterRepository = AppDataSource.getRepository(Disaster);
+    
+    const disaster = await disasterRepository.findOne({
+      where: { disaster_id: disasterId },
+      relations: ['coordinator', 'coordinator.user']
+    });
+  
+    if (!disaster) {
+      throw new Error('Disaster not found');
+    }
path: backend/src/services/coordinatorService.js
user: login: coderabbitai[bot]
body: _🧹 Nitpick (assertive)_

**DISASTER RETRIEVAL AND VALIDATION LOGIC.**

REPOSITORY INTERACTION AND DISASTER EXISTENCE VERIFICATION IMPLEMENTED CORRECTLY.

RECOMMENDATION: UTILIZE SPECIFIC ERROR TYPE FOR DISASTER NOT FOUND CASE INSTEAD OF GENERIC ERROR. CONSIDER CREATING 'DisasterNotFoundError' CLASS EXTENDING BaseError.

```diff
- throw new Error('Disaster not found');
+ throw new DisasterNotFoundError('Disaster not found');
```


> Committable suggestion skipped: line range outside the PR's diff.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-09T07:09:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,7 +20,19 @@ const getDisasters = async (req, res) => {
     const result = await coordinatorService.getDisasters(offset, parseInt(limit));
     return sendSuccessResponse(res, result, 'Disasters retrieved successfully');
   } catch (error) {
-    console.error('getDisasters error:', error);
+    return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
+  }
+};
+
+const closeDisaster = async (req, res) => {
+  try {
+    const coordinatorId = req.user.id;
+    const { disasterId } = req.params;
+    
+    const result = await coordinatorService.closeDisaster(coordinatorId, disasterId);
+    
+    return sendSuccessResponse(res, result, 'Disaster turned off successfully');
+  } catch (error) {
     return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
   }
 };
path: backend/src/controllers/coordinatorController.js
user: login: coderabbitai[bot]
body: _🧹 Nitpick (assertive)_

**CONTROLLER FUNCTION IMPLEMENTATION: DISASTER CLOSURE.**

FUNCTION IMPLEMENTATION FOLLOWS ESTABLISHED PATTERN:
1. EXTRACT COORDINATOR ID FROM REQUEST
2. EXTRACT DISASTER ID FROM URL PARAMETERS
3. CALL SERVICE FUNCTION
4. RETURN APPROPRIATE RESPONSE

SUGGESTION: MESSAGE "Disaster turned off successfully" COULD BE CHANGED TO "Disaster closed successfully" FOR TERMINOLOGY CONSISTENCY WITH STATUS VALUE.

```diff
- return sendSuccessResponse(res, result, 'Disaster turned off successfully');
+ return sendSuccessResponse(res, result, 'Disaster closed successfully');
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **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.

`````suggestion
const closeDisaster = async (req, res) => {
  try {
    const coordinatorId = req.user.id;
    const { disasterId } = req.params;
    
    const result = await coordinatorService.closeDisaster(coordinatorId, disasterId);
    
    return sendSuccessResponse(res, result, 'Disaster closed successfully');
  } catch (error) {
    return sendErrorResponse(res, error.message || 'Internal Server Error', error.statusCode || 500);
  }
};
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-09T07:09:56Z
author_association: CONTRIBUTOR

PR comments:
user: login: coderabbitai[bot]
created_at: 2025-04-09T07:07:45Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

<details>
<summary>📝 Walkthrough</summary>

## Summary by CodeRabbit

- **New Features**
  - Coordinators can now close disasters by specifying a disaster ID through a dedicated endpoint, streamlining disaster management.

- **Bug Fixes**
  - Error handling has been standardized across several management workflows, ensuring that error messages are returned directly to users for a clearer experience.
## Walkthrough
A new asynchronous function `closeDisaster` has been introduced across the backend. In the controller layer, it extracts the coordinator and disaster IDs from the request, calls the corresponding service, and returns a success response. The routing file now includes a PATCH endpoint to invoke this functionality. In the service layer, the function validates the disaster’s existence and the coordinator’s authorization, then updates the disaster status to 'Closed'. Additionally, error handling in multiple functions has been standardized to use `sendErrorResponse`. A minor formatting update was also made to the errors utility.

## Changes

| File(s) | Change Summary |
|---------|----------------|
| `backend/src/controllers/coordinatorController.js`<br>`backend/src/routes/coordinatorRoutes.js` | Added `closeDisaster` functionality: introduced an asynchronous function in the controller, updated error responses for multiple functions, and defined a new PATCH route to close disasters based on disaster ID. |
| `backend/src/services/coordinatorService.js` | Implemented a new `closeDisaster` function: validates disaster existence, coordinator authorization, updates disaster status to 'Closed', and persists the update. |
| `backend/src/utils/errors.js` | Applied minor formatting changes by adding two blank lines at the file end; no functional changes. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant C as Client
    participant R as Router
    participant CC as CoordinatorController
    participant CS as CoordinatorService
    participant DB as Database

    C->>R: PATCH /disasters/:disasterId/close
    R->>CC: closeDisaster(req, res)
    CC->>CS: closeDisaster(coordinatorId, disasterId)
    CS->>DB: Retrieve disaster by disasterId
    DB-->>CS: Return disaster data
    CS->>DB: Update disaster (status: Closed, endDate: now)
    DB-->>CS: Confirm update
    CS-->>CC: Return updated disaster
    CC-->>R: Send success response
    R-->>C: Return success response
```

## Possibly related PRs
- **Learnathon-By-Geeky-Solutions/3-brain-cell#30**: Involves modifications in `coordinatorService.js` related to disaster management, establishing a direct code-level connection with the `closeDisaster` functionality.

## Poem
> In circuits deep where data flies,  
> A disaster meets its swift goodbyes.  
> New routes and functions now align,  
> With error handling by design.  
> Beep boop, the code sings its tune—  
> A closed case under a digital moon! 🤖🚀

</details>

<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpADK2VmgqyjcEj2wAbb5AokAI7Y0riQ4rjedJAARABmJNQAFEz4FLTwGNRpAJRcaLT0ZLTc+JlhBIze+IieGYhoiDQUiDGQAO6NkIjYAszqNPRy4bCe2LV8bKMZYLCNmGAATADMAAyL6Bj0qPBKGOJx8NFdGE4ClJDLAKwaMKM8FPDMLvKCImKSnvhxI6i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VqSjxdBjQWStXdFrHKG6k0Ba23VFRqVAK8ACBPjd2oFG3FSEHGFwFKmQEQntH3hQEtT4IbF6yUHlnOEwWLETAGVxSfRfRmQzyUGIOzwvlz1/Xz3/ULwT2Lx2VAygG0XQFT3MMgPfTMNGVmR+E4KsPoAL3WTsO2RAzcin1BVanam8g/05DwHyi3ytxKjCnKkql3xqmGASgajUCajSgiIyhCn6FwAAH1dhEBCiAg4Rmk6BCjWRlkWo2o8iSABAAB2AARmWAYAEA6MaLiDiCuB6IABYWiGQABOAQYYwoJo1YBgVYOIFolopotAfopopYpogQOoyI/I9QYo2gUo8oo4McWgQotUfQIAA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Learnathon-By-Geeky-Solutions/3-brain-cell&utm_content=35):

- 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai plan` to trigger planning for file edits and PR creation.
- `@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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: CONTRIBUTOR
user: login: Warhammer4000
created_at: 2025-04-09T07:07:59Z
body: ![](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)

### :tada: **Snyk checks have passed. No issues have been found so far.**

:white_check_mark: **security/snyk** check is complete. No issues have been found. [(View Details)](https://app.snyk.io/org/warhammer4000/pr-checks/6377ec8e-1156-499e-aa24-c79ecb451b7d?refs=eb713cbcbebff5ff41da9b9dd70c0f117a47477b&source=prChecksComment)



author_association: CONTRIBUTOR