Extends the existing PATCH /admin/agents/:agentId with an optional userId to finish wiring 010's Agent.userId link, and adds GET /agents/me/tickets + GET /admin/agents/:agentId/tickets sharing one ticketing/tickets service method, backed by a new Assignment @@index([agentId, isCurrent]). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2.2 KiB
Contract: Agent Ticket Queue
PATCH /admin/agents/:agentId (existing route, extended)
Auth: fastify.authenticate (unchanged — this route was already agent-usable, not
admin-only, since agents may already update their own roster fields per existing precedent).
Request body (existing shape plus one new optional field):
{
"name": "string, optional",
"teamId": "string, optional",
"active": "boolean, optional",
"userId": "string | null, optional"
}
Responses:
200— updatedAgent, includinguserId.404—agentIddoesn't exist, or (new) the targetuserIddoesn't exist as aUser.400— (new) the targetUser's role is notAGENT.409— (new) the targetuserIdis already linked to a differentAgent.
GET /agents/me/tickets
Auth: fastify.authenticate only — no requireRole, since any authenticated AGENT (or
ADMIN, who may also hold an agent profile) may call this for their own session.
Response 200:
{
"success": true,
"data": [
{
"id": "string",
"code": "string",
"status": "string",
"priority": "string",
"severity": "string",
"product": { "id": "string", "externalProductId": "string", "name": "string" },
"customer": { "externalUserId": "string", "externalTenantId": "string" },
"assignedAt": "ISO 8601 datetime",
"sla": {
"status": "string",
"firstResponseDueAt": "ISO 8601 datetime | null",
"resolutionDueAt": "ISO 8601 datetime | null",
"breachedAt": "ISO 8601 datetime | null"
}
}
],
"meta": null
}
sla is null when no SLARun exists yet for that ticket.
Response 404: the session's User has no linked Agent row
({ "success": false, "error": { "code": "NOT_FOUND", "message": "No agent profile is linked to this account." } }).
GET /admin/agents/:agentId/tickets
Auth: fastify.authenticate + requireRole('ADMIN').
Response: identical shape to GET /agents/me/tickets's 200, for the agentId named in
the URL. 404 if agentId doesn't exist as an Agent row (a plain "agent not found," distinct
from the self-route's "no agent linked to this account").