Skip to content

Conversation

@Shubham4026
Copy link
Collaborator

@Shubham4026 Shubham4026 commented Jul 17, 2025

Summary by CodeRabbit

  • Chores
    • Updated project dependencies to latest major versions, including core NestJS packages and dev tools.
    • Introduced caching support with configuration in Fields module.
    • Added new cache service and example service demonstrating caching patterns.
    • Improved code style and formatting consistency across multiple modules and services.
    • Enhanced JSON parsing robustness in tenant service with error logging.
    • Standardized trailing commas in method signatures and calls throughout the codebase.
    • Refined logging utility to include explicit timestamps in logs.
    • Updated Swagger and API documentation decorators for clarity and consistency.

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

The changes are primarily formatting, stylistic improvements, and dependency upgrades across multiple files and modules. They include adding trailing commas, converting single quotes to double quotes, reformatting imports and method signatures, and minor code style refinements. Two new caching-related services were introduced, and dependencies were updated to newer major versions. No functional or behavioral changes were introduced in existing logic or APIs.

Changes

File(s) Change Summary
src/common/services/cache.service.ts Added new CacheService class wrapping cache-manager with async get/set/del/reset and getOrSet methods for caching operations.
src/common/services/cache-example.service.ts Added CacheExampleService demonstrating usage patterns of the new CacheService for caching user data and reports.
package.json Upgraded multiple dependencies and devDependencies to newer major versions, including NestJS packages and core libraries.
src/fields/fields.module.ts Added CacheModule import with TTL and max size configuration to enable caching in FieldsModule.
src/tenant/tenant.service.ts Refactored tenant service methods for readability; added robust JSON parsing with error handling for params and contentFilter.
src/adapters/postgres/* Multiple Postgres adapter files reformatted for consistent style, added trailing commas, converted quotes, no logic changes.
src/rbac/* Various RBAC adapter and controller files updated with trailing commas and formatting adjustments, no logic changes.
src/cohort/* Cohort-related controllers, modules, and adapters updated with trailing commas and formatting improvements.
src/common/utils/* Utility files reformatted for consistent quotes and trailing commas, no logic changes.
src/auth/* Auth service and controller files updated with trailing commas and formatting changes only.
src/automatic-member/* Automatic member module, service, DTOs, and entity files reformatted for style consistency, no functional changes.
src/forms/* Forms controller, service, DTOs, and entity files updated with quote style changes and trailing commas.
src/kafka/* Kafka config, service, and module files reformatted for consistent quotes and spacing.
src/location/* Location controller and service updated with trailing commas and formatting fixes.
src/middleware/permission.middleware.ts Added trailing commas and formatting adjustments in permission middleware.
src/cohortAcademicYear/* Cohort academic year adapters, controllers, DTOs, and modules reformatted with trailing commas and consistent quotes.
src/cohortMembers/* Cohort members adapter, controller, DTOs, and module files updated with trailing commas and minor formatting fixes.
src/common/logger/LoggerUtil.ts Logger utility reformatted to add explicit ISO timestamps in log methods, consistent quotes and indentation.
src/common/responses/response.ts Added trailing commas to static APIResponse methods' parameters.
src/common/utils/api-id.config.ts Changed string literals to double quotes and added trailing commas in APIID constants.
src/common/utils/auth-util.ts Changed import and string literals to double quotes, no logic changes.
src/common/utils/http-service.ts Added trailing commas to optional config parameters in HTTP methods.
src/common/utils/jwt-token.ts Reformatted method signature with trailing commas, no logic change.
src/common/utils/keycloak.adapter.util.ts Minor formatting and trailing commas added, error handling unchanged.
src/common/utils/notification.axios.ts Added trailing commas after HttpException constructor arguments.
src/common/utils/response.messages.ts Converted all string literals to double quotes and added trailing commas.
src/fields/dto/fields-update.dto.ts Changed validation message quotes from single to double quotes.
src/fields/fieldValidators/* Added trailing commas in constructors and method parameters, no logic changes.
src/fields/fields.controller.ts Added trailing commas in method parameters.
src/fields/fields.service.ts Added trailing commas in constructor and method signatures and calls.
src/fields/fields.module.ts Added CacheModule import with configuration.
src/cohort/cohort.controller.ts Added trailing commas in method parameters.
src/cohort/cohort.module.ts Added trailing commas and removed blank lines for style.
src/cohort/dto/cohort-create.dto.ts Removed trailing whitespace.
src/cohort/dto/cohort-search.dto.ts Removed blank line before decorator.
src/cohortAcademicYear/cohortAcademicYear.controller.ts Reformatted imports, constructor, and method chaining for readability.
src/cohortAcademicYear/cohortAcademicYear.module.ts Added trailing commas and reformatted arrays.
src/cohortAcademicYear/cohortacademicyearsadaptor.ts Reformatted constructor to single line.
src/cohortAcademicYear/dto/cohort-academicyear.dto.ts Added decorators and reformatted properties for clarity.
src/cohortMembers/cohortMembers.controller.ts Added trailing commas, reformatted exception messages, and fixed minor spacing.
src/cohortMembers/cohortMembers.module.ts Added trailing commas and reformatted class declaration.
src/cohortMembers/dto/cohortMembers-search.dto.ts Removed trailing whitespace.
src/cohortMembers/dto/cohortMembers.dto.ts Reformatted decorator options to multi-line.
src/common/decorators/* Reformatted imports and quotes; fixed syntax in permission decorator.
src/common/filters/exception.filter.ts Added trailing comma in APIResponse.error call.
src/common/guards/* Added trailing commas in method parameters and calls.
src/common/logger/LoggerUtil.ts Reformatted logger methods to add explicit ISO timestamps and consistent quotes.
src/common/responses/response.ts Added trailing commas in static methods.
src/common/services/upload-S3.service.ts Reformatted getPresignedUrl method for readability; no logic changes.
src/common/services/upload-file.ts Reformatted imports and code indentation; no logic changes.
src/common/utils/api-id.config.ts Changed string literals to double quotes and added trailing commas.
src/common/utils/auth-util.ts Changed import and string literals to double quotes.
src/common/utils/http-service.ts Added trailing commas to optional config parameters.
src/common/utils/jwt-token.ts Reformatted method signature with trailing commas.
src/common/utils/keycloak.adapter.util.ts Minor formatting and trailing commas added; error handling unchanged.
src/common/utils/notification.axios.ts Added trailing commas after HttpException constructor arguments.
src/common/utils/response.messages.ts Converted string literals to double quotes and added trailing commas.
src/forms/dto/form-create.dto.ts Changed string literals in decorators from single to double quotes.
src/forms/entities/form.entity.ts Changed string literals in column type declarations to double quotes.
src/forms/forms.controller.ts Reformatted imports and minor whitespace; changed let to const for tenantId.
src/forms/forms.service.spec.ts Added trailing commas in APIResponse calls.
src/forms/forms.service.ts Converted some let to const, added trailing commas, and removed blank lines; no logic changes.
src/kafka/kafka.config.ts Changed string literals to double quotes and removed trailing whitespace.
src/kafka/kafka.module.ts Changed import quotes to double quotes; added newline.
src/kafka/kafka.service.ts Converted string literals to double quotes and reformatted logging calls; no logic changes.
src/location/location.controller.ts Added trailing commas in method parameters.
src/location/location.service.ts Added trailing commas in method parameters and APIResponse calls.
src/main.ts Added trailing commas in middleware and Swagger config calls; added blank line after comment.
src/middleware/permission.middleware.ts Added trailing commas and formatting adjustments; no logic changes.
src/permissionRbac/rolePermissionMapping/* Added trailing commas in controller and service; replaced let with const in service.
src/rbac/assign-privilege/* Added trailing commas in error messages and method parameters; no logic changes.
src/rbac/assign-role/* Added trailing commas in error messages, method parameters, and controller methods.
src/rbac/privilege/* Added trailing commas in method parameters and APIResponse calls; no logic changes.
src/rbac/role/* Reformatted imports, added trailing commas, and adjusted whitespace; no logic changes.
src/tenant/dto/* Reformatted decorators and added explicit @Expose() decorators; changed quotes to double quotes; no logic changes.
src/tenant/entities/tenent.entity.ts Changed string literals in column types to double quotes; no logic changes.
src/tenant/tenant.controller.spec.ts Changed quotes to double quotes; no logic changes.
src/tenant/tenant.controller.ts Reformatted imports and code style; no logic changes.
src/tenant/tenant.module.ts Reformatted imports and arrays; added trailing commas; no logic changes.
src/tenant/tenant.service.spec.ts Changed quotes to double quotes; no logic changes.
src/tenant/tenant.service.ts Refactored methods for readability; added robust JSON parsing with error handling; no functional changes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CacheService
    participant Database

    Client->>CacheService: Request data with key
    CacheService->>CacheService: Check if key exists
    alt Key exists
        CacheService-->>Client: Return cached data
    else Key missing
        CacheService->>Database: Fetch data
        Database-->>CacheService: Return data
        CacheService->>CacheService: Cache data with TTL
        CacheService-->>Client: Return data
    end
Loading

Estimated code review effort

3 (~45 minutes)

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.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-22T06_26_54_011Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

@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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d5db76d and d9a1047.

📒 Files selected for processing (1)
  • src/adapters/postgres/user-adapter.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.ts

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE


async getEditableFieldsAttributes(tenantId: string) {
let tenantData = tenantId ? tenantId : 'default'
const tenantData = tenantId ? tenantId : "default";

Check notice

Code scanning / SonarCloud

Unused assignments should be removed

<!--SONAR_ISSUE_KEY:AZgwt_xtqw4aXqLVt4sQ-->Remove this useless assignment to variable "tenantData". <p>See more on <a href="https://sonarcloud.io/project/issues?id=tekdi_user-microservice&issues=AZgwt_xtqw4aXqLVt4sQ&open=AZgwt_xtqw4aXqLVt4sQ&pullRequest=399">SonarQube Cloud</a></p>

async getEditableFieldsAttributes(tenantId: string) {
let tenantData = tenantId ? tenantId : 'default'
const tenantData = tenantId ? tenantId : "default";

Check notice

Code scanning / SonarCloud

Unused assignments should be removed Low

Remove this useless assignment to variable "tenantData". See more on SonarQube Cloud
Copy link

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

🔭 Outside diff range comments (8)
src/location/location.service.ts (5)

43-43: Add missing type annotation for consistency.

The response parameter should have a type annotation for consistency with other methods.

-  async findLocation(id: string, response): Promise<Response> {
+  async findLocation(id: string, response: Response): Promise<Response> {

46-57: Fix incorrect entity lookup logic.

The current implementation has multiple issues:

  1. Using find() instead of findOne() for single entity lookup is inefficient
  2. The null check is incorrect since find() returns an empty array, not null
-      const location = await this.locationRepository.find({
-        where: { id: id },
-      });
-      if (!location) {
+      const location = await this.locationRepository.findOne({
+        where: { id: id },
+      });
+      if (!location) {

84-95: Fix incorrect entity lookup logic.

Same issues as in findLocation method - using find() instead of findOne() and incorrect null check.

-      const location = await this.locationRepository.find({
-        where: { id: id },
-      });
-      if (!location) {
+      const location = await this.locationRepository.findOne({
+        where: { id: id },
+      });
+      if (!location) {

119-129: Fix incorrect entity lookup logic in remove method.

The same find() vs findOne() issue exists here as in other methods.

-      const location = await this.locationRepository.find({
-        where: { id: id },
-      });
-      if (!location) {
+      const location = await this.locationRepository.findOne({
+        where: { id: id },
+      });
+      if (!location) {

The trailing comma addition is good for consistency.


150-150: Add missing type annotation for consistency.

The response parameter should have a type annotation.

-  async filter(reqObj: any, response): Promise<Response> {
+  async filter(reqObj: any, response: Response): Promise<Response> {
src/adapters/postgres/fields-adapter.ts (2)

69-76: High-risk SQL-injection surface – build the clause with parameters, not string concatenation

requiredData.context / contextType come from the client and are directly interpolated into whereClause.
An attacker can inject "'; DROP TABLE "Fields";--" (or similar) and you happily pass it to this.fieldsRepository.query(query) a few lines later.

Replace the dynamic string with a parameterised TypeORM query builder or at least query(..., [param]). Example idea:

- if (requiredData.context) {
-   whereClause += ` OR context = '${requiredData.context}' AND "contextType" IS NULL`;
- }
+ if (requiredData.context) {
+   params.push(requiredData.context);
+   whereClause += ` OR context = $${params.length} AND "contextType" IS NULL`;
+ }

Do the same for contextType, then execute:

await this.fieldsRepository.query(
  `SELECT * FROM public."Fields" WHERE ${whereClause}`,
  params,
);

Otherwise a single malformed header/value can wipe or leak your DB.


1460-1476: findDynamicOptions() repeats the same SQL-injection pattern

order, whereClause, optionSelected, tableName are interpolated straight into the query.
Even worse, order is composed from request-controlled sort so an attacker can inject arbitrary SQL after ORDER BY.

Move to query-builder with:

this.fieldsRepository
     .createQueryBuilder(tableName)
     .where(whereClauseObj, params)
     .orderBy(sortCol, sortDir)

If you must keep raw SQL, strictly whitelist column names and use placeholders for values.

src/forms/forms.service.ts (1)

205-212: Guard against undefined contextType / context before .toUpperCase()

formCreateDto.contextType.toUpperCase() (and similar) throws when the field is missing. Use optional chaining or validate beforehand:

-formCreateDto.contextType = formCreateDto.contextType.toUpperCase();
-formCreateDto.context = formCreateDto.context.toUpperCase();
-formCreateDto.title = formCreateDto.title.toUpperCase();
+formCreateDto.contextType = formCreateDto.contextType?.toUpperCase?.() ?? "";
+formCreateDto.context = formCreateDto.context?.toUpperCase?.() ?? "";
+formCreateDto.title = formCreateDto.title?.toUpperCase?.() ?? "";

Alternatively, return a BAD_REQUEST early when mandatory properties are absent.

♻️ Duplicate comments (1)
src/adapters/postgres/fields-adapter.ts (1)

1651-1657: tenantData is never used – just delete it

Matches the Sonar finding; the variable is assigned and then ignored.

🧹 Nitpick comments (17)
src/common/guards/rbac.guard.ts (2)

27-28: Clean up commented code.

Consider removing the commented code if it's no longer needed, or add a TODO comment if this represents planned functionality.

-    // const request = context.switchToHttp().getRequest();
-    // request.requiredPermissions = requiredPermissions;

26-26: Consider immutability for payload modification.

Directly mutating the payload object could have unexpected side effects. Consider creating a new object or documenting this behavior clearly.

-    payload.requiredPermissions = requiredPermissions;
+    // Create a new payload object to avoid mutations
+    const enhancedPayload = { ...payload, requiredPermissions };
+    super.getRequest(context).user = enhancedPayload;
src/location/location.service.ts (2)

25-31: LGTM! Consistent method call formatting.

The trailing comma addition maintains consistency. However, consider using HttpStatus.CREATED instead of HttpStatus.OK for resource creation to follow REST conventions.

-        HttpStatus.OK,
+        HttpStatus.CREATED,

6-6: Remove unused import.

The error import from 'console' is not used anywhere in the file and should be removed.

-import { error } from "console";
src/kafka/kafka.service.ts (1)

162-162: Use optional chaining for cleaner error checking.

The static analysis correctly suggests using optional chaining here for more concise code.

-      if (error.message && error.message.includes("already exists")) {
+      if (error.message?.includes("already exists")) {
src/automatic-member/automatic-member.service.ts (1)

121-121: Remove redundant Object.assign call.

The Object.assign(member); call with only one argument serves no purpose and should be removed.

-    Object.assign(member);
src/tenant/tenant.service.ts (2)

271-271: Use optional chaining for cleaner condition.

The static analysis correctly suggests using optional chaining for more concise code.

-      if (result && result.affected && result.affected > 0) {
+      if (result?.affected && result.affected > 0) {

370-370: Use optional chaining for cleaner condition.

Similar to the previous suggestion, optional chaining would make this condition more concise.

-      if (result && result.affected && result.affected > 0) {
+      if (result?.affected && result.affected > 0) {
src/adapters/postgres/fields-adapter.ts (1)

42-45: Blocking readFileSync in request path

readFileSync is executed on every request to getFormCustomField.
Synchronous disk I/O blocks the Node event-loop and hurts latency under load.

Cache the parsed JSON at module scope or switch to readFile + await fs.promises during app startup.

src/common/logger/LoggerUtil.ts (2)

8-20: Duplicate timestamp and noisy payload

winston.format.timestamp() already injects a timestamp property.
Your log calls add a second timestamp: new Date().toISOString() so every entry contains two fields with the same meaning.

Drop the manual timestamp in log/error/warn/debug or remove the formatter’s timestamp to avoid confusion.


1-83: Static-only utility class – consider a plain module instead

The class only contains static members; no state, no instances.
A simple logger.ts that exports getLogger, log, … reduces indirection and avoids the this-in-static anti-pattern flagged by Biome.

src/adapters/postgres/user-adapter.ts (1)

3086-3086: Remove console.log statement.

Console.log statement should be removed from production code as it can impact performance and expose sensitive information.

-            console.log("customFields", customFields);
src/common/services/cache-example.service.ts (1)

18-18: Consider replacing console.log statements for production readiness.

While appropriate for an example service, console.log statements should be replaced with proper logging using NestJS Logger service for production use.

+import { Injectable, Logger } from '@nestjs/common';
+
 @Injectable()
 export class CacheExampleService {
+  private readonly logger = new Logger(CacheExampleService.name);
+
-        console.log('Fetching user from database...');
+        this.logger.log('Fetching user from database...');

Apply similar changes to other console.log statements throughout the service.

Also applies to: 35-35, 40-40, 57-57, 81-81, 92-92, 96-96, 115-115

src/common/services/cache.service.ts (2)

40-53: Consider adding error handling for fallback function.

The getOrSet method should handle potential errors from the fallback function to prevent cache pollution with failed results.

  async getOrSet<T>(
    key: string,
    fallback: () => Promise<T>,
    ttl?: number,
  ): Promise<T> {
    let value = await this.get<T>(key);

    if (value === undefined || value === null) {
-     value = await fallback();
-     await this.set(key, value, ttl);
+     try {
+       value = await fallback();
+       await this.set(key, value, ttl);
+     } catch (error) {
+       // Re-throw to let caller handle, but don't cache the error
+       throw error;
+     }
    }

    return value;
  }

58-61: Consider caching the existence check result.

The has method calls get which may be redundant if the cache implementation already provides an efficient existence check.

Consider if the underlying cache manager provides a more efficient has method that doesn't require retrieving the full value:

async has(key: string): Promise<boolean> {
  // If cache-manager provides a native has method, use it
  // return await this.cacheManager.has?.(key) ?? (await this.get(key)) !== undefined;
  const value = await this.get(key);
  return value !== undefined && value !== null;
}
src/forms/forms.service.ts (2)

149-156: Stop mutating input with delete; filter keys instead

Using delete requiredData.tenantId; de-opts V8 objects and is flagged by static-analysis. Rather than mutating the caller’s object, copy & validate:

- delete requiredData.tenantId;
- const allowedKeys = ["context", "contextType", "userId"];
- const extraKeys = Object.keys(requiredData).filter(
-   (key) => !allowedKeys.includes(key),
- );
+const { tenantId: _, ...payload } = requiredData; // exclude tenantId
+const allowedKeys = new Set(["context", "contextType", "userId"]);
+const extraKeys = Object.keys(payload).filter((k) => !allowedKeys.has(k));

No functional change, better performance & immutability.


213-216: Use exist() instead of find() for existence check

getFormDetail retrieves full entities only to inspect .length, wasting bandwidth and memory.
With TypeORM ≥0.3 you can do:

const alreadyExists = await this.formRepository.exist({
  where: { context, contextType, tenantId: tenantId || IsNull() },
});
if (alreadyExists) {
  
}

Reduces DB load and avoids deserialising unused columns.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d9a1047 and 5ee3da9.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (107)
  • package.json (2 hunks)
  • src/academicyears/academicyears.controller.ts (3 hunks)
  • src/academicyears/academicyears.module.ts (1 hunks)
  • src/academicyears/academicyearsadaptor.ts (1 hunks)
  • src/academicyears/dto/academicyears-create.dto.ts (1 hunks)
  • src/adapters/academicyearsservicelocater.ts (1 hunks)
  • src/adapters/assignprivilegelocater.ts (1 hunks)
  • src/adapters/assignroleservicelocater.ts (1 hunks)
  • src/adapters/cohortMembersservicelocator.ts (1 hunks)
  • src/adapters/cohortacademicyearservicelocator.ts (1 hunks)
  • src/adapters/cohortservicelocator.ts (1 hunks)
  • src/adapters/fieldsservicelocator.ts (1 hunks)
  • src/adapters/postgres/academicyears-adapter.ts (9 hunks)
  • src/adapters/postgres/cohort-adapter.ts (48 hunks)
  • src/adapters/postgres/cohortAcademicYear-adapter.ts (6 hunks)
  • src/adapters/postgres/cohortMembers-adapter.ts (35 hunks)
  • src/adapters/postgres/fields-adapter.ts (74 hunks)
  • src/adapters/postgres/postgres-module.ts (1 hunks)
  • src/adapters/postgres/rbac/assignrole-adapter.ts (16 hunks)
  • src/adapters/postgres/rbac/privilege-adapter.ts (18 hunks)
  • src/adapters/postgres/rbac/privilegerole.adapter.ts (10 hunks)
  • src/adapters/postgres/rbac/role-adapter.ts (21 hunks)
  • src/adapters/postgres/user-adapter.ts (108 hunks)
  • src/adapters/postgres/userTenantMapping-adapter.ts (8 hunks)
  • src/adapters/privilegeservicelocator.ts (2 hunks)
  • src/adapters/userservicelocator.ts (2 hunks)
  • src/adapters/usertenantmappinglocator.ts (1 hunks)
  • src/auth/auth.controller.ts (1 hunks)
  • src/auth/auth.service.ts (8 hunks)
  • src/authRbac/authRbac.service.ts (6 hunks)
  • src/automatic-member/automatic-member.controller.spec.ts (2 hunks)
  • src/automatic-member/automatic-member.controller.ts (2 hunks)
  • src/automatic-member/automatic-member.module.ts (1 hunks)
  • src/automatic-member/automatic-member.service.spec.ts (2 hunks)
  • src/automatic-member/automatic-member.service.ts (5 hunks)
  • src/automatic-member/dto/create-automatic-member.dto.ts (3 hunks)
  • src/automatic-member/dto/update-automatic-member.dto.ts (1 hunks)
  • src/automatic-member/entity/automatic-member.entity.ts (1 hunks)
  • src/cohort/cohort.controller.ts (7 hunks)
  • src/cohort/cohort.module.ts (2 hunks)
  • src/cohort/dto/cohort-create.dto.ts (1 hunks)
  • src/cohort/dto/cohort-search.dto.ts (0 hunks)
  • src/cohortAcademicYear/cohortAcademicYear.controller.ts (2 hunks)
  • src/cohortAcademicYear/cohortAcademicYear.module.ts (1 hunks)
  • src/cohortAcademicYear/cohortacademicyearsadaptor.ts (1 hunks)
  • src/cohortAcademicYear/dto/cohort-academicyear.dto.ts (1 hunks)
  • src/cohortMembers/cohortMembers.controller.ts (13 hunks)
  • src/cohortMembers/cohortMembers.module.ts (2 hunks)
  • src/cohortMembers/dto/cohortMembers-search.dto.ts (1 hunks)
  • src/cohortMembers/dto/cohortMembers.dto.ts (1 hunks)
  • src/common/decorators/getUserId.decorator.ts (1 hunks)
  • src/common/decorators/permission.decorator.ts (1 hunks)
  • src/common/filters/exception.filter.ts (1 hunks)
  • src/common/guards/rbac.guard.ts (1 hunks)
  • src/common/guards/rbac.strategy.ts (1 hunks)
  • src/common/logger/LoggerUtil.ts (1 hunks)
  • src/common/responses/response.ts (2 hunks)
  • src/common/services/cache-example.service.ts (1 hunks)
  • src/common/services/cache.service.ts (1 hunks)
  • src/common/services/upload-S3.service.ts (3 hunks)
  • src/common/services/upload-file.ts (1 hunks)
  • src/common/utils/api-id.config.ts (1 hunks)
  • src/common/utils/auth-util.ts (1 hunks)
  • src/common/utils/http-service.ts (2 hunks)
  • src/common/utils/jwt-token.ts (1 hunks)
  • src/common/utils/keycloak.adapter.util.ts (7 hunks)
  • src/common/utils/notification.axios.ts (3 hunks)
  • src/common/utils/response.messages.ts (3 hunks)
  • src/fields/dto/fields-update.dto.ts (1 hunks)
  • src/fields/fieldValidators/field.util.ts (1 hunks)
  • src/fields/fieldValidators/fieldClass.ts (1 hunks)
  • src/fields/fieldValidators/fieldFactory.ts (1 hunks)
  • src/fields/fieldValidators/fieldTypeClasses.ts (1 hunks)
  • src/fields/fields.controller.ts (9 hunks)
  • src/fields/fields.module.ts (2 hunks)
  • src/fields/fields.service.ts (8 hunks)
  • src/forms/dto/form-create.dto.ts (1 hunks)
  • src/forms/entities/form.entity.ts (1 hunks)
  • src/forms/forms.controller.ts (4 hunks)
  • src/forms/forms.service.spec.ts (4 hunks)
  • src/forms/forms.service.ts (14 hunks)
  • src/kafka/kafka.config.ts (1 hunks)
  • src/kafka/kafka.module.ts (1 hunks)
  • src/kafka/kafka.service.ts (8 hunks)
  • src/location/location.controller.ts (2 hunks)
  • src/location/location.service.ts (10 hunks)
  • src/main.ts (2 hunks)
  • src/middleware/permission.middleware.ts (5 hunks)
  • src/permissionRbac/rolePermissionMapping/role-permission-mapping.controller.ts (2 hunks)
  • src/permissionRbac/rolePermissionMapping/role-permission-mapping.service.ts (3 hunks)
  • src/rbac/assign-privilege/assign-privilege.apater.ts (1 hunks)
  • src/rbac/assign-privilege/assign-privilege.controller.ts (3 hunks)
  • src/rbac/assign-role/assign-role.apater.ts (1 hunks)
  • src/rbac/assign-role/assign-role.controller.ts (3 hunks)
  • src/rbac/assign-role/dto/create-assign-role.dto.ts (1 hunks)
  • src/rbac/privilege/privilege.controller.ts (4 hunks)
  • src/rbac/role/dto/role.dto.ts (1 hunks)
  • src/rbac/role/role.controller.ts (5 hunks)
  • src/tenant/dto/tenant-create.dto.ts (1 hunks)
  • src/tenant/dto/tenant-search.dto.ts (2 hunks)
  • src/tenant/dto/tenant-update.dto.ts (1 hunks)
  • src/tenant/entities/tenent.entity.ts (2 hunks)
  • src/tenant/tenant.controller.spec.ts (2 hunks)
  • src/tenant/tenant.controller.ts (1 hunks)
  • src/tenant/tenant.module.ts (1 hunks)
  • src/tenant/tenant.service.spec.ts (2 hunks)
  • src/tenant/tenant.service.ts (1 hunks)
⛔ Files not processed due to max files limit (13)
  • src/user/dto/otpSend.dto.ts
  • src/user/dto/otpVerify.dto.ts
  • src/user/dto/passwordReset.dto.ts
  • src/user/dto/user-create.dto.ts
  • src/user/dto/user-search.dto.ts
  • src/user/dto/user-update.dto.ts
  • src/user/entities/user-entity.ts
  • src/user/user.controller.ts
  • src/userTenantMapping/user-tenant-mapping.adapter.ts
  • src/userTenantMapping/user-tenant-mapping.controller.ts
  • src/userTenantMapping/user-tenant-mapping.module.ts
  • src/utils/dob-not-in-future.validator.ts
  • src/utils/response.ts
📓 Path-based instructions (1)
**/*.ts

⚙️ CodeRabbit Configuration File

**/*.ts: "Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations. Ensure that:

  • The code adheres to best practices associated with nodejs.
  • The code adheres to best practices associated with nestjs framework.
  • The code adheres to best practices recommended for performance.
  • The code adheres to similar naming conventions for controllers, models, services, methods, variables."

Files:

  • src/common/guards/rbac.guard.ts
  • src/fields/fields.module.ts
  • src/adapters/postgres/rbac/privilege-adapter.ts
  • src/location/location.service.ts
  • src/common/services/cache-example.service.ts
  • src/common/services/cache.service.ts
  • src/tenant/tenant.service.ts
  • src/adapters/postgres/cohort-adapter.ts
  • src/adapters/postgres/fields-adapter.ts
  • src/adapters/postgres/user-adapter.ts
  • src/automatic-member/automatic-member.service.ts
  • src/common/logger/LoggerUtil.ts
  • src/forms/forms.service.ts
  • src/kafka/kafka.service.ts
🧬 Code Graph Analysis (2)
src/adapters/postgres/rbac/privilege-adapter.ts (3)
src/rbac/privilege/dto/privilege.dto.ts (1)
  • CreatePrivilegesDto (50-55)
src/common/responses/response.ts (1)
  • APIResponse (4-60)
src/utils/response.ts (1)
  • APIResponse (21-85)
src/location/location.service.ts (1)
src/location/dto/location-create.dto.ts (1)
  • CreateLocationDto (3-15)
🪛 Biome (1.9.4)
src/tenant/tenant.service.ts

[error] 271-271: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 370-370: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/adapters/postgres/cohort-adapter.ts

[error] 592-592: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 1101-1101: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

src/adapters/postgres/user-adapter.ts

[error] 1517-1517: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

src/automatic-member/automatic-member.service.ts

[error] 12-12: Do not shadow the global "String" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/common/logger/LoggerUtil.ts

[error] 3-83: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 7-7: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 21-21: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 30-30: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 44-44: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 59-59: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 69-69: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 77-77: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/forms/forms.service.ts

[error] 152-152: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

src/kafka/kafka.service.ts

[error] 162-162: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: SonarCloud
src/adapters/postgres/fields-adapter.ts

[notice] 1651-1651: Unused assignments should be removed

Remove this useless assignment to variable "tenantData".

See more on SonarQube Cloud


[notice] 1651-1651: Unused assignments should be removed

Remove this useless assignment to variable "tenantData".

See more on SonarQube Cloud

💤 Files with no reviewable changes (1)
  • src/cohort/dto/cohort-search.dto.ts
✅ Files skipped from review due to trivial changes (91)
  • src/academicyears/academicyearsadaptor.ts
  • src/cohortMembers/dto/cohortMembers-search.dto.ts
  • src/common/filters/exception.filter.ts
  • src/automatic-member/entity/automatic-member.entity.ts
  • src/kafka/kafka.module.ts
  • src/automatic-member/automatic-member.controller.spec.ts
  • src/common/decorators/getUserId.decorator.ts
  • src/academicyears/academicyears.module.ts
  • src/tenant/tenant.service.spec.ts
  • src/rbac/role/dto/role.dto.ts
  • src/cohort/dto/cohort-create.dto.ts
  • src/fields/dto/fields-update.dto.ts
  • src/common/guards/rbac.strategy.ts
  • src/cohortMembers/dto/cohortMembers.dto.ts
  • src/fields/fieldValidators/field.util.ts
  • src/adapters/postgres/postgres-module.ts
  • src/adapters/cohortservicelocator.ts
  • src/rbac/assign-role/dto/create-assign-role.dto.ts
  • src/tenant/entities/tenent.entity.ts
  • src/forms/entities/form.entity.ts
  • src/rbac/assign-role/assign-role.apater.ts
  • src/academicyears/dto/academicyears-create.dto.ts
  • src/auth/auth.controller.ts
  • src/adapters/assignprivilegelocater.ts
  • src/academicyears/academicyears.controller.ts
  • src/rbac/role/role.controller.ts
  • src/tenant/tenant.controller.spec.ts
  • src/rbac/assign-privilege/assign-privilege.apater.ts
  • src/automatic-member/automatic-member.module.ts
  • src/permissionRbac/rolePermissionMapping/role-permission-mapping.service.ts
  • src/common/decorators/permission.decorator.ts
  • src/cohortAcademicYear/cohortacademicyearsadaptor.ts
  • src/automatic-member/automatic-member.service.spec.ts
  • src/main.ts
  • src/common/utils/api-id.config.ts
  • src/adapters/postgres/rbac/privilegerole.adapter.ts
  • src/location/location.controller.ts
  • src/adapters/academicyearsservicelocater.ts
  • src/cohortMembers/cohortMembers.module.ts
  • src/forms/forms.service.spec.ts
  • src/adapters/postgres/academicyears-adapter.ts
  • src/cohort/cohort.module.ts
  • src/rbac/assign-privilege/assign-privilege.controller.ts
  • src/cohortAcademicYear/cohortAcademicYear.module.ts
  • src/tenant/dto/tenant-update.dto.ts
  • src/automatic-member/dto/update-automatic-member.dto.ts
  • src/adapters/cohortacademicyearservicelocator.ts
  • src/tenant/tenant.module.ts
  • src/forms/dto/form-create.dto.ts
  • src/adapters/usertenantmappinglocator.ts
  • src/rbac/assign-role/assign-role.controller.ts
  • src/common/utils/notification.axios.ts
  • src/automatic-member/automatic-member.controller.ts
  • src/rbac/privilege/privilege.controller.ts
  • src/auth/auth.service.ts
  • src/permissionRbac/rolePermissionMapping/role-permission-mapping.controller.ts
  • src/adapters/userservicelocator.ts
  • src/common/services/upload-file.ts
  • src/adapters/assignroleservicelocater.ts
  • src/adapters/cohortMembersservicelocator.ts
  • src/kafka/kafka.config.ts
  • src/middleware/permission.middleware.ts
  • src/common/utils/response.messages.ts
  • src/fields/fieldValidators/fieldFactory.ts
  • src/fields/fields.controller.ts
  • src/adapters/postgres/userTenantMapping-adapter.ts
  • src/cohortAcademicYear/cohortAcademicYear.controller.ts
  • src/common/responses/response.ts
  • src/fields/fieldValidators/fieldTypeClasses.ts
  • src/adapters/postgres/rbac/assignrole-adapter.ts
  • src/tenant/tenant.controller.ts
  • src/adapters/postgres/rbac/role-adapter.ts
  • src/common/utils/jwt-token.ts
  • src/automatic-member/dto/create-automatic-member.dto.ts
  • src/common/utils/keycloak.adapter.util.ts
  • src/fields/fieldValidators/fieldClass.ts
  • src/adapters/privilegeservicelocator.ts
  • src/cohort/cohort.controller.ts
  • src/cohortMembers/cohortMembers.controller.ts
  • src/forms/forms.controller.ts
  • src/adapters/fieldsservicelocator.ts
  • src/adapters/postgres/cohortAcademicYear-adapter.ts
  • src/tenant/dto/tenant-search.dto.ts
  • src/authRbac/authRbac.service.ts
  • src/tenant/dto/tenant-create.dto.ts
  • src/common/services/upload-S3.service.ts
  • src/cohortAcademicYear/dto/cohort-academicyear.dto.ts
  • src/common/utils/http-service.ts
  • src/common/utils/auth-util.ts
  • src/fields/fields.service.ts
  • src/adapters/postgres/cohortMembers-adapter.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.ts

⚙️ CodeRabbit Configuration File

**/*.ts: "Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations. Ensure that:

  • The code adheres to best practices associated with nodejs.
  • The code adheres to best practices associated with nestjs framework.
  • The code adheres to best practices recommended for performance.
  • The code adheres to similar naming conventions for controllers, models, services, methods, variables."

Files:

  • src/common/guards/rbac.guard.ts
  • src/fields/fields.module.ts
  • src/adapters/postgres/rbac/privilege-adapter.ts
  • src/location/location.service.ts
  • src/common/services/cache-example.service.ts
  • src/common/services/cache.service.ts
  • src/tenant/tenant.service.ts
  • src/adapters/postgres/cohort-adapter.ts
  • src/adapters/postgres/fields-adapter.ts
  • src/adapters/postgres/user-adapter.ts
  • src/automatic-member/automatic-member.service.ts
  • src/common/logger/LoggerUtil.ts
  • src/forms/forms.service.ts
  • src/kafka/kafka.service.ts
🧬 Code Graph Analysis (2)
src/adapters/postgres/rbac/privilege-adapter.ts (3)
src/rbac/privilege/dto/privilege.dto.ts (1)
  • CreatePrivilegesDto (50-55)
src/common/responses/response.ts (1)
  • APIResponse (4-60)
src/utils/response.ts (1)
  • APIResponse (21-85)
src/location/location.service.ts (1)
src/location/dto/location-create.dto.ts (1)
  • CreateLocationDto (3-15)
🪛 Biome (1.9.4)
src/tenant/tenant.service.ts

[error] 271-271: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 370-370: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/adapters/postgres/cohort-adapter.ts

[error] 592-592: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 1101-1101: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

src/adapters/postgres/user-adapter.ts

[error] 1517-1517: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

src/automatic-member/automatic-member.service.ts

[error] 12-12: Do not shadow the global "String" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

src/common/logger/LoggerUtil.ts

[error] 3-83: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 7-7: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 21-21: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 30-30: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 35-35: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 44-44: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 59-59: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 69-69: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 77-77: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/forms/forms.service.ts

[error] 152-152: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

src/kafka/kafka.service.ts

[error] 162-162: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: SonarCloud
src/adapters/postgres/fields-adapter.ts

[notice] 1651-1651: Unused assignments should be removed

Remove this useless assignment to variable "tenantData".

See more on SonarQube Cloud


[notice] 1651-1651: Unused assignments should be removed

Remove this useless assignment to variable "tenantData".

See more on SonarQube Cloud

🔇 Additional comments (36)
src/common/guards/rbac.guard.ts (2)

13-13: LGTM: Trailing comma improves code consistency.

The trailing comma addition aligns with modern JavaScript/TypeScript formatting standards and improves diff readability.


18-18: LGTM: Consistent trailing comma formatting.

The trailing comma in the method call follows the same formatting pattern applied consistently across the codebase.

src/location/location.service.ts (12)

12-15: LGTM! Trailing comma improves code maintainability.

The addition of the trailing comma in the constructor parameter list follows modern TypeScript best practices and improves diff readability.


17-20: LGTM! Consistent parameter formatting.

The trailing comma addition maintains consistency with modern TypeScript formatting standards.


33-39: LGTM! Consistent error handling formatting.

The trailing comma maintains consistency with the applied formatting standards.


58-64: LGTM! Consistent success response formatting.

The trailing comma addition maintains consistency with the applied formatting standards.


66-72: LGTM! Consistent error handling formatting.

The trailing comma maintains consistency with the applied formatting standards.


97-103: LGTM! Consistent response formatting.

The trailing comma addition maintains consistency with the applied formatting standards.


105-111: LGTM! Consistent error handling formatting.

The trailing comma maintains consistency with the applied formatting standards.


132-138: LGTM! Consistent response formatting.

The trailing comma addition maintains consistency with the applied formatting standards.


140-146: LGTM! Consistent error handling formatting.

The trailing comma maintains consistency with the applied formatting standards.


157-163: LGTM! Consistent response formatting.

The trailing comma addition maintains consistency with the applied formatting standards.


175-181: LGTM! Consistent response formatting.

The trailing comma addition maintains consistency with the applied formatting standards.


183-189: LGTM! Consistent error handling formatting.

The trailing comma maintains consistency with the applied formatting standards.

src/kafka/kafka.service.ts (6)

1-8: Good formatting improvement for imports.

The consistent use of double quotes and multi-line formatting with trailing commas aligns well with the Google JavaScript style guide requirements.


21-31: Improved constructor parameter formatting.

The multi-line formatting with consistent indentation and trailing commas enhances readability and follows NestJS/TypeScript best practices.


54-79: Consistent logging format improvements.

The conversion to double quotes and multi-line formatting for error logging calls improves code consistency and readability while maintaining all existing functionality.


184-188: Well-formatted method signature.

The multi-line parameter formatting improves readability for methods with multiple parameters, following TypeScript and NestJS best practices.


240-252: Consistent string literal formatting.

The conversion to double quotes for all string literals maintains consistency throughout the codebase and aligns with the Google JavaScript style guide.


212-216: Improved error handling formatting.

The multi-line formatting for error logging enhances readability while preserving all error handling logic and behavior.

src/automatic-member/automatic-member.service.ts (2)

85-89: Good formatting but problematic type usage.

The multi-line parameter formatting improves readability, but the UUID type imported from AWS SDK should be replaced with string type as mentioned in the imports review.


59-61: Improved query object formatting.

The multi-line formatting for query objects enhances readability and follows TypeScript best practices.

src/tenant/tenant.service.ts (2)

175-187: Excellent JSON parsing improvement.

The addition of proper type checking and error handling around JSON.parse operations significantly improves robustness. The graceful handling of parsing errors with logging is a best practice.


21-29: Comprehensive formatting improvements.

The consistent use of double quotes, multi-line parameter formatting, and improved indentation significantly enhance code readability and align with TypeScript/NestJS best practices.

src/fields/fields.module.ts (2)

2-2: Correct cache module import.

Using @nestjs/cache-manager is the correct approach as it's the dedicated caching package for NestJS, not the deprecated cache functionality from @nestjs/common.


17-20: Well-configured cache module.

The cache configuration with 5-minute TTL and 100-item limit is reasonable for field data. This should improve performance by reducing database queries for frequently accessed field information.

src/adapters/postgres/rbac/privilege-adapter.ts (2)

26-26: Good formatting with trailing commas.

The addition of trailing commas in constructor parameters follows TypeScript best practices and improves git diff readability.


66-79: Consistent API response formatting.

The trailing commas in APIResponse method calls improve code consistency and follow the established formatting patterns throughout the codebase.

src/adapters/postgres/user-adapter.ts (1)

1092-1098: Approve asynchronous Kafka event publishing pattern.

The implementation correctly publishes Kafka events asynchronously after sending the response to the client, preventing blocking operations from affecting user experience. The error handling with .catch() ensures failures don't impact the main operation flow.

package.json (2)

36-40: Approve addition of caching dependencies.

The addition of @nestjs/cache-manager and cache-manager aligns well with the new caching services introduced in the codebase. The versions chosen are stable and appropriate.


26-36: Verify compatibility with NestJS v10 migration

Please ensure you’ve followed the official NestJS v10 migration guide and double-checked for any remaining breaking changes:

  • Confirm there are no leftover HttpModule imports from @nestjs/common (all should now come from @nestjs/axios).
  • Verify caching setup with @nestjs/cache-manager and update any custom interceptors or providers.
  • Audit any removed or renamed decorators, pipes or guards against the v10 release notes.
  • Run the full test suite and perform smoke tests on critical endpoints (Swagger docs, validation pipes, scheduled tasks, etc.).
src/common/services/cache-example.service.ts (1)

1-6: Approve NestJS service structure and dependency injection.

The service correctly implements NestJS patterns with proper @Injectable() decorator and constructor-based dependency injection. The naming convention follows NestJS standards.

src/adapters/postgres/cohort-adapter.ts (3)

47-48: Approve trailing comma addition.

The trailing comma in the constructor parameter list improves maintainability and follows TypeScript best practices.


442-453: Approve asynchronous Kafka event publishing pattern.

The implementation correctly publishes events asynchronously after sending the response to the client, with proper error handling that doesn't affect the main operation flow.


1210-1304: Well-structured Kafka event publishing method.

The publishCohortEvent method demonstrates good error handling practices:

  • Graceful degradation when data fetching fails
  • Separate handling for different event types
  • Comprehensive logging without affecting main operations
src/common/services/cache.service.ts (1)

1-70: Well-implemented cache service following NestJS best practices.

The CacheService demonstrates excellent implementation:

  • Proper dependency injection with @Inject decorator
  • Clean async/await patterns throughout
  • Comprehensive method coverage for cache operations
  • Good TypeScript generic usage for type safety
  • Helpful utility method for key generation
  • Clear JSDoc comments for all public methods

The service follows NestJS conventions and provides a clean abstraction over the cache-manager library.

Comment on lines 587 to 596
const customFieldAttributes = allCustomFields.reduce(
(fieldDetail, { fieldId, fieldAttributes, fieldParams, name }) =>
fieldDetail[`${fieldId}`]
? fieldDetail
: {
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{}
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{},
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix performance issue with spread operator in accumulator.

The spread syntax in the .reduce() accumulator causes O(n²) time complexity. Use object assignment instead for better performance.

-            const customFieldAttributes = allCustomFields.reduce(
-              (fieldDetail, { fieldId, fieldAttributes, fieldParams, name }) =>
-                fieldDetail[`${fieldId}`]
-                  ? fieldDetail
-                  : {
-                      ...fieldDetail,
-                      [`${fieldId}`]: { fieldAttributes, fieldParams, name },
-                    },
-              {},
-            );
+            const customFieldAttributes = allCustomFields.reduce(
+              (fieldDetail, { fieldId, fieldAttributes, fieldParams, name }) => {
+                if (!fieldDetail[`${fieldId}`]) {
+                  fieldDetail[`${fieldId}`] = { fieldAttributes, fieldParams, name };
+                }
+                return fieldDetail;
+              },
+              {},
+            );
📝 Committable suggestion

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

Suggested change
const customFieldAttributes = allCustomFields.reduce(
(fieldDetail, { fieldId, fieldAttributes, fieldParams, name }) =>
fieldDetail[`${fieldId}`]
? fieldDetail
: {
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{}
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{},
);
const customFieldAttributes = allCustomFields.reduce(
(fieldDetail, { fieldId, fieldAttributes, fieldParams, name }) => {
if (!fieldDetail[`${fieldId}`]) {
fieldDetail[`${fieldId}`] = { fieldAttributes, fieldParams, name };
}
return fieldDetail;
},
{},
);
🧰 Tools
🪛 Biome (1.9.4)

[error] 592-592: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🤖 Prompt for AI Agents
In src/adapters/postgres/cohort-adapter.ts around lines 587 to 596, the use of
the spread operator inside the reduce accumulator causes O(n²) time complexity.
To fix this, replace the spread syntax with direct object assignment by mutating
the accumulator object instead of creating a new object on each iteration.
Initialize the accumulator as an empty object and add new properties directly to
it before returning it.

Comment on lines +1099 to +1101
const {
condition: { value, fieldId },
} = requiredData?.rules;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix unsafe optional chaining usage.

The destructuring with optional chaining can throw a TypeError if the chain short-circuits to undefined.

-    const {
-      condition: { value, fieldId },
-    } = requiredData?.rules;
+    const rules = requiredData?.rules;
+    if (!rules?.condition) {
+      throw new Error("Invalid requiredData structure: missing rules.condition");
+    }
+    const { value, fieldId } = rules.condition;
📝 Committable suggestion

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

Suggested change
const {
condition: { value, fieldId },
} = requiredData?.rules;
const rules = requiredData?.rules;
if (!rules?.condition) {
throw new Error("Invalid requiredData structure: missing rules.condition");
}
const { value, fieldId } = rules.condition;
🧰 Tools
🪛 Biome (1.9.4)

[error] 1101-1101: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

🤖 Prompt for AI Agents
In src/adapters/postgres/cohort-adapter.ts around lines 1099 to 1101, the
destructuring of condition from requiredData?.rules uses optional chaining
unsafely, which can cause a TypeError if requiredData or rules is undefined. To
fix this, add explicit checks to ensure requiredData and requiredData.rules are
defined before destructuring condition, or use default values to safely handle
undefined cases.

Comment on lines +1517 to 1521
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{},
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix performance issue with spread operator in reduce.

The static analysis tool correctly identified a performance concern. Using spread syntax in the reduce accumulator creates O(n²) time complexity due to object recreation on each iteration.

-            fieldDetail[`${fieldId}`]
-              ? fieldDetail
-              : {
-                  ...fieldDetail,
-                  [`${fieldId}`]: { fieldAttributes, fieldParams, name },
-                },
+            fieldDetail[`${fieldId}`]
+              ? fieldDetail
+              : Object.assign(fieldDetail, {
+                  [`${fieldId}`]: { fieldAttributes, fieldParams, name },
+                }),

Alternatively, consider restructuring to avoid the reduce pattern entirely if performance is critical.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1517-1517: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🤖 Prompt for AI Agents
In src/adapters/postgres/user-adapter.ts around lines 1517 to 1521, the use of
the spread operator inside the reduce function causes O(n²) complexity by
recreating the accumulator object on each iteration. To fix this, replace the
reduce with a standard for-loop or use reduce but mutate the accumulator object
directly without spreading it, adding each new property in place to avoid
repeated object copying and improve performance.

Comment on lines +12 to +13
import { String } from "aws-sdk/clients/apigateway";
import { UUID } from "aws-sdk/clients/cloudtrail";
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove problematic AWS SDK imports.

Importing String from AWS SDK shadows the global String constructor and is inappropriate for basic type definitions. These imports should be replaced with proper TypeScript types.

-import { String } from "aws-sdk/clients/apigateway";
-import { UUID } from "aws-sdk/clients/cloudtrail";
+// Use built-in TypeScript types instead
+// string (lowercase) for the type, UUID can be imported from a proper UUID library or defined as string

Consider using a proper UUID library like uuid or simply use string type for UUID parameters.

🧰 Tools
🪛 Biome (1.9.4)

[error] 12-12: Do not shadow the global "String" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🤖 Prompt for AI Agents
In src/automatic-member/automatic-member.service.ts at lines 12 to 13, remove
the imports of String and UUID from the AWS SDK as they shadow global types and
are inappropriate. Replace these with standard TypeScript types: use 'string'
for general string types and consider importing a UUID type from a dedicated
library like 'uuid' if UUID validation or generation is needed.

Comment on lines +11 to +24
async getUserWithCache(userId: string) {
const cacheKey = this.cacheService.generateKey('user', userId);

return await this.cacheService.getOrSet(
cacheKey,
async () => {
// This function will only run if data is not in cache
console.log('Fetching user from database...');
// Your actual database call here
return { id: userId, name: 'John Doe', email: 'john@example.com' };
},
300 // Cache for 5 minutes
);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for cache operations.

The service lacks error handling for cache operations, which could lead to unhandled promise rejections in production environments.

 async getUserWithCache(userId: string) {
   const cacheKey = this.cacheService.generateKey('user', userId);
   
+  try {
     return await this.cacheService.getOrSet(
       cacheKey,
       async () => {
         console.log('Fetching user from database...');
         return { id: userId, name: 'John Doe', email: 'john@example.com' };
       },
       300
     );
+  } catch (error) {
+    this.logger.error('Cache operation failed', error);
+    // Fallback to direct database call
+    return { id: userId, name: 'John Doe', email: 'john@example.com' };
+  }
 }

Also applies to: 29-50

🤖 Prompt for AI Agents
In src/common/services/cache-example.service.ts around lines 11 to 24 and 29 to
50, the cache operations lack error handling, risking unhandled promise
rejections. Wrap the cacheService.getOrSet calls in try-catch blocks to catch
and handle any errors during cache retrieval or setting. In the catch block, log
the error and optionally fallback to fetching data directly without caching to
ensure the service remains resilient.

Comment on lines 71 to 85
const mappedResponse = await Promise.all(
formData.fields.result.map(async (data) => {
if (!data.coreField) {
const whereClause = `"fieldId" = '${data.fieldId}'`;
const whereClause = `"fieldId" = '${data.fieldId}'`;
const [customFieldData] = await this.fieldsService.getFieldData(
whereClause,
tenantId
tenantId,
);
customFieldData.validation = data.validation;
customFieldData.order = data.order;
customFieldData.order = data.order;
return { ...data, ...customFieldData };
}
return data;
})
}),
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid N + 1 database calls when enriching non-core fields

Promise.all is used correctly for concurrency, yet each iteration still hits fieldsService.getFieldData individually, causing as many DB round-trips as there are custom fields.
Fetch all required fieldIds in one query and join the data in-memory to cut latency and load.

-const mappedResponse = await Promise.all(
-  formData.fields.result.map(async (data) => {
-    if (!data.coreField) {
-      const whereClause = `"fieldId" = '${data.fieldId}'`;
-      const [customFieldData] = await this.fieldsService.getFieldData(
-        whereClause,
-        tenantId,
-      );
-      customFieldData.validation = data.validation;
-      customFieldData.order = data.order;
-      return { ...data, ...customFieldData };
-    }
-    return data;
-  }),
-);
+const customFieldIds = formData.fields.result
+  .filter((f) => !f.coreField)
+  .map((f) => f.fieldId);
+
+const customFieldMap = new Map(
+  (await this.fieldsService.getFieldData(
+    `"fieldId" IN (${customFieldIds.map((id) => `'${id}'`).join(",")})`,
+    tenantId,
+  )).map((f) => [f.fieldId, f]),
+);
+
+const mappedResponse = formData.fields.result.map((data) => {
+  if (data.coreField) return data;
+  const custom = customFieldMap.get(data.fieldId) ?? {};
+  return { ...data, ...custom, validation: data.validation, order: data.order };
+});

This eliminates the per-field query while preserving behavior.

📝 Committable suggestion

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

Suggested change
const mappedResponse = await Promise.all(
formData.fields.result.map(async (data) => {
if (!data.coreField) {
const whereClause = `"fieldId" = '${data.fieldId}'`;
const whereClause = `"fieldId" = '${data.fieldId}'`;
const [customFieldData] = await this.fieldsService.getFieldData(
whereClause,
tenantId
tenantId,
);
customFieldData.validation = data.validation;
customFieldData.order = data.order;
customFieldData.order = data.order;
return { ...data, ...customFieldData };
}
return data;
})
}),
);
const customFieldIds = formData.fields.result
.filter((f) => !f.coreField)
.map((f) => f.fieldId);
const customFieldMap = new Map(
(await this.fieldsService.getFieldData(
`"fieldId" IN (${customFieldIds.map((id) => `'${id}'`).join(',')})`,
tenantId,
)).map((f) => [f.fieldId, f]),
);
const mappedResponse = formData.fields.result.map((data) => {
if (data.coreField) return data;
const custom = customFieldMap.get(data.fieldId) ?? {};
return { ...data, ...custom, validation: data.validation, order: data.order };
});
🤖 Prompt for AI Agents
In src/forms/forms.service.ts around lines 71 to 85, the current code makes a
separate database call for each non-core field inside the map, causing N+1 query
issues. To fix this, first collect all fieldIds of non-core fields, then make a
single call to fieldsService.getFieldData with a where clause that fetches all
these fieldIds at once. After retrieving all custom field data in one query,
join this data in-memory with the original formData.fields.result array to
enrich each non-core field without additional DB calls.

Comment on lines 77 to 81
async update(
id: string,
updateLocationDto: any,
response
response,
): Promise<Response> {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing type annotation and improve parameter typing.

Missing type annotation for response parameter and updateLocationDto should have proper typing.

   async update(
     id: string,
-    updateLocationDto: any,
-    response,
+    updateLocationDto: Partial<CreateLocationDto>,
+    response: Response,
   ): Promise<Response> {
📝 Committable suggestion

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

Suggested change
async update(
id: string,
updateLocationDto: any,
response
response,
): Promise<Response> {
async update(
id: string,
updateLocationDto: Partial<CreateLocationDto>,
response: Response,
): Promise<Response> {
🤖 Prompt for AI Agents
In src/location/location.service.ts around lines 77 to 81, the method update has
a missing type annotation for the response parameter and uses any type for
updateLocationDto. Add an explicit type annotation for the response parameter,
such as Response or the appropriate HTTP response type, and replace any with a
proper interface or DTO type that defines the expected structure of
updateLocationDto to improve type safety and clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant