import{logger as e}from"../../logger/index.mjs";import{DictionaryModel as t}from"../../models/dictionary.model.mjs";import{OrganizationModel as n}from"../../models/organization.model.mjs";import{ProjectModel as r}from"../../models/project.model.mjs";import{TagModel as i}from"../../models/tag.model.mjs";import{DiscussionModel as a}from"../../models/discussion.model.mjs";import{OAuth2AccessTokenModel as o}from"../../models/oAuth2.model.mjs";import{UserModel as s}from"../../models/user.model.mjs";import{connect as c}from"mongoose";let l=null;const u=async()=>{try{let u=await c(`mongodb+srv://${process.env.DB_ID}:${process.env.DB_MDP}@${process.env.DB_CLUSTER}/?retryWrites=true&w=majority&appName=Cluster0`);return e.info(`MongoDB connected`),await r.syncIndexes(),await a.syncIndexes(),await s.createIndexes(),await o.createIndexes(),await i.createIndexes(),await t.createIndexes(),await n.createIndexes(),l=u.connection.getClient(),l}catch(t){let n=`MongoDB connection error - ${t.message}`;throw e.error(n),Error(n)}},d=()=>{if(!l)throw Error(`Database not connected. Call connectDB() first.`);return l};export{u as connectDB,d as getDBClient};
//# sourceMappingURL=connectDB.mjs.map