From c1c47865792a4f29316fbf8c24b39cc02cd91ffd Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 26 Mar 2024 16:20:09 +0200 Subject: [PATCH] Enable logging in mongodb tables --- src/client/storage/interfaces/MongodbTable.ts | 14 +++++++++++++- src/client/storage/interfaces/Provider.ts | 2 +- src/client/storage/interfaces/Table.ts | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/client/storage/interfaces/MongodbTable.ts b/src/client/storage/interfaces/MongodbTable.ts index 25a03eb..f0790f5 100644 --- a/src/client/storage/interfaces/MongodbTable.ts +++ b/src/client/storage/interfaces/MongodbTable.ts @@ -155,14 +155,26 @@ class MongodbTable extends Table if ('_id' in query && !(query._id instanceof ObjectId)) { 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) + { query._id = { $in: Object.values(query._id).map((id) => { return new ObjectId(id); }) }; + } } else if (query instanceof Array) { diff --git a/src/client/storage/interfaces/Provider.ts b/src/client/storage/interfaces/Provider.ts index 8557093..d30b388 100644 --- a/src/client/storage/interfaces/Provider.ts +++ b/src/client/storage/interfaces/Provider.ts @@ -138,7 +138,7 @@ abstract class Provider implements Initialisable return this.#config; } - protected get logger () + get logger () { return this.#logger; } diff --git a/src/client/storage/interfaces/Table.ts b/src/client/storage/interfaces/Table.ts index 6ad323b..7b4fecd 100644 --- a/src/client/storage/interfaces/Table.ts +++ b/src/client/storage/interfaces/Table.ts @@ -11,6 +11,10 @@ class Table this.#provider = provider; } + get logger () + { + return this.#provider.logger; + } get name () { return this.#name;