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:
Evandro Fonseca Junior committed 2025-11-05 01:58:03 -03:00
1 parent 55eebde0ba
commit ab37b477df
106 files changed
+15261 -301

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
/**
* Queries de servidores usando Prisma
* Migrado de lib/db/queries/servers.ts
*/
import { prisma } from "../app";
export interface Server {
server_id: number;
server_name: string;
server_type: "pvp" | "no-pvp" | "retro-pvp" | "hardcore-pvp" | null;
location: "NA" | "SA" | "EU" | "OC" | "BR" | null;
is_active: boolean;
total_listings: number;
total_users: number;
total_subscribers: number;
total_transactions: number;
total_volume: number;
average_listing_price: number;
last_activity_at: Date | null;
created_at: Date;
updated_at: Date;
}
export interface ServerStats {
total_listings?: number;
total_users?: number;
total_subscribers?: number;
total_transactions?: number;
total_volume?: number;
average_listing_price?: number;
last_activity_at?: Date;
}
/**
* Lista todos os servidores
*/
export async function getAllServers(): Promise<Server[]> {
return await prisma.server.findMany({
orderBy: { server_name: "asc" },
});
}
/**
* Lista apenas servidores ativos
*/
export async function getActiveServers(): Promise<Server[]> {
return await prisma.server.findMany({
where: { is_active: true },
orderBy: { server_name: "asc" },
});
}
/**
* Busca servidor por nome
*/
export async function getServerByName(serverName: string): Promise<Server | null> {
return await prisma.server.findUnique({
where: { server_name: serverName },
});
}
/**
* Busca servidor por ID
*/
export async function getServerById(serverId: number): Promise<Server | null> {
return await prisma.server.findUnique({
where: { server_id: serverId },
});
}
/**
* Verifica se servidor existe e está ativo
*/
export async function isServerActive(serverName: string): Promise<boolean> {
const count = await prisma.server.count({
where: {
server_name: serverName,
is_active: true,
},
});
return count > 0;
}
/**
* Incrementa estatísticas do servidor
*/
export async function incrementServerStats(
serverName: string,
stats: Partial<{
total_listings: number;
total_users: number;
total_subscribers: number;
total_transactions: number;
total_volume: number;
}>
): Promise<void> {
const updateData: any = {
last_activity_at: new Date(),
};
if (stats.total_listings !== undefined) {
updateData.total_listings = { increment: stats.total_listings };
}
if (stats.total_users !== undefined) {
updateData.total_users = { increment: stats.total_users };
}
if (stats.total_subscribers !== undefined) {
updateData.total_subscribers = { increment: stats.total_subscribers };
}
if (stats.total_transactions !== undefined) {
updateData.total_transactions = { increment: stats.total_transactions };
}
if (stats.total_volume !== undefined) {
updateData.total_volume = { increment: stats.total_volume };
}
await prisma.server.update({
where: { server_name: serverName },
data: updateData,
});
}
/**
* Atualiza estatísticas completas do servidor
*/
export async function updateServerStats(
serverName: string,
stats: ServerStats
): Promise<void> {
const updateData: any = {};
if (stats.total_listings !== undefined) updateData.total_listings = stats.total_listings;
if (stats.total_users !== undefined) updateData.total_users = stats.total_users;
if (stats.total_subscribers !== undefined) updateData.total_subscribers = stats.total_subscribers;
if (stats.total_transactions !== undefined) updateData.total_transactions = stats.total_transactions;
if (stats.total_volume !== undefined) updateData.total_volume = stats.total_volume;
if (stats.average_listing_price !== undefined) updateData.average_listing_price = stats.average_listing_price;
if (stats.last_activity_at !== undefined) updateData.last_activity_at = stats.last_activity_at;
if (Object.keys(updateData).length === 0) {
return;
}
await prisma.server.update({
where: { server_name: serverName },
data: updateData,
});
}
/**
* Incrementa total_users de múltiplos servidores
*/
export async function incrementUsersForServers(serverNames: string[]): Promise<void> {
if (serverNames.length === 0) {
return;
}
await prisma.server.updateMany({
where: {
server_name: { in: serverNames },
},
data: {
total_users: { increment: 1 },
last_activity_at: new Date(),
},
});
}