Merge pull request 'Enable logging in mongodb tables' (#6) from development into main

Reviewed-on: Galactic/galactic-bot#6
This commit is contained in:
Erik 2024-03-26 15:20:28 +01:00
commit 4982e7a0c2
3 changed files with 18 additions and 2 deletions

View File

@ -155,14 +155,26 @@ class MongodbTable<Default extends Document = Document> extends Table
if ('_id' in query && !(query._id instanceof ObjectId)) if ('_id' in query && !(query._id instanceof ObjectId))
{ {
if (typeof query._id === 'string' && query._id.length === 24) if (typeof query._id === 'string' && query._id.length === 24)
query._id = new ObjectId(query._id); {
try
{
const _id = new ObjectId(query._id);
query._id = _id;
}
catch
{
this.logger.warn(`Invalid ObjectId given ${query._id}`);
}
}
else if (query._id instanceof Array) else if (query._id instanceof Array)
{
query._id = { query._id = {
$in: Object.values(query._id).map((id) => $in: Object.values(query._id).map((id) =>
{ {
return new ObjectId(id); return new ObjectId(id);
}) })
}; };
}
} }
else if (query instanceof Array) else if (query instanceof Array)
{ {

View File

@ -138,7 +138,7 @@ abstract class Provider implements Initialisable
return this.#config; return this.#config;
} }
protected get logger () get logger ()
{ {
return this.#logger; return this.#logger;
} }

View File

@ -11,6 +11,10 @@ class Table
this.#provider = provider; this.#provider = provider;
} }
get logger ()
{
return this.#provider.logger;
}
get name () get name ()
{ {
return this.#name; return this.#name;