4.4 KiB
4.4 KiB
Task C: Customer + Contact Production Module
1. Files Added
src/app/api/crm/customers/route.tssrc/app/api/crm/customers/[id]/route.tssrc/app/api/crm/customers/[id]/contacts/route.tssrc/app/api/crm/customers/[id]/contacts/[contactId]/route.tssrc/features/crm/customers/api/types.tssrc/features/crm/customers/api/service.tssrc/features/crm/customers/api/queries.tssrc/features/crm/customers/api/mutations.tssrc/features/crm/customers/schemas/customer.schema.tssrc/features/crm/customers/server/service.tssrc/features/crm/customers/components/customer-status-badge.tsxsrc/features/crm/customers/components/customer-form-sheet.tsxsrc/features/crm/customers/components/contact-form-sheet.tsxsrc/features/crm/customers/components/customer-cell-action.tsxsrc/features/crm/customers/components/customer-columns.tsxsrc/features/crm/customers/components/customers-table.tsxsrc/features/crm/customers/components/customer-listing.tsxsrc/features/crm/customers/components/customer-contacts-tab.tsxsrc/features/crm/customers/components/customer-detail.tsxdrizzle/0002_plain_anthem.sqldrizzle/meta/0002_snapshot.json
2. Files Modified
src/app/dashboard/crm/customers/page.tsxsrc/app/dashboard/crm/customers/[id]/page.tsxsrc/db/schema.tssrc/db/seeds/foundation.seed.tssrc/features/foundation/audit-log/service.tssrc/features/foundation/audit-log/types.tssrc/lib/auth/rbac.tssrc/lib/searchparams.tsdrizzle/meta/_journal.json
3. Schema Added
crm_customers- organization-scoped customer master with unique
(organization_id, code) - branch, CRM classification, contact channels, notes, soft-delete, and audit actor columns
- organization-scoped customer master with unique
crm_customer_contacts- organization-scoped child contacts under customer
- primary contact flag, soft-delete, and audit actor columns
4. API Routes Added
GET /api/crm/customersPOST /api/crm/customersGET /api/crm/customers/[id]PATCH /api/crm/customers/[id]DELETE /api/crm/customers/[id]GET /api/crm/customers/[id]/contactsPOST /api/crm/customers/[id]/contactsPATCH /api/crm/customers/[id]/contacts/[contactId]DELETE /api/crm/customers/[id]/contacts/[contactId]
5. UI Routes Completed
/dashboard/crm/customers- production list with React Query, nuqs filters, create button, edit/view/delete actions
/dashboard/crm/customers/[id]- detail page with Template A style structure
- tabs: Overview, Contacts, Activity, Related Documents Placeholder
6. Permissions Used
crm.customer.readcrm.customer.createcrm.customer.updatecrm.customer.deletecrm.contact.readcrm.contact.createcrm.contact.updatecrm.contact.delete
Admin defaults now include the CRM customer/contact permissions. Regular users inherit read permissions only unless additional permissions are granted.
7. Audit Integration
- customer create/update/delete writes to
tr_audit_logswithentityType = crm_customer - contact create/update/delete writes to
tr_audit_logswithentityType = crm_customer_contact - activity tab reads audit log entries for the current customer and resolves actor names from
users
8. Document Sequence Integration
- customer create uses
generateNextDocumentCode({ documentType: 'customer' }) - branch-specific sequence is honored when
branchIdis provided - foundation seed now also prepares
crm_customer_groupoptions for form-driven classification
9. Remaining Risks
- there are no database foreign keys yet between
crm_customers,crm_customer_contacts, and master option rows; organization filtering is enforced in application code - branch scope currently resolves from seeded
crm_branchoptions only; if branch ownership becomes role-sensitive later,branch-scopewill need stronger membership-aware rules - contact primary uniqueness is enforced in transaction logic, not via a database partial unique index
- list/detail UI depends on seeded master options being present for customer status/type/group/channel labels
10. Task D Readiness
- customer and contact production backbone is ready for enquiry linkage
- activity timeline is already in place for future downstream CRM entities
- customer detail route now has a stable home for related document tabs
- foundation permissions, sequence, branch scope, and audit plumbing are reusable for enquiry and quotation modules