Overview
Implement a `GET` handler that returns all audit events related to a specific invoice.
⚠️ Scope: Write your code only inside `app/api/routes-b/invoices/[id]/activity/route.ts`. Do not touch any file outside this folder.
Create the route file
File: `app/api/routes-b/invoices/[id]/activity/route.ts`
The `AuditEvent` model already exists in `prisma/schema.prisma`.
Handler logic
- Verify auth
- Find invoice by `params.id` — verify `invoice.userId === user.id`
- Fetch `AuditEvent` records where `resourceType === 'invoice'` AND `resourceId === params.id`
- Order by `createdAt asc` (chronological)
Expected response
```json
{
"activity": [
{
"id": "uuid",
"action": "invoice_created",
"ipAddress": "192.168.1.1",
"createdAt": "2025-01-01T00:00:00.000Z"
},
{
"id": "uuid",
"action": "invoice_viewed",
"ipAddress": "41.58.0.1",
"createdAt": "2025-01-02T09:00:00.000Z"
}
]
}
```
Acceptance criteria
Overview
Implement a `GET` handler that returns all audit events related to a specific invoice.
Create the route file
File: `app/api/routes-b/invoices/[id]/activity/route.ts`
The `AuditEvent` model already exists in `prisma/schema.prisma`.
Handler logic
Expected response
```json
{
"activity": [
{
"id": "uuid",
"action": "invoice_created",
"ipAddress": "192.168.1.1",
"createdAt": "2025-01-01T00:00:00.000Z"
},
{
"id": "uuid",
"action": "invoice_viewed",
"ipAddress": "41.58.0.1",
"createdAt": "2025-01-02T09:00:00.000Z"
}
]
}
```
Acceptance criteria