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

feat(signature-collection): Admin remove signature collection list #16217

Merged
merged 4 commits into from
Sep 30, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Sep 30, 2024

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new mutation for administrators to remove signature collection lists.
    • Added new API endpoints for retrieving area information, toggling list processing status, and locking recommendation lists.
    • Launched a new AdminApi class to enhance administrative functionalities.
  • Bug Fixes

    • Improved error handling for list deletion operations.
  • Documentation

    • Updated API schemas to reflect new properties and endpoints.

@juni-haukur juni-haukur requested a review from a team as a code owner September 30, 2024 15:08
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The changes introduce a new mutation method signatureCollectionAdminRemoveList in the SignatureCollectionAdminResolver class and a corresponding removeList method in the SignatureCollectionAdminService class, enabling administrators to remove signature collection lists by their IDs. Additionally, several new endpoints are added to the OpenAPI specification, enhancing the functionality of the MedmaeliRestAPI. The AdminApi class is introduced to extend administrative functionalities, and the SignatureCollectionAdminClientService is updated to utilize this new API for list removal.

Changes

Files Change Summary
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts
Added a new mutation method signatureCollectionAdminRemoveList in the resolver and a corresponding removeList method in the service for removing signature lists.
libs/clients/signature-collection/src/clientConfig.json Introduced new endpoints in the OpenAPI specification for retrieving area info, toggling list processing status, and locking lists, along with schema updates.
libs/clients/signature-collection/src/lib/apis.ts Added a new AdminApi class extending AdminClient, integrating it into the exported APIs.
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts Introduced a removeList method in SignatureCollectionAdminClientService, updated constructor to include adminApi, and modified the Api type to include AdminApi.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • kksteini
  • albinagu

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 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.

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.

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

🧹 Outside diff range and nitpick comments (4)
libs/clients/signature-collection/src/lib/apis.ts (1)

19-19: LGTM: New AdminApi class is well-structured.

The new AdminApi class follows the established pattern of other API classes in the file. It correctly extends the imported AdminClient and is properly exported.

For consistency with other class declarations, consider adding a blank line before and after this class declaration:

+
export class AdminApi extends AdminClient {}
+
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (1)

181-186: LGTM with suggestions for improvement

The implementation of the removeList method looks good and adheres to the coding guidelines. It's properly typed and follows the existing pattern in the service.

However, consider the following improvements:

  1. Add error handling to manage potential failures when calling signatureCollectionClientService.removeList.
  2. Include documentation (JSDoc) for the method to improve maintainability.

Here's an example of how you could improve the method:

/**
 * Removes a signature collection list.
 * @param listId - The ID of the list to remove.
 * @param user - The user performing the action.
 * @returns A promise that resolves to SignatureCollectionSuccess.
 * @throws An error if the list removal fails.
 */
async removeList(
  listId: string,
  user: User,
): Promise<SignatureCollectionSuccess> {
  try {
    return await this.signatureCollectionClientService.removeList(listId, user);
  } catch (error) {
    // Log the error or handle it as appropriate for your application
    throw new Error(`Failed to remove list: ${error.message}`);
  }
}
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

300-311: LGTM: New removeList method is well-implemented.

The removeList method is a good addition to the service. It follows TypeScript best practices, uses proper error handling, and maintains consistency with other methods in the class.

Suggestion for improvement:
Consider adding error logging to capture more details about failures. This could help with debugging and monitoring in production.

Example:

} catch (error) {
  console.error('Failed to remove list:', error);
  return { success: false, reasons: [ReasonKey.DeniedByService] }
}
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

198-205: Consider adding explicit authorization check and improve error handling.

The new mutation signatureCollectionAdminRemoveList looks good and follows the existing patterns in the class. However, consider the following improvements:

  1. Authorization: Although the class is decorated with @Scopes(AdminPortalScope.signatureCollectionProcess), it might be beneficial to add an explicit authorization check within the method, especially if removing a list requires higher privileges.

  2. Error Handling: While error handling might be implemented in the signatureCollectionService.removeList method, consider adding a try-catch block here to handle any unexpected errors and provide more informative error messages to the client.

Example implementation:

@Mutation(() => SignatureCollectionSuccess)
@Audit()
async signatureCollectionAdminRemoveList(
  @CurrentUser() user: User,
  @Args('input') { listId }: SignatureCollectionListIdInput,
): Promise<SignatureCollectionSuccess> {
  if (!user.scope.includes(AdminPortalScope.signatureCollectionManage)) {
    throw new UnauthorizedException('Insufficient permissions to remove list');
  }

  try {
    return await this.signatureCollectionService.removeList(listId, user);
  } catch (error) {
    // Log the error
    console.error('Error removing signature collection list:', error);
    throw new Error('Failed to remove signature collection list');
  }
}

This implementation adds an explicit authorization check and basic error handling, improving the robustness of the mutation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50e0899 and 7eb5dc2.

📒 Files selected for processing (5)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (1 hunks)
  • libs/clients/signature-collection/src/clientConfig.json (8 hunks)
  • libs/clients/signature-collection/src/lib/apis.ts (3 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/signature-collection/src/clientConfig.json (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/signature-collection/src/lib/apis.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (12)
libs/clients/signature-collection/src/lib/apis.ts (3)

8-8: LGTM: Import statement is consistent and well-structured.

The addition of AdminApi as AdminClient to the import statement is consistent with the existing code style and helps avoid naming conflicts. This change supports the introduction of the new AdminApi class.


79-79: LGTM: AdminApi correctly added to exportedApis array.

The addition of AdminApi to the exportedApis array is correct and consistent with the existing structure. This ensures that the new AdminApi will be properly provided and instantiated with the same configuration as other admin API classes.


Line range hint 1-124: Summary: New AdminApi successfully integrated into the signature collection client library.

The changes in this file effectively introduce the new AdminApi class and integrate it into the existing API structure. The modifications are consistent with the established patterns in the codebase and adhere to the coding guidelines for reusability and TypeScript usage.

Key points:

  1. The new AdminApi class is properly imported, declared, and exported.
  2. The exportedApis array is updated to include the AdminApi, ensuring it's provided and instantiated correctly.
  3. The changes maintain the existing configuration and injection setup, promoting consistency across admin API classes.

These changes align well with the PR objectives of enhancing administrative capabilities for the signature collection feature.

libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (3)

23-23: LGTM: Import and type definition updates are consistent with new functionality.

The addition of AdminApi to the imports and the Api type definition aligns well with the new removeList method. These changes maintain good TypeScript practices and support effective tree-shaking.

Also applies to: 32-32


42-42: LGTM: Constructor update enhances service capabilities.

The addition of private adminApi: AdminApi to the constructor is a good practice. It follows dependency injection principles, which enhances testability and maintainability of the service.


Line range hint 1-338: Overall assessment: Changes successfully implement new feature and maintain code quality.

The modifications to this file effectively implement the new feature for removing signature collection lists. The changes adhere to the coding guidelines, maintaining reusability, proper TypeScript usage, and supporting effective tree-shaking. The new functionality is well-integrated with the existing codebase, following established patterns and practices.

libs/clients/signature-collection/src/clientConfig.json (6)

180-215: Well-structured new admin endpoint for toggling list processing status.

The new PATCH endpoint /Admin/Medmaelalisti/{ID}/ToggleList is a good addition to the API. It provides a clear way for admins to toggle the processing status of a list. The optional shouldToggle parameter adds flexibility, and the response schemas are appropriate.


Line range hint 217-266: Well-defined new admin endpoint for locking recommendation lists.

The new PATCH endpoint /Admin/Medmaelalisti/{ID}/LockList is a valuable addition to the API. It provides a clear mechanism for admins to lock a recommendation list. The optional shouldLock parameter adds flexibility, and the response schemas are appropriate.


371-408: Useful new admin endpoint for retrieving area-specific information.

The new GET endpoint /Admin/Medmaelasofnun/{ID}/SvaediInfo/{svaediID} is a valuable addition to the API. It allows admins to retrieve detailed information about a specific area within a recommendation collection. The endpoint is well-documented, and the response schema (SvaediExtendedDTO) is appropriate for the purpose.


2169-2169: Improved DTOs with additional properties for recommendation lists.

The updates to MedmaelalistiBaseDTO and MedmaelalistiDTO, along with the introduction of MedmaelalistiExtendedDTO, enhance the API's capability to provide more detailed information about recommendation lists. The consistent addition of the urvinnslaLokid property and the new extended DTO with additional fields for electronic and written recommendations improve the overall functionality of the API.

Also applies to: 2186-2186, 2196-2219


2393-2394: Enhanced MedmaeliDTO with locking information.

The addition of the locked property to the MedmaeliDTO schema is a good improvement. This change aligns with the new locking functionality introduced by the LockList endpoint and enhances the API's capability to represent the locked state of recommendations.


Line range hint 1-2471: Overall improvement in API functionality and admin capabilities.

The changes introduced in this update significantly enhance the MedmaeliRestAPI. New admin endpoints for toggling list processing status, locking recommendation lists, and retrieving area-specific information provide more granular control and insight. The updates to various DTOs, including the addition of the urvinnslaLokid and locked properties, as well as the introduction of the MedmaelalistiExtendedDTO, improve the API's ability to represent and manage recommendation lists and individual recommendations.

These changes collectively contribute to a more robust and feature-rich API, particularly for administrative functions. The consistent documentation and appropriate use of response schemas maintain the API's overall quality and usability.

@juni-haukur juni-haukur added the automerge Merge this PR as soon as all checks pass label Sep 30, 2024
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.

Project coverage is 36.66%. Comparing base (29a1854) to head (5b3db28).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tion/src/lib/signature-collection-admin.service.ts 16.66% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16217      +/-   ##
==========================================
- Coverage   36.77%   36.66%   -0.11%     
==========================================
  Files        6784     6781       -3     
  Lines      139833   139716     -117     
  Branches    39763    39728      -35     
==========================================
- Hits        51429    51233     -196     
- Misses      88404    88483      +79     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.63% <28.57%> (-0.01%) ⬇️
application-template-api-modules 23.74% <ø> (-0.02%) ⬇️
application-templates-car-recycling 3.12% <ø> (ø)
application-ui-shell 21.29% <ø> (ø)
download-service 44.75% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
libs/clients/signature-collection/src/lib/apis.ts 96.55% <100.00%> (+0.12%) ⬆️
...tion/src/lib/signature-collection-admin.service.ts 13.91% <16.66%> (+0.15%) ⬆️

... and 33 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29a1854...5b3db28. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 30, 2024

Datadog Report

All test runs a6519fb 🔗

7 Total Test Services: 0 Failed, 6 Passed
🔻 Test Sessions change in coverage: 2 decreased, 1 increased (+0.04%), 34 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.87s 1 no change Link
application-system-api 0 0 0 111 2 3m 21.17s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 49.86s 1 decreased (-0.01%) Link
application-ui-shell 0 0 0 74 0 33.34s 1 no change Link
download-service 0 0 0 1 0 22.19s 1 no change Link
service-portal-core 0 0 0 5 0 1.95s N/A Link
service-portal-health 0 0 0 0 0 560.52ms 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • api-domains-signature-collection - jest 13.21% (-0.1%) - Details
  • application-template-api-modules - jest 25.74% (-0.01%) - Details

@oddsson oddsson added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Sep 30, 2024
@kodiakhq kodiakhq bot merged commit 95b39ac into main Sep 30, 2024
51 checks passed
@kodiakhq kodiakhq bot deleted the feat/admin-remove-signature-collection-list branch September 30, 2024 22:50
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
…16217)

* admin remove list endpoint

* add new admin api

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants