Files
co-lite/openspec/changes/add-lead-listing-export/tasks.md
T
ngqileandClaude Opus 5.5 963735d524 feat(mobile-api): leads admin API and @AdminModule(also)
List, detail and update under /api/admin/leads. Update validates and
normalises like capture and needs both Edit leads and Leads, enforced by
the new also() attribute, which fails closed if any lookup throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-27 16:15:36 +08:00

5.9 KiB
Raw Blame History

Tasks

Design: design.md (decision numbers below refer to it). All tasks run serially. Each task touches a hotspot (SQL or pom.xml) or files the next task builds on. Every task is TDD: tests first, run red, then implement.

1. Database

  • 1.1 Write the SQL files (design decision 1):

    • sql/01-lead-index.sql: ALTER TABLE event_lead ADD KEY idx_event_lead_company_lead (company_id, lead_uuid).
    • sql/02-lead-modules.sql: the three module rows.
    • sql/99-rollback.sql.

    Mirror them into local/seed/03-colite.sql. Then apply the index and the module rows to the running local database, because a reset would wipe its test data.

    • Scope: openspec/changes/add-lead-listing-export/sql/**, local/seed/**
    • Verify: a read-only SHOW INDEX FROM event_lead and SELECT on module show the new index and the three rows.

2. services-counter

  • 2.1 Add lead search, detail and update (design decisions 2 and 3):

    • POST /counter/lead/search: the native query with cnt, last and sp.
    • GET /counter/lead/detail/{companyId}/{leadUuid}: the lead with its history and shared contacts.
    • POST /counter/lead/update: @Transactional.

    Tests first. The unit tests cover:

    • the page size cap;
    • blank q;
    • escaping of % and _;
    • passing the digits key;
    • 404 for another company's lead;
    • update sets the six fields plus updatedBy and updatedAt, and is transactional;
    • shared contacts exclude the lead itself and ignore nulls.

    Prove the native query live against local MySQL through the gateway:

    • counts, last event and latest non-null salesperson;
    • a lead with no capture;
    • order;
    • each search form (name, email, 012-345 6701).
    • Scope: solvway-services-counter/src/** (lead files and dto/)
    • Verify: mvn -T 1C -B -q -pl solvway-services-counter -am verify.

3. mobile-api

  • 3.1 Add the leads admin API (design decision 4): list, detail and update under /api/admin/leads, with the module rules and the second check in code.

    Tests first:

    • each validation code, with update normalisation the same as capture;
    • the digits key built from 012-345 6701 and from +60 12-345 6701;
    • @AdminModule(also=…) in AppAccessAspect: missing an also module gives 403, super admin passes, injected ROLE_ADMIN grants nothing; the update is refused 403 without BO_LEADS, even with BO_LEADS_EDIT;
    • uuids are strings;
    • the latest salesperson and history names are resolved once per request.

    Live check through the gateway.

    • Scope: solvway-mobile-api/src/** (lead files)
    • Verify: mvn -T 1C -B -q -pl solvway-mobile-api -am verify.
  • 3.2 Add both xlsx exports (design decision 5):

    • Add poi-ooxml 4.1.0 to solvway-mobile-api/pom.xml and record the dependency:tree result.
    • Add the export endpoints for leads and event leads.

    Tests first:

    • the header row and column order of each export;
    • the mobile cell is a string;
    • follow-up and capture cells are dates;
    • all pages are collected;
    • more than 20,000 rows gives 422 EXPORT_TOO_LARGE before any write;
    • 403 without the listing module;
    • the audit log line has no lead data.

    Tests read the workbook back with POI. Live check: download both files through the gateway and open them with POI.

    • Scope: solvway-mobile-api/pom.xml, solvway-mobile-api/src/**
    • Verify: mvn -T 1C -B -q -pl solvway-mobile-api -am verify.

4. Portal

  • 4.1 Add the Lead Listing and lead detail (design decision 6):

    • the leads data layer: route app/api/leads/[...path], service, types, and /leads mapped to BO_LEADS;
    • the /leads listing with search;
    • the /leads/[leadUuid] detail page, with an edit form when the user has BO_LEADS_EDIT, the shared-contact warning, the event history and not-found;
    • a "View lead" link on the event lead edit page when the user has BO_LEADS.

    Leads* i18n keys. Tests first, one per portal-visible lead-records scenario.

    • Scope: solvway-admin-portal/app/leads/**, solvway-admin-portal/app/api/leads/**, solvway-admin-portal/app/lib/**, solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/**
    • Verify: cd solvway-admin-portal && npx vitest run && npx tsc --noEmit && npm run lint && npm run build.
  • 4.2 Add the Export buttons (design decision 6):

    • a binary variant of callMobileApi with the same error shape;
    • the app/api/leads/export and app/api/event-leads/[eventUuid]/export routes, which pass through Content-Type and Content-Disposition;
    • an Export button on both listings when the user has BO_LEADS_EXPORT. It sends the current search or filters, downloads via Blob under the server's filename, shows EXPORT_TOO_LARGE and other errors on the page, and is disabled while running.

    Tests first.

    • Scope: solvway-admin-portal/app/api/**/export/**, solvway-admin-portal/app/lib/**, solvway-admin-portal/app/leads/page*, solvway-admin-portal/app/event-leads/[eventUuid]/page*
    • Verify: as 4.1.

5. Browser check

  • 5.1 Rebuild the changed services and drive the portal with Playwright, using only local dev data and made-up test leads.
    • Desktop:
      • Grant the three modules to a role.
      • On Leads, check the counts, last event and latest salesperson of a lead captured at two events.
      • Search by name, by email and by 012-345 6701.
      • Open a lead and check the history and the shared-mobile warning.
      • Edit the email and company.
      • Try an invalid mobile.
      • Export Leads with a search, and export an event's leads with a filter. Open both files and check the columns, the rows and that the mobile is text.
    • 360×780: the lead detail page and its edit form.
    • Restricted users:
      • A user without BO_LEADS_EDIT sees the lead read-only.
      • A user without BO_LEADS_EXPORT sees no Export button, and the export API returns 403.
      • A user without BO_LEADS gets not-authorised on /leads.