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(cms): Be able to query organization by national id #17122

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

baering
Copy link
Member

@baering baering commented Dec 4, 2024

What

  • Refactor getOrganization and getOrganizationByX to use a utility function
  • Add getOrganizationByNationalId

Why

To be able to query organizations by national id

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 method to retrieve organizations by national ID.
    • Enhanced flexibility in organization retrieval with a new querying method.
  • Bug Fixes
    • Improved error handling across organization retrieval methods for better reliability.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request involve significant refactoring of the CmsContentfulService class within the cms.contentful.service.ts file. The getOrganization method has been split into two methods: getOrganizationBy for flexible querying and a modified getOrganization that retains its original functionality. New methods for retrieving organizations by title, reference ID, and national ID have been added, enhancing the service's querying capabilities while maintaining existing error handling practices.

Changes

File Path Change Summary
libs/cms/src/lib/cms.contentful.service.ts - Refactored getOrganization into getOrganizationBy (private) and a modified getOrganization.
- Simplified getOrganizationByTitle and getOrganizationByReferenceId to call getOrganizationBy.
- Added getOrganizationByNationalId method.
- Updated method signatures for organization retrieval.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • siggifv

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning storybook > @storybook/cli > tempy > del > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning next-auth > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning next-auth > [email protected]: this version is no longer supported
warning next-auth > @next-auth/typeorm-legacy-adapter > typeorm > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > stylus > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @nx/next > @nx/webpack > fork-ts-checker-webpack-plugin > [email protected]: this will be v4
warning @nx/next > @nx/webpack > webpack-dev-server > webpack-dev-middleware > [email protected]: this will be v4
warning workspace-aggregator-bbfedfd4-4583-4a95-a8b3-a57ef86aa9d7 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning "@nx/eslint > @nx/js > [email protected]" has unmet peer dependency "@types/node@".
warning "@nx/next > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "styled-components > babel-plugin-styled-components > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > [email protected]" has unmet peer dependency "react-is@>= 16.8.0".
warning "@nx/react > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > [email protected]" has unmet peer dependency "@types/node@
".
warning "@vanilla-extract/next-plugin > @vanilla-extract/[email protected]" has unmet peer dependency "webpack@^4.30.0 || ^5.20.2".
warning " > [email protected]" has incorrect peer dependency "react@^16.13.1 || ^17".
warning " > [email protected]" has incorrect peer dependency "react-dom@^16.13.1 || ^17".
warning "next-auth > @next-auth/[email protected]" has unmet peer dependency "@prisma/client@^2.16.1".
warning " > [email protected]" has incorrect peer dependency "next@^13.4".
warning "@nx/next > [email protected]" has unmet peer dependency "webpack@^5.1.0".


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.

@baering baering marked this pull request as ready for review December 4, 2024 10:22
@baering baering requested review from a team as code owners December 4, 2024 10:22
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 (2)
libs/cms/src/lib/cms.contentful.service.ts (2)

Line range hint 351-375: Consider adding input validation for fieldName parameter.

The utility method effectively centralizes organization querying logic. However, consider validating the fieldName parameter against a list of allowed fields to prevent potential runtime errors from invalid field names.

+ const ALLOWED_ORGANIZATION_FIELDS = ['slug', 'title', 'referenceIdentifier', 'kennitala'] as const;
+ type OrganizationField = typeof ALLOWED_ORGANIZATION_FIELDS[number];

  private async getOrganizationBy(
-   fieldName: string,
+   fieldName: OrganizationField,
    fieldValue: string,
    lang: string,
    requireFieldValue = false,
  ): Promise<Organization | null> {
+   if (!ALLOWED_ORGANIZATION_FIELDS.includes(fieldName)) {
+     throw new Error(`Invalid field name: ${fieldName}`);
+   }

398-403: Consider adding national ID format validation.

While the implementation is correct, consider adding validation for the national ID format to ensure data integrity.

  async getOrganizationByNationalId(
    nationalId: string,
    lang: string,
  ): Promise<Organization | null> {
+   // Icelandic national ID format: DDMMYY-XXXX
+   const nationalIdRegex = /^\d{6}-?\d{4}$/;
+   if (!nationalIdRegex.test(nationalId)) {
+     throw new Error('Invalid national ID format. Expected format: DDMMYY-XXXX');
+   }
    return this.getOrganizationBy('kennitala', nationalId, lang, true)
  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14b2142 and e117c52.

📒 Files selected for processing (1)
  • libs/cms/src/lib/cms.contentful.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/cms/src/lib/cms.contentful.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 (3)
libs/cms/src/lib/cms.contentful.service.ts (3)

377-382: LGTM! Clean refactor maintaining backward compatibility.

The refactored method effectively uses the new utility while maintaining its original contract and behavior.


384-389: LGTM! Effective use of Contentful's match operator.

The refactored method correctly uses the match operator for title search while maintaining its original behavior.


391-396: LGTM! Clean refactor using the utility method.

The refactored method effectively uses the new utility while maintaining its original behavior.

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 35.72%. Comparing base (4dec76c) to head (2f8bc91).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
libs/cms/src/lib/cms.contentful.service.ts 0.00% 10 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17122   +/-   ##
=======================================
  Coverage   35.72%   35.72%           
=======================================
  Files        6920     6920           
  Lines      147485   147480    -5     
  Branches    41988    41987    -1     
=======================================
  Hits        52686    52686           
+ Misses      94799    94794    -5     
Flag Coverage Δ
api 3.34% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-communications 39.36% <0.00%> (ø)
application-system-api 38.76% <0.00%> (+<0.01%) ⬆️
application-template-api-modules 27.78% <0.00%> (+<0.01%) ⬆️
cms 0.40% <0.00%> (ø)
cms-translations 38.69% <0.00%> (ø)
judicial-system-api 19.99% <ø> (ø)
judicial-system-backend 55.74% <0.00%> (ø)
services-user-notification 46.53% <0.00%> (ø)

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

Files with missing lines Coverage Δ
libs/cms/src/lib/cms.contentful.service.ts 9.89% <0.00%> (ø)

... and 1 file 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 4dec76c...2f8bc91. Read the comment docs.

@baering baering added the automerge Merge this PR as soon as all checks pass label Dec 4, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented Dec 4, 2024

Datadog Report

All test runs 6581f72 🔗

10 Total Test Services: 0 Failed, 9 Passed
➡️ Test Sessions change in coverage: 28 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.01s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.48s 1 no change Link
api-domains-communications 0 0 0 5 0 36.42s 1 no change Link
api-domains-license-service 0 0 0 0 0 517.38ms 1 no change Link
application-system-api 0 0 0 46 0 2m 6.53s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 37.83s 1 no change Link
cms-translations 0 0 0 3 0 31.12s 1 no change Link
judicial-system-api 0 0 0 61 0 6.58s 1 no change Link
judicial-system-backend 0 0 0 21185 0 22m 11.06s 1 no change Link
services-user-notification 0 0 0 51 0 1m 37.87s 1 no change Link

@kodiakhq kodiakhq bot merged commit 4a229a4 into main Dec 4, 2024
61 checks passed
@kodiakhq kodiakhq bot deleted the feat/query-organization-by-nationalid branch December 4, 2024 11:27
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.

2 participants