feat: enhance tickets portal and admin flows

This commit is contained in:
Esdras Renan 2025-10-07 02:26:09 -03:00
parent 9cdd8763b4
commit c15f0a5b09
67 changed files with 1101 additions and 338 deletions

View file

@ -1,8 +1,8 @@
import { NextResponse } from "next/server"
import { Prisma } from "@prisma/client"
import { ConvexHttpClient } from "convex/browser"
// @ts-expect-error Convex runtime API lacks generated types at build time in Next routes
import { api } from "@/convex/_generated/api"
import { assertAdminSession } from "@/lib/auth-server"
import { env } from "@/lib/env"
@ -36,7 +36,8 @@ async function syncInvite(invite: NormalizedInvite) {
})
}
export async function PATCH(request: Request, { params }: { params: { id: string } }) {
export async function PATCH(request: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params
const session = await assertAdminSession()
if (!session) {
return NextResponse.json({ error: "Não autorizado" }, { status: 401 })
@ -46,7 +47,7 @@ export async function PATCH(request: Request, { params }: { params: { id: string
const reason = typeof body?.reason === "string" && body.reason.trim() ? body.reason.trim() : null
const invite = await prisma.authInvite.findUnique({
where: { id: params.id },
where: { id },
include: { events: { orderBy: { createdAt: "asc" } } },
})
@ -81,7 +82,7 @@ export async function PATCH(request: Request, { params }: { params: { id: string
data: {
inviteId: invite.id,
type: "revoked",
payload: reason ? { reason } : null,
payload: reason ? { reason } : Prisma.JsonNull,
actorId: session.user.id ?? null,
},
})

View file

@ -1,9 +1,9 @@
import { NextResponse } from "next/server"
import { randomBytes } from "crypto"
import { Prisma } from "@prisma/client"
import { ConvexHttpClient } from "convex/browser"
// @ts-expect-error Convex runtime API lacks generated types at build time in Next routes
import { api } from "@/convex/_generated/api"
import { assertAdminSession } from "@/lib/auth-server"
import { DEFAULT_TENANT_ID } from "@/lib/constants"
@ -14,6 +14,13 @@ import { computeInviteStatus, normalizeInvite, type InviteWithEvents, type Norma
const DEFAULT_EXPIRATION_DAYS = 7
function toJsonPayload(payload: unknown): Prisma.InputJsonValue | Prisma.NullableJsonNullValueInput {
if (payload === null || payload === undefined) {
return Prisma.JsonNull
}
return payload as Prisma.InputJsonValue
}
function normalizeRole(input: string | null | undefined): RoleOption {
const role = (input ?? "agent").toLowerCase() as RoleOption
return (ROLE_OPTIONS as readonly string[]).includes(role) ? role : "agent"
@ -52,7 +59,7 @@ async function appendEvent(inviteId: string, type: string, actorId: string | nul
data: {
inviteId,
type,
payload,
payload: toJsonPayload(payload),
actorId,
},
})

View file

@ -4,7 +4,6 @@ import { randomBytes } from "crypto"
import { hashPassword } from "better-auth/crypto"
import { ConvexHttpClient } from "convex/browser"
// @ts-expect-error Convex generated API lacks type declarations in Next API routes
import { api } from "@/convex/_generated/api"
import { prisma } from "@/lib/prisma"
import { DEFAULT_TENANT_ID } from "@/lib/constants"