feat(contacts): populate CompanyResponse rollup fields #59

Merged
YousifShkara merged 1 commit from feat/crm-ops into main 2026-06-04 06:52:20 +02:00
Owner

The CompanyResponse DTO declared account_manager_name, contact_count,
site_count, and open_ticket_count as Option<...>, but the
From impl always set them to None and no SQL ever populated
them. The mokosh-apps Companies list page reads
company.account_manager_name and company.open_ticket_count off the
response; those columns were rendering blank on every row.

Add ContactService::enrich_companies which runs ONE follow-up query
per page (regardless of page size) and zips the four rollup values
into the responses by company id. Run it from the list and detail
route handlers.

Counts:

  • account_manager_name: LEFT JOIN users on account_manager_id.
  • contact_count, site_count, open_ticket_count: correlated
    subqueries scoped to (tenant_id, company_id).
  • open_ticket_count filters closed_at IS NULL so the metric tracks
    what the UI calls 'open'.

Internal callers of list_companies / get_company that consume the
lean Company shape (update_company, create_company, validate_fk,
contact-side validators) keep working: the base service methods
still return Company; only the route-facing flow goes through
enrich_companies.

The CompanyResponse DTO declared account_manager_name, contact_count, site_count, and open_ticket_count as Option<...>, but the From<Company> impl always set them to None and no SQL ever populated them. The mokosh-apps Companies list page reads company.account_manager_name and company.open_ticket_count off the response; those columns were rendering blank on every row. Add ContactService::enrich_companies which runs ONE follow-up query per page (regardless of page size) and zips the four rollup values into the responses by company id. Run it from the list and detail route handlers. Counts: - account_manager_name: LEFT JOIN users on account_manager_id. - contact_count, site_count, open_ticket_count: correlated subqueries scoped to (tenant_id, company_id). - open_ticket_count filters closed_at IS NULL so the metric tracks what the UI calls 'open'. Internal callers of list_companies / get_company that consume the lean Company shape (update_company, create_company, validate_fk, contact-side validators) keep working: the base service methods still return Company; only the route-facing flow goes through enrich_companies.
feat(contacts): populate CompanyResponse rollup fields
All checks were successful
Build OCI container / Build and push mokosh-api image (push) Successful in 5m48s
Create release / Create release from merged PR (pull_request) Has been skipped
Check / fmt + clippy + compile + tests (pull_request) Successful in 45s
abc2bc4b0c
The CompanyResponse DTO declared account_manager_name, contact_count,
site_count, and open_ticket_count as Option<...>, but the
From<Company> impl always set them to None and no SQL ever populated
them. The mokosh-apps Companies list page reads
company.account_manager_name and company.open_ticket_count off the
response; those columns were rendering blank on every row.

Add ContactService::enrich_companies which runs ONE follow-up query
per page (regardless of page size) and zips the four rollup values
into the responses by company id. Run it from the list and detail
route handlers.

Counts:
- account_manager_name: LEFT JOIN users on account_manager_id.
- contact_count, site_count, open_ticket_count: correlated
  subqueries scoped to (tenant_id, company_id).
- open_ticket_count filters closed_at IS NULL so the metric tracks
  what the UI calls 'open'.

Internal callers of list_companies / get_company that consume the
lean Company shape (update_company, create_company, validate_fk,
contact-side validators) keep working: the base service methods
still return Company; only the route-facing flow goes through
enrich_companies.
YousifShkara deleted branch feat/crm-ops 2026-06-04 06:52:21 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!59
No description provided.