Fix admin cleanup hook order and lint setup
This commit is contained in:
parent
37c32149a6
commit
c7aaa60d9a
4 changed files with 1886 additions and 31 deletions
|
|
@ -10,6 +10,28 @@ export const runtime = "nodejs"
|
|||
|
||||
const MAX_RESULTS = 10
|
||||
|
||||
type TicketRecord = {
|
||||
id: string | number
|
||||
reference: string | number
|
||||
subject?: string | null
|
||||
status?: string | null
|
||||
priority?: string | null
|
||||
requester?: { name?: string | null } | null
|
||||
assignee?: { name?: string | null } | null
|
||||
company?: { name?: string | null } | null
|
||||
updatedAt?: number | null
|
||||
}
|
||||
|
||||
function isTicketRecord(value: unknown): value is TicketRecord {
|
||||
if (!value || typeof value !== "object") {
|
||||
return false
|
||||
}
|
||||
const record = value as Record<string, unknown>
|
||||
const hasValidId = typeof record.id === "string" || typeof record.id === "number"
|
||||
const hasValidReference = typeof record.reference === "string" || typeof record.reference === "number"
|
||||
return hasValidId && hasValidReference
|
||||
}
|
||||
|
||||
function normalizeRole(role?: string | null) {
|
||||
return (role ?? "").toLowerCase()
|
||||
}
|
||||
|
|
@ -59,25 +81,15 @@ export async function GET(request: Request) {
|
|||
}
|
||||
|
||||
// Pesquisar pelos tickets visíveis ao viewer (assunto, resumo ou #referência)
|
||||
let tickets: Array<{
|
||||
id: string
|
||||
reference: number
|
||||
subject: string
|
||||
status: string
|
||||
priority: string
|
||||
requester?: { name?: string | null } | null
|
||||
assignee?: { name?: string | null } | null
|
||||
company?: { name?: string | null } | null
|
||||
updatedAt?: number | null
|
||||
}> = []
|
||||
let tickets: TicketRecord[] = []
|
||||
try {
|
||||
const res = (await client.query(api.tickets.list, {
|
||||
const res = await client.query(api.tickets.list, {
|
||||
tenantId,
|
||||
viewerId: viewerId as unknown as Id<"users">,
|
||||
search: query,
|
||||
limit: 40,
|
||||
})) as any[]
|
||||
tickets = Array.isArray(res) ? res : []
|
||||
})
|
||||
tickets = Array.isArray(res) ? res.filter(isTicketRecord) : []
|
||||
} catch (error) {
|
||||
console.error("[mentions] tickets.list failed", error)
|
||||
return NextResponse.json({ items: [] }, { status: 500 })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue