Skip to content

Commit

Permalink
fix ts type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Jan 16, 2025
1 parent 2c62fd9 commit c968899
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions app/api/odm/specs/DB.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion app/api/odm/specs/EntitiesUpdateLogHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('EntitiesUpdateLogHelper', () => {
fixtureFactory.id('files-thumbnail1'),
fixtureFactory.id('files-document1'),
].forEach(id => {
const original = fixtures.updatelogs.find(log => log._id.toString() === id.toString());
const original = fixtures.updatelogs.find(log => log._id!.toString() === id.toString());
const current = logs.find(log => log._id.toString() === id.toString());

expect(current!.timestamp).toBeGreaterThan(original!.timestamp! as number);
Expand Down
6 changes: 3 additions & 3 deletions app/api/odm/specs/model_multi_tenant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion app/api/stats/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion app/api/stats/specs/RetrieveStatsService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
3 changes: 1 addition & 2 deletions app/api/sync/syncConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DataType } from 'api/odm';
import { SyncConfig } from 'api/sync/syncWorker';
import templatesModel from 'api/templates/templatesModel';
import { model as updateLog, UpdateLog } from 'api/updatelogs';
Expand Down Expand Up @@ -163,7 +162,7 @@ export const createSyncConfig = async (
return changes;
},

async shouldSync(change: DataType<UpdateLog>) {
async shouldSync(change: UpdateLog) {
if (change.deleted) return { skip: true };
const templatesConfig = this.config.templates || {};

Expand Down
4 changes: 2 additions & 2 deletions app/api/sync/synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const uploadFile = async (
};

export const synchronizer = {
async syncDelete(change: DataType<UpdateLog>, url: string, cookie: string) {
async syncDelete(change: UpdateLog, url: string, cookie: string) {
await this.syncData(
{
url,
Expand All @@ -40,7 +40,7 @@ export const synchronizer = {
change,
data,
cookie,
}: { url: string; change: DataType<UpdateLog>; data: DataType<any>; cookie: string },
}: { url: string; change: UpdateLog; data: DataType<any>; cookie: string },
action: keyof typeof request
) {
await request[action](
Expand Down
2 changes: 1 addition & 1 deletion app/api/tenants/specs/tenantsContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion app/api/tenants/specs/tenantsModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 2 additions & 0 deletions app/api/updatelogs/updatelogsModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mongoose from 'mongoose';
import { MultiTenantMongooseModel } from 'api/odm/MultiTenantMongooseModel';
import { ObjectIdSchema } from 'shared/types/commonTypes';
import { ObjectId } from 'mongodb';

const updateLogSchema = new mongoose.Schema({
timestamp: { type: Number, index: true },
Expand All @@ -11,6 +12,7 @@ const updateLogSchema = new mongoose.Schema({

updateLogSchema.index({ namespace: 1, timestamp: 1 });
export interface UpdateLog extends mongoose.Document {
_id: ObjectId;
timestamp: number;
namespace: string;
mongoId: ObjectIdSchema;
Expand Down
4 changes: 2 additions & 2 deletions app/api/utils/testing_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c968899

Please sign in to comment.