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(application-system): built in notifications #16352

Merged
merged 12 commits into from
Oct 21, 2024
Merged

Conversation

obmagnusson
Copy link
Member

@obmagnusson obmagnusson commented Oct 10, 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

    • Enhanced notification system with the introduction of NotificationsService for improved error handling and validation.
    • Added new ApplicationsNotificationsModule to various templates for streamlined notification management.
  • Bug Fixes

    • Updated methods to ensure consistent use of NotificationsService for sending notifications.
  • Documentation

    • Updated API configuration to include NotificationsApi alongside existing APIs.

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 40.81633% with 58 lines in your changes missing coverage. Please review.

Project coverage is 36.70%. Comparing base (40811a5) to head (9927039).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...nce-change-v2/children-residence-change.service.ts 15.25% 50 Missing ⚠️
...ules/src/lib/notification/notifications.service.ts 50.00% 5 Missing ⚠️
...s/reference-template/reference-template.service.ts 50.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16352      +/-   ##
==========================================
- Coverage   36.77%   36.70%   -0.07%     
==========================================
  Files        6838     6816      -22     
  Lines      141603   141433     -170     
  Branches    40338    40243      -95     
==========================================
- Hits        52069    51909     -160     
+ Misses      89534    89524      -10     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.38% <40.81%> (+0.02%) ⬆️
application-template-api-modules 27.78% <0.00%> (-0.08%) ⬇️
application-ui-shell 21.37% <ø> (ø)
nest-aws ?

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

Files with missing lines Coverage Δ
apps/application-system/api/src/app/app.module.ts 100.00% <100.00%> (ø)
...ence-change-v2/children-residence-change.module.ts 100.00% <100.00%> (ø)
...es/reference-template/reference-template.module.ts 100.00% <100.00%> (ø)
...dules/src/lib/notification/notifications.module.ts 100.00% <100.00%> (ø)
...les/src/lib/notification/notificationsTemplates.ts 100.00% <100.00%> (ø)
...ates/reference-template/src/dataProviders/index.ts 100.00% <100.00%> (ø)
...e-template/src/lib/ReferenceApplicationTemplate.ts 58.69% <ø> (ø)
...ents/user-notification/src/lib/apiConfiguration.ts 100.00% <100.00%> (ø)
...s/reference-template/reference-template.service.ts 73.52% <50.00%> (-2.34%) ⬇️
...ules/src/lib/notification/notifications.service.ts 50.00% <50.00%> (ø)
... and 1 more

... and 240 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 40811a5...9927039. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 14, 2024

Datadog Report

All test runs efbce72 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 2 decreased, 8 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.62s 1 no change Link
application-system-api 0 0 0 120 2 3m 11.37s 1 decreased (-0.07%) Link
application-template-api-modules 0 0 0 123 0 2m 16.67s 1 decreased (-0.05%) Link
application-ui-shell 0 0 0 74 0 31.44s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • application-system-api - jest 36.95% (-0.07%) - Details
  • application-template-api-modules - jest 30.04% (-0.05%) - Details

@norda-gunni norda-gunni marked this pull request as ready for review October 16, 2024 11:40
@norda-gunni norda-gunni requested review from a team as code owners October 16, 2024 11:40
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve the integration of UserNotificationClientConfig into the AppModule of the application system API and significant updates to the notification system across various modules. These updates include the introduction of a new NotificationsService, modifications to existing services to utilize this new service for notifications, and enhancements to various templates and types related to notifications. The overall structure of the application remains intact while improving the notification handling capabilities.

Changes

File Path Change Summary
apps/application-system/api/src/app/app.module.ts Added import for UserNotificationClientConfig and included it in ConfigModule.forRoot.
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.module.ts Added import for ApplicationsNotificationsModule.
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts Updated constructor to use NotificationsService and added ConfigService. Refactored notification methods.
libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.module.ts Added ApplicationsNotificationsModule to imports.
libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.service.ts Injected NotificationsService and updated getReferenceData method to include auth parameter.
libs/application/template-api-modules/src/lib/notification/notificationTypes.ts Introduced new types for notifications.
libs/application/template-api-modules/src/lib/notification/notifications.module.ts Added new module ApplicationsNotificationsModule.
libs/application/template-api-modules/src/lib/notification/notifications.service.ts Created NotificationsService for handling notifications.
libs/application/template-api-modules/src/lib/notification/notificationsTemplates.ts Added NotificationType enum and NotificationConfig constant.
libs/application/templates/reference-template/src/dataProviders/index.ts Updated to replace NationalRegistryUserApi with NationalRegistryApi.
libs/application/templates/reference-template/src/forms/Prerequisites.ts Updated imports and changed provider to NationalRegistryApi.
libs/clients/user-notification/src/lib/apiConfiguration.ts Updated exportedApis array to include NotificationsApi.

Possibly related PRs

  • chore(j-s): SMS and Email Config #15514: This PR modifies the app.module.ts file in the application-system API to include new configurations for SMS and email services, which is relevant to the changes made in the main PR that also involves modifications to the app.module.ts file for adding UserNotificationClientConfig.
  • feat(user-notifications): Send notificationId in push notifications #15962: This PR enhances the notification dispatching process by adding a notificationId parameter, which relates to the overall notification system being integrated in the main PR through the addition of UserNotificationClientConfig.

Suggested labels

automerge, high priority

Suggested reviewers

  • unakb
  • thoreyjona
  • saevarma
  • jonnigs
  • oddsson

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: 11

🧹 Outside diff range and nitpick comments (8)
libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.module.ts (1)

10-10: LGTM: Addition of ApplicationsNotificationsModule to imports

The addition of ApplicationsNotificationsModule to the imports array is consistent with the new import statement and allows the ReferenceTemplateModule to use functionalities from the notifications module. This change adheres to the NestJS module structure.

For improved readability, consider formatting the imports array vertically when it contains multiple items:

imports: [
  SharedTemplateAPIModule,
  ApplicationsNotificationsModule,
],
libs/clients/user-notification/src/lib/apiConfiguration.ts (1)

11-27: LGTM: exportedApis array updated correctly with a minor suggestion

The addition of NotificationsApi to the exportedApis array expands the functionality of the user notification client while maintaining reusability across different NextJS apps. The mapping function ensures both APIs use the same configuration and factory function, which is efficient and consistent.

The change adheres to the coding guidelines:

  • It maintains reusability of components across different NextJS apps.
  • It uses TypeScript for defining types.
  • It continues to use createEnhancedFetch, which is good for effective bundling.

For improved readability, consider extracting the configuration object into a separate constant:

const apiConfig = (config: ConfigType<typeof UserNotificationClientConfig>) => ({
  fetchApi: createEnhancedFetch({
    name: 'clients-user-notification',
    organizationSlug: 'stafraent-island',
  }),
  basePath: `${config.basePath}`,
});

export const exportedApis = [UserNotificationApi, NotificationsApi].map(
  (Api) => ({
    provide: Api,
    scope: LazyDuringDevScope,
    useFactory: (config: ConfigType<typeof UserNotificationClientConfig>) =>
      new Api(new Configuration(apiConfig(config))),
    inject: [UserNotificationClientConfig.KEY],
  }),
);

This refactoring would make the code more modular and easier to maintain.

libs/application/templates/reference-template/src/dataProviders/index.ts (3)

3-6: Remove unused import UserProfileApi

The UserProfileApi is imported but not used in this file. To maintain clean and efficient code, it's recommended to remove unused imports.

Apply this diff to remove the unused import:

 import {
   NationalRegistryUserApi,
-  UserProfileApi,
 } from '@island.is/application/types'

40-42: LGTM: New NationalRegistryApi configuration

The addition of NationalRegistryApi is consistent with the existing pattern and enhances the API definitions. The order property ensures it runs before ReferenceDataApi.

Consider adding a comment to explain the purpose of this API and why it needs to run first.

You could add a comment like this:

export const NationalRegistryApi = NationalRegistryUserApi.configure({
  order: 1, // Runs first to fetch user data from the National Registry
})

Line range hint 45-47: Remove duplicate MyParameterType interface

The MyParameterType interface is duplicated at the end of the file. To maintain clean and maintainable code, it's recommended to remove this duplicate definition.

Apply this diff to remove the duplicate interface:

-export interface MyParameterType {
-  id: number
-}
libs/application/template-api-modules/src/lib/notification/notificationsTemplates.ts (1)

12-45: LGTM: Well-structured notification configuration with type safety

The NotificationConfig constant is well-implemented:

  • It provides a clear mapping between notification types and their configurations.
  • The use of type assertions for the keys property ensures type safety.
  • The structure supports reusability across different NextJS apps.

Consider using a more robust type definition for the keys property. Instead of using type assertions, you could define an interface for each notification type's keys. This would provide better type checking and autocompletion. For example:

interface SystemNotificationKeys {
  documentId: string;
}

interface ChildrenResidenceChangeKeys {
  applicantName: string;
  applicationId: string;
}

// ... define interfaces for other notification types

export const NotificationConfig: Record<NotificationType, {
  templateId: string;
  keys: SystemNotificationKeys | ChildrenResidenceChangeKeys | ... // union of all key types
}> = {
  [NotificationType.System]: {
    templateId: 'HNIPP.TEST.INBOX.TEMPLATE',
    keys: {} as SystemNotificationKeys,
  },
  // ... other configurations
};

This approach would provide stronger type checking and better IDE support.

libs/application/templates/reference-template/src/forms/Prerequisites.ts (1)

14-19: LGTM with a minor suggestion for import organization.

The changes to the import statements look good and align with the coding guidelines. The separate import for UserProfileApi and the replacement of NationalRegistryUserApi with NationalRegistryApi improve code organization and potentially enhance reusability.

Consider grouping related imports together for better readability. For example:

import { UserProfileApi } from '@island.is/application/types'
import {
  ReferenceDataApi,
  NationalRegistryApi,
  MyMockProvider,
} from '../dataProviders'

This groups external and internal imports separately, which is a common practice in TypeScript projects.

libs/application/templates/reference-template/src/lib/ReferenceApplicationTemplate.ts (1)

Line range hint 120-124: Approve API configuration change with minor suggestion

The update to use NationalRegistryApi is consistent with the import changes and maintains the existing functionality. The TypeScript usage for defining props is correctly maintained.

Consider extracting the ageToValidate value to a constant at the top of the file for better maintainability:

const AGE_TO_VALIDATE = 18;

// Then use it in the configuration:
NationalRegistryApi.configure({
  params: {
    ageToValidate: AGE_TO_VALIDATE,
  },
}),

This change would improve readability and make it easier to update the age requirement if needed in the future.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 83b076f and bb9878c.

📒 Files selected for processing (13)
  • apps/application-system/api/src/app/app.module.ts (2 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.module.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (4 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.module.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.service.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notificationTypes.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notifications.module.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notifications.service.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notificationsTemplates.ts (1 hunks)
  • libs/application/templates/reference-template/src/dataProviders/index.ts (2 hunks)
  • libs/application/templates/reference-template/src/forms/Prerequisites.ts (2 hunks)
  • libs/application/templates/reference-template/src/lib/ReferenceApplicationTemplate.ts (2 hunks)
  • libs/clients/user-notification/src/lib/apiConfiguration.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
apps/application-system/api/src/app/app.module.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.module.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/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.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/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.module.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/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.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/application/template-api-modules/src/lib/notification/notificationTypes.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/application/template-api-modules/src/lib/notification/notifications.module.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/application/template-api-modules/src/lib/notification/notifications.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/application/template-api-modules/src/lib/notification/notificationsTemplates.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/application/templates/reference-template/src/dataProviders/index.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/application/templates/reference-template/src/forms/Prerequisites.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/application/templates/reference-template/src/lib/ReferenceApplicationTemplate.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/user-notification/src/lib/apiConfiguration.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 (27)
libs/application/template-api-modules/src/lib/notification/notificationTypes.ts (4)

3-3: LGTM: Well-defined type for NotificationConfig

The NotificationConfigType is correctly defined using the typeof operator, which ensures type safety and easy maintenance as it will automatically update if NotificationConfig changes.


4-4: LGTM: Effective type definition for notification keys

The NotificationTypeKey type is well-defined using keyof typeof, providing a type-safe way to reference keys in NotificationConfig. This enhances code quality by enabling autocomplete and type checking for notification types.


5-6: Excellent use of advanced TypeScript features

The NotificationArgs<T> generic type is a great example of leveraging TypeScript's advanced features. It provides a type-safe way to access notification arguments specific to each notification type, enhancing code quality and developer experience.

This implementation promotes:

  1. Type safety when working with notification arguments
  2. Code reusability across different parts of the application
  3. Better IDE support with autocomplete for specific notification types

1-6: Excellent implementation of notification types

This file demonstrates high-quality TypeScript code that adheres to the coding guidelines for the libs directory:

  1. It promotes reusability by exporting well-defined types.
  2. It effectively uses TypeScript for defining and exporting types.
  3. The lightweight type definitions should not interfere with tree-shaking and bundling.

The three type definitions work together to create a comprehensive and type-safe system for handling notifications. The use of advanced TypeScript features like typeof, keyof, and generics showcases a deep understanding of the language and promotes maintainable, self-documenting code.

libs/application/template-api-modules/src/lib/notification/notifications.module.ts (3)

1-4: Imports look good and align with coding guidelines.

The imports are correctly using TypeScript, which is in line with the coding guidelines for files in the libs directory. The use of @island.is/clients/user-notification suggests good modularity and potential for reusability across different NextJS apps.


6-11: Module structure adheres to best practices and coding guidelines.

The ApplicationsNotificationsModule is well-structured and follows NestJS best practices. It correctly uses the @Module decorator and properly imports, provides, and exports the necessary components. This structure promotes reusability across different NextJS apps, which aligns with the coding guidelines for the libs directory.

The module also seems to follow effective tree-shaking practices by only importing and exporting what's necessary, which is crucial for optimal bundling.


1-11: Overall, excellent implementation of the ApplicationsNotificationsModule.

This new module is well-structured, follows NestJS best practices, and adheres to the coding guidelines for the libs directory. It promotes reusability and effective tree-shaking, which are crucial for optimal performance across different NextJS apps. The introduction of this module seems to be a valuable addition to the application system, potentially enhancing the notification handling capabilities.

libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.module.ts (2)

8-8: LGTM: Import statement for ApplicationsNotificationsModule

The import statement is correctly formatted and follows TypeScript conventions. It also aligns with the guideline for reusability across different NextJS apps by importing from within the same library.


Line range hint 1-14: Adherence to coding guidelines for libs//* files**

The changes in this file adhere to the specified coding guidelines:

  1. Reusability: The module structure allows for reuse across different NextJS apps.
  2. TypeScript usage: The file correctly uses TypeScript for module definition.
  3. Tree-shaking: The specific imports and exports support effective tree-shaking and bundling practices.
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.module.ts (3)

7-7: LGTM: Import statement for notifications module.

The import of ApplicationsNotificationsModule is correctly formatted and aligns with the PR objective of integrating built-in notifications.


15-15: LGTM: Integration of ApplicationsNotificationsModule.

The addition of ApplicationsNotificationsModule to the imports array correctly integrates the notifications functionality into the ChildrenResidenceChangeModuleV2. This change is consistent with the new import statement and follows NestJS module structure.


Line range hint 1-21: Verification: Compliance with coding guidelines for libs//* files.**

The changes in this file adhere to the coding guidelines:

  1. The module maintains its reusability across different NextJS apps.
  2. TypeScript is used appropriately for defining the module structure.
  3. The changes do not negatively impact tree-shaking or bundling practices.

However, to ensure full compliance, please verify that the imported ApplicationsNotificationsModule is also designed with reusability in mind.

To confirm the reusability of the ApplicationsNotificationsModule, please run the following script:

libs/clients/user-notification/src/lib/apiConfiguration.ts (1)

4-8: LGTM: Import statement updated correctly

The addition of NotificationsApi to the import statement is consistent with its usage in the exportedApis array. This change follows TypeScript best practices and adheres to the coding guidelines for TypeScript usage in library components.

libs/application/templates/reference-template/src/dataProviders/index.ts (2)

13-13: LGTM: Addition of order property

The addition of the order property to ReferenceDataApi is consistent with the existing pattern and helps in defining the execution order of API calls.


Line range hint 1-47: Overall review summary

The changes in this file enhance the API definitions by introducing new configurations and properties. The code adheres to the coding guidelines for reusability and TypeScript usage. Minor improvements have been suggested to remove an unused import and a duplicate interface definition. After addressing these minor issues, the code will be in excellent shape.

libs/application/template-api-modules/src/lib/notification/notificationsTemplates.ts (2)

1-10: LGTM: Well-structured and type-safe enum implementation

The NotificationType enum is well-implemented, following TypeScript best practices:

  • It uses string literal types for improved type safety.
  • The naming convention is consistent and descriptive.
  • The enum is exported, allowing reuse across different modules.

This implementation supports effective tree-shaking and bundling practices.


1-45: Overall: Excellent adherence to coding guidelines and best practices

This file demonstrates excellent adherence to the coding guidelines for libs/**/*:

  1. The code is structured to support reusability across different NextJS apps.
  2. TypeScript is used effectively for defining props (in this case, notification configurations) and exporting types.
  3. The implementation supports effective tree-shaking and bundling practices.

The clear separation of concerns between the NotificationType enum and the NotificationConfig object enhances maintainability and scalability. The use of TypeScript's type system ensures type safety throughout the notification system.

Great job on creating a well-structured and type-safe foundation for the notification system!

libs/application/templates/reference-template/src/forms/Prerequisites.ts (1)

Line range hint 1-124: Overall changes adhere to coding guidelines and improve code organization.

The modifications in this file are focused on import statements and data provider configuration, while maintaining the overall structure of the form. These changes align well with the coding guidelines for files in the libs directory:

  1. Reusability: The updated import structure and data provider configuration potentially enhance the reusability of components across different NextJS apps.
  2. TypeScript usage: The changes maintain proper TypeScript usage for defining types and exports.
  3. Effective tree-shaking: The more specific imports (e.g., separate import for UserProfileApi) can contribute to better tree-shaking and bundling practices.

The changes improve code organization without altering the core functionality of the form, which is a positive approach to code maintenance and evolution.

apps/application-system/api/src/app/app.module.ts (3)

63-63: LGTM: Import statement for UserNotificationClientConfig

The import statement for UserNotificationClientConfig is correctly added and follows the established pattern for importing client configurations in this module.


Line range hint 1-128: Summary: Integration of UserNotificationClientConfig

The changes in this file successfully integrate the UserNotificationClientConfig into the AppModule. This addition aligns with the PR objective of building in notifications to the application system. The modifications are minimal, focused, and adhere to the existing code structure and TypeScript best practices.

Key points:

  1. The import statement is correctly added.
  2. The configuration is properly integrated into the ConfigModule.forRoot method.
  3. The changes should enable user notification functionality without disrupting existing features.

These modifications lay the groundwork for implementing user notifications in the application system. Ensure that any related components or services that will use this configuration are also updated accordingly.


123-123: LGTM: Integration of UserNotificationClientConfig

The UserNotificationClientConfig is correctly added to the load array in the ConfigModule.forRoot method, following the established pattern for configuration integration.

To ensure proper setup, please verify that any necessary environment variables or additional configurations for the UserNotificationClientConfig are in place. Run the following script to check for any related environment variables:

✅ Verification successful

Verified: UserNotificationClientConfig Integration Confirmed

The UserNotificationClientConfig integration in the ConfigModule.forRoot method has been successfully verified. Configuration is handled within the codebase without reliance on external environment variables.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for UserNotificationClientConfig related environment variables

# Test: Search for environment variables related to UserNotificationClientConfig
rg --type dotenv 'USER_NOTIFICATION|NOTIFICATION' .env*

Length of output: 101


Script:

#!/bin/bash
# Description: Check for UserNotificationClientConfig related environment variables

# Test: Search for environment variables related to UserNotificationClientConfig
rg 'USER_NOTIFICATION|NOTIFICATION' .env*

Length of output: 56


Script:

#!/bin/bash
# Description: Search the codebase for all occurrences of UserNotificationClientConfig

# Search for the keyword in all relevant files
rg 'UserNotificationClientConfig' .

Length of output: 1098

libs/application/templates/reference-template/src/lib/ReferenceApplicationTemplate.ts (1)

Line range hint 1-364: Summary: Changes adhere to coding guidelines

The modifications in this file, specifically the import changes and API configuration update, adhere to the coding guidelines for the libs/**/* pattern:

  1. Reusability: The change to use a local import for NationalRegistryApi improves reusability across different NextJS apps.
  2. TypeScript usage: The code maintains proper TypeScript usage for defining props and types.
  3. Tree-shaking and bundling: The changes don't negatively impact effective tree-shaking and bundling practices.

Overall, the changes are minimal, focused, and align well with the project's coding standards.

libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.service.ts (5)

13-14: Imports added correctly for notification functionality

The import statements for NotificationsService and NotificationType are correctly added and necessary for the notification functionality.


21-21: Dependency injection of NotificationsService added

The NotificationsService is correctly injected into the constructor, enabling notification capabilities within the service.


26-26: 'auth' parameter added to method signature

The auth parameter is appropriately added to the getReferenceData method, allowing access to authentication information needed for sending notifications.


29-32: Retrieval of applicant's full name

The applicantName is correctly retrieved from application.externalData, ensuring the accurate name is used in notifications.


55-55: Updated return value includes 'applicantName'

The return data now correctly includes applicantName, ensuring consistent usage of the variable.

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: 1

🧹 Outside diff range and nitpick comments (5)
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (5)

Line range hint 1-43: LGTM! Consider using type inference for ConfigService.

The changes to imports and constructor align well with the transition to a unified notification system. The use of TypeScript for imports and type definitions is good for maintainability.

Consider using type inference for ConfigService instead of explicitly specifying SharedModuleConfig:

- private readonly configService: ConfigService<SharedModuleConfig>,
+ private readonly configService: ConfigService,

This change allows for better flexibility if the config structure changes in the future.


169-195: LGTM! Consider extracting the notification logic.

The changes in the sendNotificationToCounterParty method effectively address the previous issue of potential undefined access and align well with the new unified notification system.

Consider extracting the notification logic into a separate private method for better readability and reusability:

private sendCounterPartyNotification(applicant: any, otherParent: any, contractLink: string) {
  this.notificationsService.sendNotification({
    type: NotificationType.AssignCounterParty,
    messageParties: {
      recipient: otherParent.nationalId,
      sender: applicant.nationalId,
    },
    args: {
      applicantName: applicant.fullName,
      contractLink,
    },
  });
}

Then call this method in sendNotificationToCounterParty:

if (otherParent) {
  this.sendCounterPartyNotification(applicant, otherParent, contractLink);
}

This refactoring improves the method's readability and makes the notification logic more reusable.


201-242: LGTM! Consider consolidating duplicate notification logic.

The changes in the approvedByOrganization method effectively address the previous issue of potential undefined access and align well with the new unified notification system.

Consider consolidating the duplicate notification logic into a single method call:

private sendApprovalNotification(recipientId: string, applicationLink: string, caseNumber: string) {
  this.notificationsService.sendNotification({
    type: NotificationType.ChildrenResidenceChangeApprovedByOrg,
    messageParties: {
      recipient: recipientId,
    },
    args: {
      applicationLink,
      caseNumber: caseNumber || '',
    },
  });
}

Then in the approvedByOrganization method:

this.sendApprovalNotification(applicant.nationalId, applicationLink, caseNumber || '');
this.sendApprovalNotification(otherParent.nationalId, applicationLink, caseNumber || '');

This refactoring reduces code duplication and improves maintainability.


270-313: LGTM! Consider extracting common logic for notifications.

The changes in the rejectedByOrganization method effectively address the previous issue of potential undefined access and align well with the new unified notification system. The addition of error handling for missing custody information and other parent data is a good improvement.

Consider extracting the common notification logic into a separate method to reduce duplication:

private sendRejectionNotification(recipientId: string, orgName: string) {
  this.notificationsService.sendNotification({
    type: NotificationType.RejectedByOrganization,
    messageParties: {
      recipient: recipientId,
    },
    args: {
      orgName,
    },
  });
}

Then in the rejectedByOrganization method:

this.sendRejectionNotification(applicant.nationalId, syslumennName);
this.sendRejectionNotification(otherParent.nationalId, syslumennName);

This refactoring improves code maintainability and reduces the risk of inconsistencies between notifications.


315-323: LGTM! Consider using template literals for URL construction.

The new getApplicationLink method is a good addition that centralizes the link generation logic, improving code reusability. The use of the injected ConfigService aligns well with dependency injection principles.

Consider using template literals for cleaner URL construction:

private async getApplicationLink(application: CRCApplication) {
  const clientLocationOrigin = getConfigValue(
    this.configService,
    'clientLocationOrigin',
  ) as string

  const slug = getSlugFromType(application.typeId) as string
  return `${clientLocationOrigin}/${slug}/${application.id}` as string
}

This change makes the URL construction more readable and less prone to errors from string concatenation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb9878c and da390d0.

📒 Files selected for processing (3)
  • libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (4 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.service.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notifications.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/application/template-api-modules/src/lib/notification/notifications.service.ts
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.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/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.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 (7)
libs/application/template-api-modules/src/lib/modules/templates/reference-template/reference-template.service.ts (5)

13-14: LGTM: Imports for notification functionality added correctly

The new imports for NotificationsService and NotificationType are correctly added and follow TypeScript conventions. These specific imports will aid in effective tree-shaking.


21-21: LGTM: NotificationsService correctly injected

The NotificationsService is properly injected as a dependency in the constructor. This follows dependency injection principles and Angular/NestJS conventions, supporting the new notification functionality.


26-26: LGTM: Method signature updated correctly

The getReferenceData method signature has been appropriately updated to include the auth parameter from TemplateApiModuleActionProps. This change enables access to authentication information needed for the new notification functionality.


53-53: LGTM: Return object updated correctly

The return object has been correctly updated to use the applicantName variable, which is consistent with the changes made earlier in the method.


Line range hint 1-124: LGTM: Changes adhere to coding guidelines

The modifications to this file in the libs directory adhere to the specified coding guidelines:

  • TypeScript is used effectively for defining types and props.
  • The changes enhance the reusability of the ReferenceTemplateService across different NextJS apps by adding notification functionality.
  • The code structure supports effective tree-shaking and bundling practices.

These changes maintain code quality and improve the overall functionality of the service.

libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (2)

246-266: LGTM! Improved error handling and notification system integration.

The changes in the rejectedByCounterParty method effectively address the previous issue of potential undefined access and align well with the new unified notification system. The addition of error handling for missing custody information is a good improvement.

The use of the NotificationsService for sending notifications is consistent with the overall changes in the class, promoting a more unified approach to user communication.


Line range hint 1-324: Great job on implementing the unified notification system!

The changes in this file significantly improve the notification handling capabilities of the ChildrenResidenceChangeServiceV2 class. The transition to using the NotificationsService across all methods ensures a consistent approach to user communication. The addition of error handling and null checks enhances the robustness of the code.

Key improvements:

  1. Consistent use of the new NotificationsService.
  2. Better error handling and null checks throughout the methods.
  3. Introduction of the getApplicationLink method for improved code reusability.
  4. Removal of unused services from the constructor.

These changes align well with the PR objectives and maintain good coding practices such as TypeScript usage and code reusability. The overall structure of the application remains intact while significantly enhancing its functionality.

Great work on this implementation! The code is now more maintainable, robust, and aligned with the project's notification system goals.

Copy link
Member

@HjorturJ HjorturJ left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

@norda-gunni norda-gunni added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 21, 2024
@kodiakhq kodiakhq bot merged commit c910dd7 into main Oct 21, 2024
38 checks passed
@kodiakhq kodiakhq bot deleted the as-notifications branch October 21, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants