refactor: reorganize hooks and add safety checks

fix(api): add validation for listing and seller in bid route
feat(telemetry): add userId to MarketTelemetry
style(globe): add null check for canvas element
chore: add lint:fix script to package.json
This commit is contained in:
Evandro Fonseca Junior committed 2025-11-11 03:20:01 -03:00
1 parent 47c04de6fe
commit 6adc8d96e8
12 files changed
+119 -89

No files matched your search

+27 -7
View File
@@ -61,12 +61,32 @@ export async function POST(
);
}
// Garantir existência do anúncio e vendedor antes de notificar
const listing = result.listing;
if (!listing) {
return NextResponse.json(
{ success: false, error: "Anúncio não encontrado após registrar o lance" },
{ status: 404 },
);
}
if (typeof listing.seller_id !== "number") {
secureLogger.warn("SellerId inválido ao criar notificação de lance", {
listingId,
sellerId: listing.seller_id,
});
return NextResponse.json(
{ success: false, error: "Vendedor inválido para notificação" },
{ status: 500 },
);
}
// Criar notificação para o vendedor
await createNotification({
user_id: result.listing?.seller_id,
user_id: listing.seller_id,
notification_type: "bid",
title: "Novo lance!",
message: `Novo lance de R$ ${amount.toFixed(2)} no item "${result.listing?.item_name}"`,
message: `Novo lance de R$ ${amount.toFixed(2)} no item "${listing.item_name}"`,
related_id: listingId,
send_whatsapp: false,
});
@@ -77,7 +97,7 @@ export async function POST(
user_id: result.previousBidderId,
notification_type: "bid",
title: "Lance superado",
message: `Seu lance foi superado no item "${result.listing?.item_name}"`,
message: `Seu lance foi superado no item "${listing.item_name}"`,
related_id: listingId,
send_whatsapp: false,
});
@@ -92,11 +112,11 @@ export async function POST(
metadata: {
bid_amount: amount,
payment_method: payment_method,
previous_bid: result.listing?.current_bid_amount
? Number(result.listing?.current_bid_amount)
previous_bid: listing.current_bid_amount
? Number(listing.current_bid_amount)
: null,
min_increment: result.listing?.min_bid_increment
? Number(result.listing?.min_bid_increment)
min_increment: listing.min_bid_increment
? Number(listing.min_bid_increment)
: null,
},
});