From 3c0f7d49c354f25f29fb054dc367d4b28e82f112 Mon Sep 17 00:00:00 2001 From: Daneryl Date: Thu, 16 Jan 2025 15:28:56 +0100 Subject: [PATCH] fix ts type errors --- ...1-add-collections-for-v2-relationships-migration.spec.ts | 4 ++-- app/api/odm/specs/DB.spec.ts | 4 ++-- app/api/odm/specs/model_multi_tenant.spec.ts | 6 +++--- .../services/pdfsegmentation/specs/PDFSegmentation.spec.ts | 4 ++-- app/api/stats/routes.ts | 2 +- app/api/stats/specs/RetrieveStatsService.spec.ts | 2 +- app/api/tenants/specs/tenantsContext.spec.ts | 2 +- app/api/tenants/specs/tenantsModel.spec.ts | 2 +- app/api/utils/testing_db.ts | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/api/migrations/migrations/141-add-collections-for-v2-relationships-migration/specs/141-add-collections-for-v2-relationships-migration.spec.ts b/app/api/migrations/migrations/141-add-collections-for-v2-relationships-migration/specs/141-add-collections-for-v2-relationships-migration.spec.ts index 4841b8b340b..d26a0c9f7b4 100644 --- a/app/api/migrations/migrations/141-add-collections-for-v2-relationships-migration/specs/141-add-collections-for-v2-relationships-migration.spec.ts +++ b/app/api/migrations/migrations/141-add-collections-for-v2-relationships-migration/specs/141-add-collections-for-v2-relationships-migration.spec.ts @@ -55,12 +55,12 @@ describe('migration add collections for v2 relationships migration', () => { }); it('should set unique index on the migration fields', async () => { - const relCollection = await db.collection('relationshipMigrationFields'); + const relCollection = db.collection('relationshipMigrationFields'); const indexInfo = await relCollection.indexInformation({ full: true }); const uniqueIndex = indexInfo.find( (index: any) => index.name === 'sourceTemplate_1_relationType_1_targetTemplate_1' ); - expect(uniqueIndex.unique).toBe(true); + expect(uniqueIndex?.unique).toBe(true); }); it('should check if a reindex is needed', async () => { diff --git a/app/api/odm/specs/DB.spec.ts b/app/api/odm/specs/DB.spec.ts index 85ac82fd1d3..4ef6881d1fd 100644 --- a/app/api/odm/specs/DB.spec.ts +++ b/app/api/odm/specs/DB.spec.ts @@ -27,8 +27,8 @@ describe('DB', () => { beforeEach(async () => { const uri = config.DBHOST; await DB.connect(`${uri}_DB_spec_ts`); - db1 = DB.getConnection().useDb('db1').db; - db2 = DB.getConnection().useDb('db2').db; + db1 = DB.getConnection().getClient().db('db1'); + db2 = DB.getConnection().getClient().db('db2'); }); afterAll(async () => { diff --git a/app/api/odm/specs/model_multi_tenant.spec.ts b/app/api/odm/specs/model_multi_tenant.spec.ts index c6234e4139d..075128c39b8 100644 --- a/app/api/odm/specs/model_multi_tenant.spec.ts +++ b/app/api/odm/specs/model_multi_tenant.spec.ts @@ -23,9 +23,9 @@ describe('ODM Model multi-tenant', () => { beforeAll(async () => { await testingDB.connect({ defaultTenant: false }); - defaultDB = DB.connectionForDB(config.defaultTenant.dbName).db; - db1 = DB.connectionForDB('db1').db; - db2 = DB.connectionForDB('db2').db; + defaultDB = DB.getConnection().getClient().db(config.defaultTenant.dbName); + db1 = DB.getConnection().getClient().db('db1'); + db2 = DB.getConnection().getClient().db('db2'); }); beforeEach(async () => { diff --git a/app/api/services/pdfsegmentation/specs/PDFSegmentation.spec.ts b/app/api/services/pdfsegmentation/specs/PDFSegmentation.spec.ts index 745b7dd8829..c4183faef89 100644 --- a/app/api/services/pdfsegmentation/specs/PDFSegmentation.spec.ts +++ b/app/api/services/pdfsegmentation/specs/PDFSegmentation.spec.ts @@ -79,8 +79,8 @@ describe('PDFSegmentation', () => { beforeEach(async () => { segmentPdfs = new PDFSegmentation(); - dbOne = DB.connectionForDB(tenantOne.dbName).db; - dbTwo = DB.connectionForDB(tenantTwo.dbName).db; + dbOne = DB.getConnection().getClient().db(tenantOne.dbName); + dbTwo = DB.getConnection().getClient().db(tenantTwo.dbName); tenants.tenants = { tenantOne }; fileA = await fs.readFile(`app/api/services/pdfsegmentation/specs/uploads/${fixturesPdfNameA}`); diff --git a/app/api/stats/routes.ts b/app/api/stats/routes.ts index 4f2f9695ce5..4dd344dd445 100644 --- a/app/api/stats/routes.ts +++ b/app/api/stats/routes.ts @@ -6,7 +6,7 @@ import { DB } from 'api/odm'; export default (app: Application) => { app.get('/api/stats', needsAuthorization(['admin']), async (_req, res, _next) => { - const { db } = DB.connectionForDB(tenants.current().dbName); + const db = DB.getConnection().getClient().db(tenants.current().dbName); const action = new RetrieveStatsService(db); const stats = await action.execute(); diff --git a/app/api/stats/specs/RetrieveStatsService.spec.ts b/app/api/stats/specs/RetrieveStatsService.spec.ts index 8036b8c6b11..ec3f1668942 100644 --- a/app/api/stats/specs/RetrieveStatsService.spec.ts +++ b/app/api/stats/specs/RetrieveStatsService.spec.ts @@ -10,7 +10,7 @@ describe('RetrieveStats', () => { let db: Db; beforeAll(async () => { - db = (await testingDB.connect()).db; + db = (await testingDB.connect()).db as Db; }); beforeEach(async () => { diff --git a/app/api/tenants/specs/tenantsContext.spec.ts b/app/api/tenants/specs/tenantsContext.spec.ts index 5378623a4d5..d72ec0a084a 100644 --- a/app/api/tenants/specs/tenantsContext.spec.ts +++ b/app/api/tenants/specs/tenantsContext.spec.ts @@ -26,7 +26,7 @@ describe('tenantsContext', () => { beforeAll(async () => { await testingDB.connect(); testingEnvironment.setRequestId(); - db = DB.connectionForDB(config.SHARED_DB).db; + db = DB.getConnection().getClient().db(config.SHARED_DB); await db.collection('tenants').deleteMany({}); await db.collection('tenants').insertMany([ diff --git a/app/api/tenants/specs/tenantsModel.spec.ts b/app/api/tenants/specs/tenantsModel.spec.ts index 5d5c057ae78..885055ef693 100644 --- a/app/api/tenants/specs/tenantsModel.spec.ts +++ b/app/api/tenants/specs/tenantsModel.spec.ts @@ -17,7 +17,7 @@ describe('tenantsModel', () => { beforeAll(async () => { await testingDB.connect(); testingEnvironment.setRequestId(); - db = DB.connectionForDB(config.SHARED_DB).db; + db = DB.connectionForDB(config.SHARED_DB).getClient().db(config.SHARED_DB); }); beforeEach(async () => { diff --git a/app/api/utils/testing_db.ts b/app/api/utils/testing_db.ts index cfe6e550209..a518f6a4ca3 100644 --- a/app/api/utils/testing_db.ts +++ b/app/api/utils/testing_db.ts @@ -108,7 +108,7 @@ const testingDB: { .basename(expect.getState().testPath || '') .replace(/[.-]/g, '_')}`.substring(0, 63); await initMongoServer(this.dbName); - mongodb = mongooseConnection.db; + mongodb = mongooseConnection.getClient().db(); this.mongodb = mongodb; if (options.defaultTenant) { @@ -148,7 +148,7 @@ const testingDB: { await this.connect(); let optionalMongo: Db | null = null; if (dbName) { - optionalMongo = DB.connectionForDB(dbName).db; + optionalMongo = DB.connectionForDB(dbName).getClient().db(dbName); } await fixturer.clearAllAndLoad(optionalMongo || mongodb, fixtures); await this.createIndices();