Skip to content

feat: add DailyEstimatedVolume field to KYBProfile and related struct…#693

Merged
onahprosper merged 4 commits intomainfrom
feature/kyb-daily-estimated-volume
Feb 18, 2026
Merged

feat: add DailyEstimatedVolume field to KYBProfile and related struct…#693
onahprosper merged 4 commits intomainfrom
feature/kyb-daily-estimated-volume

Conversation

@sundayonah
Copy link
Collaborator

@sundayonah sundayonah commented Feb 18, 2026

Description

This PR updates the aggregator KYB flow to:

  1. Add required Daily Estimated Volume

    • New required field dailyEstimatedVolume on KYB submission (company-level).
    • Stored in kyb_profile.daily_estimated_volume, returned in GET /v1/kyb-submission.
    • Aligns with dashboard onboarding, which already collects and sends this value.
  2. Align with company vs beneficial-owner proof of address

    • Company-level proof of address is Proof of Business Address only.
    • Company-level Proof of Residential Address is not used; residential proof is only for beneficial owners.
    • KYBSubmissionInput does not include company-level proofOfResidentialAddressUrl; no breaking change if the dashboard already omits it.

Implementation details

  • Types (types/types.go):

    • KYBSubmissionInput: added DailyEstimatedVolume with binding:"required".
    • KYBDocumentsResponse: added DailyEstimatedVolume for GET response.
  • Ent schema (ent/schema/kybprofile.go): added field.String("daily_estimated_volume").
    Ent codegen was run (go generate ./ent).

  • Controller (controllers/index.go):

    • Create/update KYB: set DailyEstimatedVolume from input.
    • Get KYB documents: include DailyEstimatedVolume in response.
  • Tests (controllers/index_test.go):

    • All KYBSubmissionInput literals and KYB profile creates include DailyEstimatedVolume.
    • Resubmission test asserts updated profile has correct DailyEstimatedVolume.

Testing

  • Unit/integration:

    • go test ./controllers -run TestIndex/HandleKYBSubmission -v
    • go test ./controllers -run TestIndex/GetKYBDocuments -v
    • All KYB-related test data includes DailyEstimatedVolume; resubmission case asserts the field is persisted and returned.
  • Manual:

    • Submit KYB from dashboard (with Daily Estimated Volume) and confirm 201 and stored value.
    • GET /v1/kyb-submission and confirm dailyEstimatedVolume in response.
    • Omit dailyEstimatedVolume in POST body and confirm 400 "Invalid input".
  • Environment: Go 1.25, Windows; tests use in-memory SQLite via enttest.

  • This change adds test coverage for new/changed/fixed functionality
    (Existing tests updated for new field; no new dedicated test file.)


Checklist

  • I have added documentation and tests for new/changed/functionality in this PR
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

By submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.

Summary by CodeRabbit

  • New Features
    • Added daily estimated volume to KYB submissions (now accepted and required).
    • Daily estimated volume is returned in KYB profile responses and document views.
    • KYB profiles can be sorted and filtered by daily estimated volume for improved search and reporting.

…ures

- Introduced the DailyEstimatedVolume field in the KYBProfile schema and updated the corresponding input and response types.
- Enhanced the KYB submission handling to include DailyEstimatedVolume, ensuring it is processed and validated correctly.
- Updated tests to reflect the addition of DailyEstimatedVolume, ensuring comprehensive coverage for the new field.
- Added necessary mutations and predicates for DailyEstimatedVolume to support database operations and queries.
- Added assertion for DailyEstimatedVolume in the TestIndex function to ensure the new field is correctly processed and validated in the KYBProfile.
- Updated test cases to reflect the recent addition of DailyEstimatedVolume, enhancing test coverage for the KYB submission process.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

Adds a new DailyEstimatedVolume field across KYB: API input/output types, Ent schema/mutations/builders, DB migration, controller wiring, and tests to accept, persist, query, and return daily estimated volume.

Changes

Cohort / File(s) Summary
Database / Migration
ent/migrate/migrations/20260218105934_add_daily_estimated_volume.sql, ent/migrate/schema.go
Add daily_estimated_volume column to kyb_profiles (varchar, not null, default ""); adjust columns/FK index due to column insertion.
Ent Schema & Runtime
ent/schema/kybprofile.go, ent/runtime/runtime.go
Declare daily_estimated_volume field in schema and initialize DefaultDailyEstimatedVolume from descriptors at runtime.
ORM Core (models & columns)
ent/kybprofile.go, ent/kybprofile/kybprofile.go
Add DailyEstimatedVolume field on KYBProfile struct, scan/assign logic, string output; add FieldDailyEstimatedVolume, column mapping, default const, and ByDailyEstimatedVolume ordering helper.
Query Predicates
ent/kybprofile/where.go
Add predicate helpers for daily_estimated_volume (EQ, NEQ, In, NotIn, GT, GTE, LT, LTE, Contains, HasPrefix, HasSuffix, EqualFold, ContainsFold).
Create / Upsert / Update Builders
ent/kybprofile_create.go, ent/kybprofile_update.go
Add Set/SetNillable methods for daily_estimated_volume, include field in defaults, validation/checks, create/upsert/update specs, and upsert update propagation.
Mutations API
ent/mutation.go
Extend KYBProfileMutation with daily_estimated_volume field and methods: Set, getter, Old*, Reset, and integrate into Fields/Field/OldField/SetField/ResetField logic.
API Types
types/types.go
Add DailyEstimatedVolume string to KYBSubmissionInput (binding/validation) and KYBDocumentsResponse (JSON).
Controller Wiring & Tests
controllers/index.go, controllers/index_test.go
Wire input.DailyEstimatedVolume into KYB create/update flows via SetDailyEstimatedVolume; include kybProfile.DailyEstimatedVolume in responses and update tests/fixtures/assertions accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Controller as Controller
    participant Types as TypesBinder
    participant Ent as EntBuilder
    participant DB as Database

    Client->>Controller: POST/PUT KYB submission (dailyEstimatedVolume)
    Controller->>Types: bind request -> KYBSubmissionInput.DailyEstimatedVolume
    Controller->>Ent: call SetDailyEstimatedVolume on KYBProfile create/update
    Ent->>DB: INSERT/UPDATE kyb_profiles.daily_estimated_volume
    DB-->>Ent: confirm write
    Ent-->>Controller: return KYBProfile with DailyEstimatedVolume
    Controller->>Client: respond with KYBDocumentsResponse.dailyEstimatedVolume
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • chibie
  • 5ran6

Poem

🐰 A nibble of schema, a tiny new field,
Hops from input to DB, perfectly sealed.
Profiles and docs now carry the measure,
I celebrate with a crunchy treasure —
🥕📈 Hooray for data that’s neatly revealed!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a DailyEstimatedVolume field to KYBProfile and related structures.
Description check ✅ Passed The description comprehensively covers purpose, implementation details, testing approach, and includes checklist items as required by the template.
Docstring Coverage ✅ Passed Docstring coverage is 95.65% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/kyb-daily-estimated-volume

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.

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

🧹 Nitpick comments (1)
controllers/index_test.go (1)

376-381: Add assertions to cover DailyEstimatedVolume in create + documents responses.
This will ensure the new field is validated end‑to‑end, not just on resubmission.

🧪 Suggested test additions
@@
 			assert.Equal(t, validKYBSubmission.CompanyName, kybProfile.CompanyName)
 			assert.Equal(t, validKYBSubmission.RegisteredBusinessAddress, kybProfile.RegisteredBusinessAddress)
+			assert.Equal(t, validKYBSubmission.DailyEstimatedVolume, kybProfile.DailyEstimatedVolume)
@@
 			assert.Equal(t, kybData.CompanyName, data["companyName"])
 			assert.Equal(t, kybData.MobileNumber, data["mobileNumber"])
 			assert.Equal(t, kybData.RegisteredBusinessAddress, data["registeredBusinessAddress"])
+			assert.Equal(t, kybData.DailyEstimatedVolume, data["dailyEstimatedVolume"])

Also applies to: 775-780

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@controllers/index_test.go` around lines 376 - 381, The tests currently set
validKYBSubmission.DailyEstimatedVolume but do not assert it in the create and
documents responses; update the tests in controllers/index_test.go to assert
that the API responses include DailyEstimatedVolume (e.g., after calling the KYB
creation helper and when fetching documents) by checking the response JSON/body
contains the same DailyEstimatedVolume value from validKYBSubmission, and add
the same assertion to the resubmission/document-related test paths (the tests
around the validKYBSubmission variable and the create/documents response checks)
so the new field is validated end-to-end.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ent/schema/kybprofile.go`:
- Line 30: The new schema adds a non-nullable column via
field.String("daily_estimated_volume") which will break migrations for the
existing kyb_profiles table; update the schema definition for
daily_estimated_volume to allow safe migration by making it have a default or be
optional (e.g., change field.String("daily_estimated_volume") to include
.Default("") if an empty string is acceptable or .Optional() if it should be
nullable) so ALTER TABLE can succeed without failing on existing rows.

---

Nitpick comments:
In `@controllers/index_test.go`:
- Around line 376-381: The tests currently set
validKYBSubmission.DailyEstimatedVolume but do not assert it in the create and
documents responses; update the tests in controllers/index_test.go to assert
that the API responses include DailyEstimatedVolume (e.g., after calling the KYB
creation helper and when fetching documents) by checking the response JSON/body
contains the same DailyEstimatedVolume value from validKYBSubmission, and add
the same assertion to the resubmission/document-related test paths (the tests
around the validKYBSubmission variable and the create/documents response checks)
so the new field is validated end-to-end.

sundayonah and others added 2 commits February 18, 2026 11:40
…r DailyEstimatedVolume

- Introduced SetNillableDailyEstimatedVolume method in KYBProfileCreate to conditionally set the daily_estimated_volume field.
- Defined DefaultDailyEstimatedVolume in the KYBProfile schema to ensure a default value is used during creation.
- Updated schema migration to set a default value for daily_estimated_volume in the database.
- Enhanced runtime initialization to include the new default value for DailyEstimatedVolume.
- Introduced a new column "daily_estimated_volume" in the "kyb_profiles" table with a default value of an empty string.
- Updated migration files to reflect this schema change, ensuring the database structure aligns with recent enhancements to the KYBProfile schema.
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ent/migrate/migrations/20260218105934_add_daily_estimated_volume.sql`:
- Line 2: The migration adds kyb_profiles.daily_estimated_volume as NOT NULL
DEFAULT '' which leaves existing rows with a semantic empty string; either
backfill existing rows or make the column nullable so legacy rows can be
distinguished. Fix by one of: (A) add a backfill UPDATE in the migration that
sets a meaningful placeholder (e.g., 'unknown' or calculated historical value)
for all rows in kyb_profiles, then ALTER TABLE to set NOT NULL and keep/adjust
DEFAULT as desired; or (B) change the DDL to character varying NULL (remove NOT
NULL and DEFAULT '') so legacy rows remain NULL and the application (GET
/v1/kyb-submission and binding:"required" for new input) can treat NULL as "not
set"; if you choose (A) optionally add a CHECK constraint (CHECK
(daily_estimated_volume <> '')) only after the backfill completes.

@onahprosper onahprosper merged commit 64acef0 into main Feb 18, 2026
2 checks passed
onahprosper added a commit that referenced this pull request Feb 19, 2026
…ated-volume"

This reverts commit 64acef0, reversing
changes made to d157c75.
@coderabbitai coderabbitai bot mentioned this pull request Feb 19, 2026
4 tasks
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.

2 participants

Comments