An assignment is the operational bridge between an approved booking and the employee who will receive the vehicle. Rather than linking a booking directly to an employee, KaroKar inserts an explicit Assignment domain in between — a design decision that keeps the Booking domain focused on vendor-corporate negotiations while giving the Assignment domain full control over employee handovers, acceptance workflows, and future reassignment scenarios. Every vehicle handover — whether from a vendor-owned booking or a corporate-owned direct assignment — is tracked through anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Codefied-CodePix/Karokar-backend/llms.txt
Use this file to discover all available pages before exploring further.
Assignment record.
Why Assignments Exist as a Separate Domain
The intuitive model would be to storeemployeeId on the Booking entity. KaroKar deliberately rejects this:
- Reassignments — swap the employee on an active vehicle without touching the booking
- Pool vehicles — assign a vehicle to a pool rather than a named employee
- Corporate-owned vehicles — bypass the Booking domain entirely and go straight to Assignment
- Future driver workflows — assign a driver separately from the beneficiary employee
Assignment Entity
| Field | Type | Description |
|---|---|---|
id | uuid | Unique assignment identifier (from BaseEntity) |
bookingId | uuid | null | The booking this assignment originates from, or null for direct corporate assignments |
vehicleId | uuid | The vehicle being assigned |
corporateOrganizationId | uuid | The corporate organization responsible for this assignment |
employeeId | uuid | The employee receiving the vehicle |
status | AssignmentStatus | Current state of the assignment |
startDate | timestamptz | When the assignment period begins |
endDate | timestamptz | null | When it ends — null for open-ended assignments |
createdAt | timestamptz | Record creation timestamp (from BaseEntity) |
updatedAt | timestamptz | Last modification timestamp (from BaseEntity) |
bookingId is nullable because corporate-owned vehicles enter the Assignment domain directly — there is no parent booking. For vendor-owned vehicles, bookingId always references the originating Booking record.Assignment Statuses
| Status | Meaning |
|---|---|
PENDING | Assignment created and awaiting employee acknowledgement |
ACCEPTED | Employee has accepted the assignment and acknowledged the handover |
REJECTED | Employee declined the assignment |
ACTIVE | Vehicle is in active use by the employee |
COMPLETED | Assignment ended as planned |
CLOSED | Assignment force-closed, typically due to booking termination |
How Assignments Are Created
Assignments are never created directly by a controller call on a booking. Instead,BookingService.assignEmployee() transitions the booking to ASSIGNED and emits a BookingAssignedEvent. The Assignment domain listens for this event and creates the assignment automatically.
AssignmentService.createAssignment() persists the record with status: PENDING and immediately emits an AssignmentCreatedEvent — notifying downstream consumers such as the Notification domain.
Assignment Lifecycle
Assignment Created (PENDING)
Triggered automatically by the
BookingAssigned domain event. The assignment is created with status: PENDING. The employee is notified that a vehicle has been assigned to them and their acceptance is required.Domain event emitted: AssignmentCreatedEventEmployee Accepts (ACCEPTED → ACTIVE)
The employee calls:This requires the Domain event emitted:
assignment.accept permission. AssignmentService.acceptAssignment(id) is responsible for transitioning the assignment and emitting AssignmentAcceptedEvent.acceptAssignment is not yet implemented and currently throws NotImplementedException. The acceptance workflow is planned for a future phase.AssignmentAcceptedEventEmployee Rejects (REJECTED)
If the employee cannot accept the vehicle, they call:Domain event emitted:
AssignmentService.rejectAssignment(id) sets the assignment to REJECTED and emits AssignmentRejectedEvent. The corporate admin must take action — either reassigning to another employee or cancelling the booking.rejectAssignment is not yet implemented and currently throws NotImplementedException. The rejection workflow is planned for a future phase.AssignmentRejectedEventAssignment Closed (CLOSED)
An active assignment is force-closed when the parent booking is terminated. The
BookingTerminated event triggers AssignmentService.closeAssignment(id), which transitions the assignment to CLOSED regardless of its current state.Assignments can also reach COMPLETED through a planned booking completion.Domain event emitted: AssignmentClosedEventRelationship to Bookings
The full relationship chain for a vendor-owned vehicle transaction:Booking Termination Closes Active Assignments
WhenBookingService.terminateBooking() is called, the resulting BookingTerminatedEvent is consumed by the Assignment domain. Any assignment in PENDING, ACCEPTED, or ACTIVE state against the terminated booking is immediately transitioned to CLOSED.
Domain Events Summary
| Event | Triggered By | Description |
|---|---|---|
AssignmentCreatedEvent | BookingAssigned event consumed | New assignment created in PENDING |
AssignmentAcceptedEvent | PATCH /assignments/:id/accept | Employee accepted the vehicle handover |
AssignmentRejectedEvent | PATCH /assignments/:id/reject | Employee declined the vehicle handover |
AssignmentClosedEvent | BookingTerminated event consumed | Assignment force-closed due to booking termination |
Required Permissions
| Action | Required Permission |
|---|---|
| Accept an assignment | assignment.accept |
| Reject an assignment | assignment.accept |
| View assignment details | assignment.read |
CreateAssignmentInput
When the Assignment domain creates an assignment in response to a BookingAssigned event, it uses the following input shape:
status: AssignmentStatus.PENDING.