a6c0f3de-eeb0-4d76-a57f-f600dd133c06
This commit is contained in:
1 parent
2aa3496a90
commit
762f3d7373
141 files changed
+4485
-69
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { db } from '@/lib/db'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// PATCH /api/aos/tickets/[id]/escalate
|
||||
// An agency escalates a ticket to us (the platform admin). After escalation,
|
||||
// the ticket appears in our admin inbox (scope=admin sees escalated tickets).
|
||||
export async function PATCH(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const ticket = await db.ticket.findUnique({ where: { id } })
|
||||
if (!ticket) {
|
||||
return NextResponse.json({ error: 'ticket not found' }, { status: 404 })
|
||||
}
|
||||
if (ticket.escalatedToAdmin) {
|
||||
return NextResponse.json({ error: 'already escalated' }, { status: 409 })
|
||||
}
|
||||
|
||||
await db.ticket.update({
|
||||
where: { id },
|
||||
data: {
|
||||
escalatedToAdmin: true,
|
||||
escalatedAt: new Date(),
|
||||
status: 'open', // reopen for admin attention
|
||||
},
|
||||
})
|
||||
|
||||
await db.auditLog.create({
|
||||
data: {
|
||||
actor: 'agency:escalate',
|
||||
action: 'ticket.escalate',
|
||||
entity: 'Ticket',
|
||||
entityId: id,
|
||||
after: JSON.stringify({ number: ticket.number, escalatedAt: new Date() }),
|
||||
hash: 'sha256:' + Math.random().toString(36).slice(2),
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({ ok: true, escalatedToAdmin: true })
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : 'internal server error'
|
||||
return NextResponse.json({ error: msg }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user