Commit Graph
9 Commits
Author SHA1 Message Date
Gustavo 18d427e2bd Add Configuracoes review section for shared numbers
Adds an admin-only "Numeros compartilhados entre leads" section to the
settings modal, wired to the Task 4 shared-numbers routes: lists
detected groups, lets an admin liberar (with an inline motivo input)
or bloquear de novo. Updates the two frontend VM-based test files'
default API mocks to answer GET /api/outreach/shared-numbers so
existing settings-modal tests keep passing, and adds a new
interaction test covering the liberar round trip.
2026-07-31 16:33:03 -03:00
Gustavo a6dce5c936 Show shared-number badge in the treatment table and lead detail 2026-07-31 12:22:36 -03:00
Gustavo 1370b39cee Expose shared-number state on lead list and detail queries 2026-07-31 12:18:26 -03:00
Gustavo 16b29a83d0 Add shared-number review routes and block manual send for unreleased numbers 2026-07-31 12:13:46 -03:00
Gustavo d85fb12991 Exclude leads sharing a WhatsApp number from the automatic campaign queue
candidateQuery now blocks a lead whose WhatsApp number is shared by 2+
leads, unless a shared-number override exists. The inner correlated
subquery compares the bare other.whatsapp column (not normalizedSql())
against the outer row's two computed number forms so SQLite can use
idx_leads_whatsapp instead of a full table scan, keeping the 1.3M-row
perf test within budget.

Also updates the pre-existing 'persiste erro temporario e nao repete
equivalente' test: its two leads use 8/9-digit equivalent numbers,
which the new filter now blocks by default, so an override is added
to keep exercising the intended equivalent-number dedup behavior.
2026-07-31 11:18:41 -03:00
GustavoandClaude Sonnet 5 3d2144eefc Block manual send reservation for unreleased shared numbers
Implement shared-number detection in reserveOutreachSend: reject manual WhatsApp sends with HTTP 409 when the destination number is shared across 2+ leads and hasn't been explicitly released via override.

- Add test: reserveOutreachSend bloqueia numero compartilhado sem override e libera com override
- Add check in reserveOutreachSend right after isOptedOut check
- Uses isNumberSharedAcrossLeads and isSharedNumberOverridden from Task 1

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-31 11:11:54 -03:00
GustavoandClaude Sonnet 5 40bd8d096e Fix v15 migration test to drop v19 table before replaying migrations
The v15 test pattern (delete migration records >= 15, drop schema, reopen to replay)
was failing because outreach_shared_number_overrides table from v19 migration was not
dropped before replaying. Add DROP TABLE IF EXISTS to the schema cleanup block to
match the same fix applied to v17 test.

This resolves the 'table already exists' error during v19 migration replay.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-31 11:04:22 -03:00
GustavoandClaude Sonnet 5 fe70436dbb Add shared-number detection and override data layer
- Add migration v19: creates outreach_shared_number_overrides table
- Implement 7 new data-layer functions:
  - leadsSharingNumber: find leads sharing a phone number variant
  - isNumberSharedAcrossLeads: detect if number is shared by 2+ leads
  - getSharedNumberOverride: retrieve override entry for a number
  - isSharedNumberOverridden: check if number has an override
  - addSharedNumberOverride: create or update override with reason
  - removeSharedNumberOverride: delete override record
  - listSharedNumberGroups: group leads by shared numbers, reflect override state
- Add 4 comprehensive tests covering migration, detection, override crud, and grouping
- Update version assertions from 18 to 19
- Fix v17 migration test to properly clean up v19 table for schema reset

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-31 10:59:29 -03:00
Gustavo d330bb5ff0 Baseline commit of the existing Maquina Comercial Pessoal project
Tracks the app that was already in place (capture, treatment, outreach,
WhatsApp integration, server, frontend, tests, docs) so future feature
work can branch and use isolated worktrees.
2026-07-31 10:54:07 -03:00