26 lines
819 B
TypeScript
26 lines
819 B
TypeScript
import { MongoClient } from 'mongodb'
|
|
|
|
async function connectToDatabase() {
|
|
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
|
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
|
if (
|
|
process.env.MONGO_URI != undefined &&
|
|
process.env.MONGO_URI != null &&
|
|
process.env.MONGO_URI != ''
|
|
) {
|
|
uri = process.env.MONGO_URI
|
|
}
|
|
const client = new MongoClient(uri)
|
|
await client.connect()
|
|
return client
|
|
}
|
|
|
|
async function fetchLatestPatch(client: MongoClient) {
|
|
const database = client.db('patches')
|
|
const patches = database.collection('patches')
|
|
const latestPatch = await patches.find().limit(1).sort({ date: -1 }).next()
|
|
return latestPatch!.patch as string
|
|
}
|
|
|
|
export { connectToDatabase, fetchLatestPatch }
|