feat(market): add Minha Intenções tab with panel, hook, and badge
- Introduced "Minhas Intenções" tab visible only to logged-in users. - Integrated MyPurchaseIntentionsPanel and useMyPurchaseIntentions hook. - Added tab badge showing count of pending intentions. - Extended session API to include user’s main character for downstream features.
This commit is contained in:
1 parent
f35fee944d
commit
7f42def478
55 files changed
+4906
-95
No files matched your search
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Conexão MongoDB usando Mongoose
|
||||
* Singleton pattern para reutilizar conexão
|
||||
*/
|
||||
|
||||
import mongoose from "mongoose";
|
||||
|
||||
function getMongoUrl(): string {
|
||||
const url = process.env.MONGO_URL;
|
||||
if (!url) {
|
||||
throw new Error("MONGO_URL não está definida nas variáveis de ambiente");
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
interface MongooseCache {
|
||||
conn: typeof mongoose | null;
|
||||
promise: Promise<typeof mongoose> | null;
|
||||
}
|
||||
|
||||
// Cache global para Next.js (evita múltiplas conexões em hot reload)
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var mongoose: MongooseCache | undefined;
|
||||
}
|
||||
|
||||
let cached: MongooseCache = global.mongoose || { conn: null, promise: null };
|
||||
|
||||
if (!global.mongoose) {
|
||||
global.mongoose = cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conecta ao MongoDB ou retorna conexão existente
|
||||
*/
|
||||
export async function connectMongoDB(): Promise<typeof mongoose> {
|
||||
if (cached.conn) {
|
||||
return cached.conn;
|
||||
}
|
||||
|
||||
if (!cached.promise) {
|
||||
const opts = {
|
||||
bufferCommands: false,
|
||||
maxPoolSize: 10,
|
||||
serverSelectionTimeoutMS: 5000,
|
||||
socketTimeoutMS: 45000,
|
||||
};
|
||||
|
||||
cached.promise = mongoose
|
||||
.connect(getMongoUrl(), opts)
|
||||
.then((mongoose) => {
|
||||
// Conexão MongoDB estabelecida (log desabilitado)
|
||||
return mongoose;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("❌ Erro ao conectar MongoDB:", error);
|
||||
cached.promise = null;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
cached.conn = await cached.promise;
|
||||
} catch (e) {
|
||||
cached.promise = null;
|
||||
throw e;
|
||||
}
|
||||
|
||||
return cached.conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desconecta do MongoDB (útil para testes)
|
||||
*/
|
||||
export async function disconnectMongoDB(): Promise<void> {
|
||||
if (cached.conn) {
|
||||
await mongoose.disconnect();
|
||||
cached.conn = null;
|
||||
cached.promise = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user