This commit is contained in:
Sebastian Seedorf
2022-08-18 09:20:00 +02:00
parent 92b762bbd2
commit de95f57b18
60 changed files with 3450 additions and 994 deletions

View File

@@ -1,23 +1,21 @@
import {Collection, Db, MongoClient} from 'mongodb'
import { Collection, Db, MongoClient } from 'mongodb'
import getConfig from 'next/config'
import {Resolvable} from "../utils/Resolvable";
import {GroupData, InsertMeta} from "./groups";
import { Resolvable } from '../utils/Resolvable'
import { GroupData, InsertMeta } from './groups'
import { logger } from '../utils/logger'
const { serverRuntimeConfig: {
MONGO_URL,
MONGO_USER,
MONGO_PASS,
MONGO_DB
} } = getConfig()
const {
serverRuntimeConfig: { MONGO_URL, MONGO_USER, MONGO_PASS, MONGO_DB }
} = getConfig()
async function getDatabase() {
const url = `mongodb://${MONGO_USER ? `${MONGO_USER}:${MONGO_PASS ?? ''}@` : ''}${MONGO_URL}`;
const client = new MongoClient(url);
await client.connect();
console.log('Connected successfully to server')
return client.db(MONGO_DB) as unknown as (Omit<Db, 'collection'> & {
collection : (_: 'setups') => Collection<InsertMeta<GroupData>>
})
const url = `mongodb://${MONGO_USER ? `${MONGO_USER}:${MONGO_PASS ?? ''}@` : ''}${MONGO_URL}`
const client = new MongoClient(url)
await client.connect()
logger.info('Connected successfully to server')
return client.db(MONGO_DB) as unknown as Omit<Db, 'collection'> & {
collection: (_: 'setups') => Collection<InsertMeta<GroupData>>
}
}
export const database = new Resolvable(getDatabase)