exodus-framework 2.0.700 → 2.0.701

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,7 +55,7 @@ class AccessMiddleware extends _controller.default {
55
55
  envUuid = account.envUuid;
56
56
  }
57
57
  req.tenant = {
58
- id: envUuid || `root@${_app.Core.settings.getDatabase().service.database}`
58
+ id: envUuid || _app.Core.settings.getDatabase().service.database
59
59
  };
60
60
  next();
61
61
  };
@@ -1,12 +1,14 @@
1
1
  import { Model, ModelStatic, Sequelize } from 'sequelize';
2
2
  import Service from '../app/service';
3
3
  import { IService } from '../contracts/service';
4
+ import { EnvConnection } from '../models';
4
5
  declare class SequelizeService extends Service implements IService {
5
6
  serviceDB: Sequelize;
6
7
  masterDB: Sequelize;
7
8
  models: ModelStatic<any>[];
8
9
  connections: Map<string, Sequelize>;
9
10
  initializedModels: Map<string, typeof Model<any, any>>;
11
+ relations: Map<string, EnvConnection>;
10
12
  constructor();
11
13
  init(): Promise<void>;
12
14
  connectMainDatabase(): Promise<unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"sequelize.d.ts","sourceRoot":"","sources":["../../src/services/sequelize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAchD,cAAM,gBAAiB,SAAQ,OAAQ,YAAW,QAAQ;IACxD,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAA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AC,MAAM,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACvD,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;;IAMhC,IAAI;IAOJ,mBAAmB;IAgCzB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,SAAI;IAerC,mBAAmB;IAGb,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IA6C9C,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAwC9C,KAAK,CAAC,QAAQ,EAAE,MAAM;IAwCtB,MAAM,CAAC,QAAQ,EAAE,MAAM;IA4C7B,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE;IAInC,QAAQ,CAAC,CAAC,SAAS,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAC7C,KAAK,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,SAAS,KAAK,CAAC,CAAA;KAAE,EAC5E,QAAQ,EAAE,MAAM;IAwBlB,uBAAuB,CAAC,MAAM,EAAE,MAAM;;;;CAMvC;AAED,eAAe,gBAAgB,CAAC"}
@@ -26,6 +26,7 @@ class SequelizeService extends _service.default {
26
26
  models;
27
27
  connections;
28
28
  initializedModels;
29
+ relations;
29
30
 
30
31
  //# Initialization
31
32
  constructor() {
@@ -152,19 +153,41 @@ class SequelizeService extends _service.default {
152
153
  });
153
154
  }
154
155
  async getDB(tenantId) {
155
- const {
156
- con_uuid,
157
- envToken
158
- } = this.parseDataInfoByTenantId(tenantId);
159
- if (con_uuid == _app.Core.settings.getDatabase().service.database) {
156
+ let relation;
157
+ if (tenantId == _app.Core.settings.getDatabase().service.database) {
160
158
  return _database.serviceDB;
161
- } else if (con_uuid == _app.Core.settings.getDatabase().master.database) {
159
+ } else if (tenantId == _app.Core.settings.getDatabase().master.database) {
162
160
  return _database.masterDB;
163
161
  }
164
- const dbName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
165
- const queryId = `${con_uuid}@${dbName}`;
162
+ if (this.relations.get(tenantId)) {
163
+ relation = this.relations.get(tenantId);
164
+ } else {
165
+ relation = await _models.EnvConnection.findOne({
166
+ where: {
167
+ envUuid: tenantId
168
+ }
169
+ });
170
+ if (!relation) {
171
+ new _error.ApplicationException('Não foi possível encontrar a relação env-db: tenantId=' + tenantId);
172
+ return false;
173
+ }
174
+ this.relations.set(tenantId, relation);
175
+ }
176
+ const dbName = `${_app.Core.settings.getDatabase().service.database}_${relation.envToken}`; //nomeclatura padrão do banco de dados do serviço
177
+ const queryId = `${relation.connUuid}@${dbName}`;
166
178
  return this.connections.get(queryId) || (await this.initDB(tenantId));
167
179
  }
180
+ /* async getDB2(tenantId: string) {
181
+ const { con_uuid, envToken } = this.parseDataInfoByTenantId(tenantId);
182
+ if (con_uuid == Core.settings.getDatabase().service.database) {
183
+ return serviceDB;
184
+ } else if (con_uuid == Core.settings.getDatabase().master.database) {
185
+ return masterDB;
186
+ }
187
+ const dbName = `${Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
188
+ const queryId = `${con_uuid}@${dbName}`;
189
+ return this.connections.get(queryId) || (await this.initDB(tenantId));
190
+ } */
168
191
  async initDB(tenantId) {
169
192
  const {
170
193
  con_uuid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.700",
3
+ "version": "2.0.701",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",