Driver Assignment Repository
Component Detail
Description
Data access layer for driver assignment records, supporting CRUD operations and query patterns needed by the driver assignment service. Persists assignments in the Supabase database with org-scoped row-level security.
driver-assignment-repository
Summaries
This data layer is the authoritative record of every driver assignment within the platform, underpinning billing accuracy, coordinator accountability, and compliance reporting. Soft-delete semantics ensure that historical assignment data is preserved for audits and dispute resolution, protecting the organization from data loss that could complicate legal or financial inquiries. Org-scoped security policies prevent cross-tenant data exposure, which is essential for maintaining client trust in a multi-tenant deployment. Reliable assignment records directly support accurate invoicing and operational reporting that drive business decisions.
Medium-complexity data component with seven query interfaces covering insert, update, soft-delete, and four read patterns. The row-level security policy implementation in Supabase must be designed and tested before other services that depend on this repository can be validated end-to-end. Pagination support on the findByCoordinator query is a delivery dependency for any coordinator dashboard UI. Testing must cover RLS policy enforcement (cross-org isolation), soft-delete behavior, and date range query performance with representative data volumes.
Schema migrations for the driver_assignment and driver_fee data models must be coordinated with the declaration_repository to avoid conflicting migration scripts. Estimate 3–5 days.
Backend data access layer for the driver_assignment and driver_fee data models, exposing insertAssignment, updateAssignment, softDeleteAssignment, findById, findByContact, findByCoordinator (paginated), and findByDateRange. Implement soft-delete via a deleted_at timestamp column rather than a boolean flag to enable time-based retention queries. The findByCoordinator interface must accept a pagination object (limit, offset or cursor) and return a total count for UI pagination. All queries must respect Supabase row-level security policies scoped to orgId—ensure the authenticated JWT context is propagated correctly in the Supabase client.
Index the assignment table on (org_id, contact_id), (org_id, coordinator_id), and (org_id, start_date) to support all declared query patterns at scale.
Responsibilities
- Insert and update driver assignment records
- Query assignments by contact, coordinator, or date range
- Enforce org-scoped row-level security policies
- Soft-delete assignments to preserve audit trail
Interfaces
insertAssignment(assignment)
updateAssignment(id, updates)
softDeleteAssignment(id)
findById(id)
findByContact(contactId)
findByCoordinator(coordinatorId, pagination)
findByDateRange(orgId, from, to)
Relationships
Related Data Entities (2)
Data entities managed by this component
Used Integrations (1)
External integrations and APIs this component relies on