swagger documentation for Api

This commit is contained in:
2025-01-30 12:44:04 +05:30
parent 5984f445f7
commit 465f713624
45 changed files with 5201 additions and 2308 deletions

View File

@@ -1,47 +1,47 @@
import mongoose, { Schema, Connection, Model } from "mongoose";
interface ConnectionCache {
[key: string]: Connection;
}
const connections: ConnectionCache = {};
const MainModel = <T>(
db: string,
modelName: string,
schema: Schema<T>,
collectionName: string
): Model<T> => {
const db1_url = `${process.env.MONGO_URI}${db}`;
// Check if the connection already exists
if (connections[db]) {
return connections[db].model<T>(modelName, schema, collectionName);
}
try {
const db1 = mongoose.createConnection(db1_url, {
maxPoolSize: 50,
});
// Cache the connection
connections[db] = db1;
// Log connection success or handle errors
db1.on("connected", () => {
console.log(`Connected to MongoDB database: ${db}`);
});
db1.on("error", (err) => {
console.error(`MongoDB connection error for database ${db}:`, err.message);
});
return db1.model<T>(modelName, schema, collectionName);
} catch (error) {
console.error("Database connection error:", (error as Error).message);
throw error;
}
};
export default MainModel;
import mongoose, { Schema, Connection, Model } from "mongoose";
interface ConnectionCache {
[key: string]: Connection;
}
const connections: ConnectionCache = {};
const MainModel = <T>(
db: string,
modelName: string,
schema: Schema<T>,
collectionName: string
): Model<T> => {
const db1_url = `${process.env.MONGO_URI}${db}`;
// Check if the connection already exists
if (connections[db]) {
return connections[db].model<T>(modelName, schema, collectionName);
}
try {
const db1 = mongoose.createConnection(db1_url, {
maxPoolSize: 50,
});
// Cache the connection
connections[db] = db1;
// Log connection success or handle errors
db1.on("connected", () => {
console.log(`Connected to MongoDB database: ${db}`);
});
db1.on("error", (err) => {
console.error(`MongoDB connection error for database ${db}:`, err.message);
});
return db1.model<T>(modelName, schema, collectionName);
} catch (error) {
console.error("Database connection error:", (error as Error).message);
throw error;
}
};
export default MainModel;