Convert to Typescript

This commit is contained in:
2024-09-16 09:56:40 +00:00
parent a89150fc2f
commit 6a59118f4a
42 changed files with 2916 additions and 785 deletions

View File

@@ -1,37 +0,0 @@
import { MongoClient } from 'mongodb';
if (!process.env.MONGODB_URI) {
throw new Error('MONGODB_URI is not set in the environment variables.');
}
const client = new MongoClient(process.env.MONGODB_URI);
await client.connect();
const database = client.db('butler_db');
const collection = database.collection('GameFeatures');
export async function listGameNames() {
return collection.find({}, { projection: { game: 1 } }).toArray();
}
export async function getGame(game) {
return collection.findOne({ game });
}
export async function setGame(game, key, value) {
// If game is not found, create a new document with game field set to game, and key field set to value.
// Overwrite the value of the key field if it already exists.
return collection.updateOne(
{ game },
{ $set: { game, [key]: value } },
{ upsert: true }
);
}
export async function deleteGame(game) {
return collection.deleteOne({ game });
}
export async function deleteField(game, key) {
return collection.updateOne({ game }, { $unset: { [key]: '' } });
}