follow no-var eslint

This commit is contained in:
Joseph J Helfenbein
2025-01-25 06:18:58 -05:00
parent 1f4c828b30
commit 7d79f06ca8

View File

@@ -12,17 +12,14 @@ interface Cached {
} }
declare global { declare global {
var mongoose: Cached; var mongoose: Cached | undefined;
} }
let cached: Cached = global.mongoose || { conn: null, promise: null };
export async function connectDB(): Promise<Mongoose> { export async function connectDB(): Promise<Mongoose> {
const DATABASE_URL = process.env.MONGO_URI as string; const DATABASE_URL = process.env.MONGO_URI as string;
let cached: Cached = global.mongoose;
if (!cached) {
cached = global.mongoose = { conn: null, promise: null };
}
if (cached.conn) { if (cached.conn) {
return cached.conn; return cached.conn;
} }
@@ -42,5 +39,6 @@ export async function connectDB(): Promise<Mongoose> {
} }
cached.conn = await cached.promise; cached.conn = await cached.promise;
global.mongoose = cached;
return cached.conn; return cached.conn;
} }