18 lines
658 B
TypeScript
18 lines
658 B
TypeScript
import { MongoClient } from 'mongodb'
|
|
|
|
async function connectToDatabase() {
|
|
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
|
const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`)
|
|
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}
|