@friggframework/core 2.0.0--canary.396.6afd30a.0 → 2.0.0--canary.396.5afebde.0

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.
@@ -10,7 +10,16 @@ class IntegrationRepository {
10
10
  }
11
11
 
12
12
  async findIntegrationById(id) {
13
- return IntegrationModel.findById(id).populate('entities');
13
+ const integrationRecord = await IntegrationModel.findById(id, '', { lean: true }).populate('entities');
14
+ return {
15
+ id: integrationRecord._id,
16
+ entitiesIds: integrationRecord.entities.map(e => e._id),
17
+ userId: integrationRecord.user,
18
+ config: integrationRecord.config,
19
+ version: integrationRecord.version,
20
+ status: integrationRecord.status,
21
+ messages: integrationRecord.messages,
22
+ }
14
23
  }
15
24
 
16
25
  async createIntegration(entities, userId, config) {
@@ -60,6 +60,7 @@ function createIntegrationRouter(params) {
60
60
  integrationRepository,
61
61
  integrationClasses: integrations,
62
62
  moduleService,
63
+ moduleRepository,
63
64
  });
64
65
  const getCredentialForUser = new GetCredentialForUser({
65
66
  credentialRepository,
@@ -2,7 +2,7 @@ const { Integration } = require('../integration');
2
2
  const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
3
 
4
4
  class GetIntegrationForUser {
5
- constructor({ integrationRepository, integrationClasses, moduleService }) {
5
+ constructor({ integrationRepository, integrationClasses, moduleService, moduleRepository }) {
6
6
 
7
7
  /**
8
8
  * @type {import('../integration-repository').IntegrationRepository}
@@ -10,6 +10,7 @@ class GetIntegrationForUser {
10
10
  this.integrationRepository = integrationRepository;
11
11
  this.integrationClasses = integrationClasses;
12
12
  this.moduleService = moduleService;
13
+ this.moduleRepository = moduleRepository;
13
14
  }
14
15
 
15
16
  /**
@@ -19,6 +20,7 @@ class GetIntegrationForUser {
19
20
  */
20
21
  async execute(integrationId, userId) {
21
22
  const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
23
+ const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
22
24
 
23
25
  if (!integrationRecord) {
24
26
  throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
@@ -33,18 +35,18 @@ class GetIntegrationForUser {
33
35
  );
34
36
 
35
37
  const modules = {};
36
- for (const [key, entity] of Object.entries(integrationRecord.entities)) {
38
+ for (const [key, entity] of Object.entries(entities)) {
37
39
  const moduleInstance = await this.moduleService.getModuleInstance(
38
- entity._id,
40
+ entity.id,
39
41
  integrationRecord.user
40
42
  );
41
43
  modules[key] = moduleInstance;
42
44
  }
43
45
 
44
46
  const integrationInstance = new Integration({
45
- id: integrationRecord._id.toString(),
47
+ id: integrationRecord._id,
46
48
  userId: integrationRecord.user,
47
- entities: integrationRecord.entities.map(e => ({ ...e, id: e._id.toString() })),
49
+ entities: entities,
48
50
  config: integrationRecord.config,
49
51
  status: integrationRecord.status,
50
52
  version: integrationRecord.version,
@@ -10,6 +10,20 @@ class ModuleRepository {
10
10
  return entity;
11
11
  }
12
12
 
13
+ async findEntitiesByIds(entitiesIds) {
14
+ const entitiesRecords = await Entity.find({ _id: { $in: entitiesIds } }, '', { lean: true }).populate('credential');
15
+ return entitiesRecords.map(e => ({
16
+ id: e._id,
17
+ accountId: e.accountId,
18
+ credential: e.credential,
19
+ userId: e.user,
20
+ name: e.name,
21
+ externalId: e.externalId,
22
+ type: e.__t,
23
+ moduleName: e.moduleName,
24
+ }));
25
+ }
26
+
13
27
  async findEntitiesByUserId(userId) {
14
28
  return Entity.find(
15
29
  { user: userId },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.396.6afd30a.0",
4
+ "version": "2.0.0--canary.396.5afebde.0",
5
5
  "dependencies": {
6
6
  "@hapi/boom": "^10.0.1",
7
7
  "aws-sdk": "^2.1200.0",
@@ -22,9 +22,9 @@
22
22
  "uuid": "^9.0.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@friggframework/eslint-config": "2.0.0--canary.396.6afd30a.0",
26
- "@friggframework/prettier-config": "2.0.0--canary.396.6afd30a.0",
27
- "@friggframework/test": "2.0.0--canary.396.6afd30a.0",
25
+ "@friggframework/eslint-config": "2.0.0--canary.396.5afebde.0",
26
+ "@friggframework/prettier-config": "2.0.0--canary.396.5afebde.0",
27
+ "@friggframework/test": "2.0.0--canary.396.5afebde.0",
28
28
  "@types/lodash": "4.17.15",
29
29
  "@typescript-eslint/eslint-plugin": "^8.0.0",
30
30
  "chai": "^4.3.6",
@@ -53,5 +53,5 @@
53
53
  },
54
54
  "homepage": "https://github.com/friggframework/frigg#readme",
55
55
  "description": "",
56
- "gitHead": "6afd30ab7178ec917c10c2539da48b005cbecb37"
56
+ "gitHead": "5afebde4f111d7d8a1b547996575b55f03274261"
57
57
  }