From 21c70e6ce931c6da88bbe9ff863cc06115863fb5 Mon Sep 17 00:00:00 2001 From: Konstantinos Kopanidis Date: Fri, 26 Jan 2024 15:13:56 +0200 Subject: [PATCH] refactor(database): slightly reorder create view code to reduce rc --- .../src/adapters/mongoose-adapter/index.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/database/src/adapters/mongoose-adapter/index.ts b/modules/database/src/adapters/mongoose-adapter/index.ts index 35f24228d..2b9ba301e 100644 --- a/modules/database/src/adapters/mongoose-adapter/index.ts +++ b/modules/database/src/adapters/mongoose-adapter/index.ts @@ -93,25 +93,25 @@ export class MongooseAdapter extends DatabaseAdapter { this, true, ); + this.views[viewName] = viewModel; await viewModel.model.createCollection({ viewOn: model.originalSchema.collectionName, pipeline: EJSON.parse(query.mongoQuery), }); - this.views[viewName] = viewModel; - const foundView = await this.models['Views'].findOne({ name: viewName }); - if (isNil(foundView)) { - await this.models['Views'].create({ - name: viewName, - originalSchema: modelName, - joinedSchemas: [...new Set(joinedSchemas.concat(modelName))], - query, - }); - } } catch (e: any) { if (!e.message.includes('Cannot overwrite')) { throw e; } } + const foundView = await this.models['Views'].findOne({ name: viewName }); + if (isNil(foundView)) { + await this.models['Views'].create({ + name: viewName, + originalSchema: modelName, + joinedSchemas: [...new Set(joinedSchemas.concat(modelName))], + query, + }); + } } async guaranteeView(viewName: string) {