feat: implement market page with QueryProvider and dynamic listings
- wrap root layout with QueryProvider for React Query - replace market UnderConstruction placeholder with MarketClient and real data fetching - implement search, pagination, and sort via search params using getActiveListings - add necessary client components and queries - update dependencies (e.g., prisma, pkg-types)
This commit is contained in:
1 parent
55eebde0ba
commit
ab37b477df
106 files changed
+15261
-301
No files matched your search
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Queries de bids usando Prisma
|
||||
* Migrado de lib/db/queries/bids.ts
|
||||
*/
|
||||
|
||||
import { prisma } from "../app";
|
||||
|
||||
export interface Bid {
|
||||
bid_id: number;
|
||||
listing_id: number;
|
||||
bidder_id: number;
|
||||
bid_amount: number;
|
||||
bid_type: "pix" | "tibia_coins" | "gold_coins" | null;
|
||||
created_at: Date;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
export interface CreateBidData {
|
||||
listing_id: number;
|
||||
bidder_id: number;
|
||||
bid_amount: number;
|
||||
bid_type?: "pix" | "tibia_coins" | "gold_coins";
|
||||
}
|
||||
|
||||
/**
|
||||
* Cria um novo lance
|
||||
*/
|
||||
export async function createBid(data: CreateBidData): Promise<Bid> {
|
||||
return await prisma.bid.create({
|
||||
data: {
|
||||
listing_id: data.listing_id,
|
||||
bidder_id: data.bidder_id,
|
||||
bid_amount: data.bid_amount,
|
||||
bid_type: data.bid_type || null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca lances de um anúncio
|
||||
*/
|
||||
export async function getBidsByListing(
|
||||
listingId: number,
|
||||
activeOnly: boolean = true
|
||||
): Promise<Bid[]> {
|
||||
return await prisma.bid.findMany({
|
||||
where: {
|
||||
listing_id: listingId,
|
||||
...(activeOnly ? { is_active: true } : {}),
|
||||
},
|
||||
orderBy: [
|
||||
{ bid_amount: "desc" },
|
||||
{ created_at: "desc" },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca o maior lance de um anúncio
|
||||
*/
|
||||
export async function getHighestBid(listingId: number): Promise<Bid | null> {
|
||||
return await prisma.bid.findFirst({
|
||||
where: {
|
||||
listing_id: listingId,
|
||||
is_active: true,
|
||||
},
|
||||
orderBy: [
|
||||
{ bid_amount: "desc" },
|
||||
{ created_at: "desc" },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancela um lance (desativa)
|
||||
*/
|
||||
export async function cancelBid(bidId: number): Promise<boolean> {
|
||||
const result = await prisma.bid.updateMany({
|
||||
where: { bid_id: bidId },
|
||||
data: { is_active: false },
|
||||
});
|
||||
|
||||
return result.count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca lance por ID
|
||||
*/
|
||||
export async function getBidById(bidId: number): Promise<Bid | null> {
|
||||
return await prisma.bid.findUnique({
|
||||
where: { bid_id: bidId },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user