Enhance the media auction system with improved bid validation and data handling

Update the MediaOutletAuction component to correctly parse currency values for bid placement and display, and modify the DatabaseStorage to include a new method for fetching active auctions by media outlet ID.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 069d4324-6c40-4355-955e-c714a50de1ea
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3df548ff-50ae-432f-9be4-25d34eccc983/069d4324-6c40-4355-955e-c714a50de1ea/jvFIdY3
This commit is contained in:
kimjaehyeon0101
2025-09-29 18:59:03 +00:00
parent b2c5d1ab38
commit 020f212281
2 changed files with 16 additions and 11 deletions

View File

@ -32,10 +32,7 @@ export default function MediaOutletAuction() {
const placeBidMutation = useMutation({
mutationFn: async (bidData: { amount: number; qualityScore?: number }) => {
return apiRequest(`/api/media-outlets/${params?.slug}/auction/bids`, {
method: "POST",
body: JSON.stringify(bidData),
});
return apiRequest("POST", `/api/media-outlets/${params?.slug}/auction/bids`, bidData);
},
onSuccess: () => {
toast({
@ -75,7 +72,7 @@ export default function MediaOutletAuction() {
return;
}
if (auction && amount <= auction.currentBid) {
if (auction && auction.currentBid && amount <= parseFloat(auction.currentBid)) {
toast({
title: "입찰 금액 부족",
description: `현재 최고 입찰가(${auction.currentBid}원)보다 높은 금액을 입력해주세요.`,
@ -102,7 +99,7 @@ export default function MediaOutletAuction() {
}).format(amount);
};
const formatTimeRemaining = (endDate: string) => {
const formatTimeRemaining = (endDate: Date | string) => {
const end = new Date(endDate);
const now = new Date();
const diff = end.getTime() - now.getTime();
@ -264,7 +261,7 @@ export default function MediaOutletAuction() {
<span className="font-medium"> </span>
</div>
<span className="text-2xl font-bold text-green-600">
{formatCurrency(auction.currentBid)}
{formatCurrency(parseFloat(auction.currentBid || "0"))}
</span>
</div>
@ -278,14 +275,14 @@ export default function MediaOutletAuction() {
</span>
</div>
{auction.highestBidder && (
{auction.highestBidderId && (
<div className="flex items-center justify-between p-4 bg-muted rounded-lg">
<div className="flex items-center space-x-2">
<User className="h-4 w-4 text-blue-600" />
<span className="font-medium"> </span>
</div>
<span className="text-lg font-bold text-blue-600">
{auction.highestBidder.slice(0, 3)}***
{auction.highestBidderId.slice(0, 3)}***
</span>
</div>
)}
@ -328,8 +325,8 @@ export default function MediaOutletAuction() {
type="number"
value={bidAmount}
onChange={(e) => setBidAmount(e.target.value)}
placeholder={`${auction.currentBid + 1000} 이상`}
min={auction.currentBid + 1}
placeholder={`${parseFloat(auction.currentBid || "0") + 1000} 이상`}
min={parseFloat(auction.currentBid || "0") + 1}
data-testid="input-bid-amount"
/>
</div>

View File

@ -53,6 +53,7 @@ export interface IStorage {
// Auction operations
getActiveAuctions(): Promise<Auction[]>;
getAuctionById(id: string): Promise<Auction | undefined>;
getAuctionByMediaOutlet(mediaOutletId: string): Promise<Auction | undefined>;
createAuction(auction: InsertAuction): Promise<Auction>;
placeBid(bid: InsertBid): Promise<Bid>;
@ -191,6 +192,13 @@ export class DatabaseStorage implements IStorage {
return auction;
}
async getAuctionByMediaOutlet(mediaOutletId: string): Promise<Auction | undefined> {
const [auction] = await db.select().from(auctions).where(
and(eq(auctions.mediaOutletId, mediaOutletId), eq(auctions.isActive, true))
);
return auction;
}
async createAuction(auction: InsertAuction): Promise<Auction> {
const [newAuction] = await db.insert(auctions).values(auction).returning();
return newAuction;