61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server";
|
|
import { getMainCharacterByUserId } from "@/lib/prisma/queries/characters";
|
|
import { getListingById } from "@/lib/prisma/queries/listings";
|
|
import { secureLogger } from "@/lib/secure-logger";
|
|
|
|
/**
|
|
* GET /api/listings/[id]/seller
|
|
* Retorna informações do vendedor (nome do personagem)
|
|
*/
|
|
export async function GET(
|
|
_request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
) {
|
|
try {
|
|
const { id } = await params;
|
|
const listingId = parseInt(id, 10);
|
|
if (Number.isNaN(listingId)) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "ID de anúncio inválido" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const listing = await getListingById(listingId);
|
|
if (!listing) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "Anúncio não encontrado" },
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
// Buscar personagem principal do vendedor no servidor do listing
|
|
const character = await getMainCharacterByUserId(
|
|
listing.seller_id,
|
|
listing.server_name,
|
|
);
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
seller: {
|
|
user_id: listing.seller_id,
|
|
character_name: character?.character_name || null,
|
|
server_name: listing.server_name,
|
|
},
|
|
},
|
|
{ status: 200 },
|
|
);
|
|
} catch (error) {
|
|
secureLogger.error("❌ Erro ao buscar informações do vendedor", {
|
|
error: error instanceof Error ? error.message : "Erro desconhecido",
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{ success: false, error: "Erro ao buscar informações do vendedor" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|