Skip to content

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Sep 9, 2025

Summary by CodeRabbit

  • New Features

    • Login and admin creation now accept email, phone (with country code), or username.
    • Password policy simplified: minimum 8 characters with upper, lower, digit, and special character.
    • Organization list supports tenant/organization filters; organization details include related organizations.
    • Notification templates support optional type and new types: emailHeader, emailFooter.
  • Chores

    • Enhanced default data seeding for tenant, organization, and features.
    • Added user data push utility to Kafka.
    • Added slow SQL query logging.
    • Dependency updates.

Prajwal17Tunerlabs and others added 30 commits August 7, 2025 16:54
tenantCode and orgCode added to role change request body
Encrypted phone, admin create checks, validator updates, unified login
Sequelize slow-query logging; template refactor; validator updates
@coderabbitai
Copy link

coderabbitai bot commented Sep 9, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Replaces an internal tenant endpoint, adds Tenant.readInternal, introduces a Kafka user push script, updates password policy defaults, augments organization service logic, refactors validators for flexible identifiers, seeds default org/features via new migrations, adds SQL slow-query logging, adjusts seeders/scripts for tenant/org codes, and updates dependencies.

Changes

Cohort / File(s) Summary
Constants & Controller
src/constants/common.js, src/controllers/v1/tenant.js
Internal access URL updated to /user/v1/tenant/readInternal/. New controller method readInternal(req) to fetch tenant by code for internal use.
DB Migrations — Default tenant/org seeding
src/database/migrations/20250502091425-create-deafult-tenants-and-domains.js, src/database/migrations/20250506091446-create-deafult-tenants-and-domains.js, src/database/migrations/20250916094307-add-organization-features.js
Removes older seed migration. Adds idempotent seeding of tenant, domain, organization, and organization_features; separate migration to backfill organization_features for default org.
DB Migration — Org code fix
src/database/migrations/20250729064710-org-code-fix.js
Reworks migration to QueryTypes, adds pre-check/early-exit, batches FK disable/enable, consolidates updates, simplifies down to no-op. Updates function signatures.
DB Models Init & Logging
src/database/models/index.js
Adds benchmarked SQL logging with slow-query warning threshold and wires into Sequelize initialization.
Seeders
src/database/seeders/20230802144103-add-entity-and-entity-types.js
Seeds now include tenant_code and organization_code fields sourced from env vars.
Kafka Batch Push Script
src/migrations/pushDataToKafka/pushUserDataToKafka.js
New script: batch-fetch users by date range, enrich org/roles and locations, and push events to Kafka with retries, caching, and cleanup.
Dependencies
src/package.json
Adds minimist@^1.2.8. Downgrades p-limit to ^2.3.0.
Script — Insert Default Org
src/scripts/insertDefaultOrg.js
Removes passing org code as param; relies on env var; adjusts query params count.
Services
src/services/admin.js, src/services/notification.js, src/services/org-admin.js, src/services/organization.js
Admin create: optional email/phone/username, encrypted phone, dynamic OR existence check. Notification: refactors filter construction, removes debug log. Org-admin: event payload includes tenant_code and organization_code. Organization: list filters by tenant and optional org codes; read populates related_org_details.
Validators
src/validators/v1/account.js, src/validators/v1/admin.js, src/validators/v1/notification.js
Removes console log in account. Admin: flexible identifier validation (email/phone/username) for create/login with cross-field rules. Notification: type optional; values extended to sms/email/emailHeader/emailFooter.
Env Variables
src/envVariables.js
Updates PASSWORD_POLICY_REGEX and message to a simpler 8+ chars with upper/lower/digit/special.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Router
  participant TenantController as TenantController.readInternal
  participant TenantService

  Client->>Router: GET /user/v1/tenant/readInternal/:id
  Router->>TenantController: readInternal(req)
  TenantController->>TenantController: validate req.params.id
  alt valid tenantCode
    TenantController->>TenantService: read(tenantCode, true)
    TenantService-->>TenantController: tenant data
    TenantController-->>Router: 200 OK (tenant)
  else missing id
    TenantController-->>Router: 400 bad_request (TENANT_CODE_REQUIRED)
  end
  Router-->>Client: Response
Loading
sequenceDiagram
  autonumber
  participant CLI as CLI User
  participant Script as pushUserDataToKafka.js
  participant Kafka
  participant PG as PostgreSQL
  participant EMS as Entity Mgmt Service

  CLI->>Script: node pushUserDataToKafka --from --to --tenantId
  Script->>Kafka: connect (timeout)
  Kafka-->>Script: connected
  loop batches of 200 user IDs
    Script->>PG: SELECT user_ids updated between from/to for tenant
    PG-->>Script: user_id list
    Script->>PG: JOIN fetch orgs/roles for users
    PG-->>Script: org/role rows
    par per user enrichment
      Script->>EMS: GET location details (with cache/timeout)
      EMS-->>Script: location info or {}
    end
    Script->>Kafka: publish user events
    Kafka-->>Script: acks
  end
  Script-->>CLI: summary & exit
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

I thump the ground: new routes appear,
Seeds sprout orgs, features bloom near.
Kafka winds carry user song,
Passwords trimmed but still quite strong.
Logs squeak softly, slow queries sigh—
Ears up, I ship, then hop on by. 🐇✨

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@nevil-mathew
Copy link
Collaborator Author

@coderabbitai summary

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

✅ Actions performed

Summary regeneration triggered.

fix: update rawSelect queries to use correct identifiers for tenants …
@nevil-mathew nevil-mathew merged commit b9f1815 into staging Sep 23, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 30, 2025
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.

8 participants