@friggframework/core 2.0.0--canary.396.b594af8.0 → 2.0.0--canary.396.accf516.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.
@@ -2,7 +2,16 @@ const { IntegrationModel } = require('./integration-model');
2
2
 
3
3
  class IntegrationRepository {
4
4
  async findIntegrationsByUserId(userId) {
5
- return IntegrationModel.find({ user: userId }, '', { lean: true }).populate('entities');
5
+ const integrationRecords = await IntegrationModel.find({ user: userId }, '', { lean: true }).populate('entities');
6
+ return integrationRecords.map(integrationRecord => ({
7
+ id: integrationRecord._id,
8
+ entitiesIds: integrationRecord.entities.map(e => e._id),
9
+ userId: integrationRecord.user.toString(),
10
+ config: integrationRecord.config,
11
+ version: integrationRecord.version,
12
+ status: integrationRecord.status,
13
+ messages: integrationRecord.messages,
14
+ }));
6
15
  }
7
16
 
8
17
  async deleteIntegrationById(integrationId) {
@@ -21,7 +21,6 @@ class GetIntegrationForUser {
21
21
  async execute(integrationId, userId) {
22
22
  const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
23
23
  const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
24
- debugger;
25
24
 
26
25
  if (!integrationRecord) {
27
26
  throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
@@ -2,7 +2,7 @@ const { Integration } = require('../integration');
2
2
  const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
3
 
4
4
  class GetIntegrationsForUser {
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 GetIntegrationsForUser {
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
  /**
@@ -22,24 +23,25 @@ class GetIntegrationsForUser {
22
23
  const integrations = []
23
24
 
24
25
  for (const integrationRecord of integrationRecords) {
26
+ const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
25
27
 
26
28
  const integrationClass = this.integrationClasses.find(
27
29
  (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
28
30
  );
29
31
 
30
32
  const modules = {};
31
- for (const [key, entity] of Object.entries(integrationRecord.entities)) {
33
+ for (const [key, entity] of Object.entries(entities)) {
32
34
  const moduleInstance = await this.moduleService.getModuleInstance(
33
- entity._id,
34
- integrationRecord.user
35
+ entity.id,
36
+ integrationRecord.userId
35
37
  );
36
38
  modules[key] = moduleInstance;
37
39
  }
38
40
 
39
41
  const integrationInstance = new Integration({
40
- id: integrationRecord._id.toString(),
42
+ id: integrationRecord.id,
41
43
  userId: integrationRecord.user,
42
- entities: integrationRecord.entities,
44
+ entities: entities,
43
45
  config: integrationRecord.config,
44
46
  status: integrationRecord.status,
45
47
  version: integrationRecord.version,
@@ -7,16 +7,30 @@ class ModuleRepository {
7
7
  throw new Error(`Entity ${entityId} not found`);
8
8
  }
9
9
 
10
- return entity;
10
+ return {
11
+ id: entity._id,
12
+ accountId: entity.accountId,
13
+ credential: entity.credential,
14
+ userId: entity.user.toString(),
15
+ name: entity.name,
16
+ externalId: entity.externalId,
17
+ type: entity.__t,
18
+ moduleName: entity.moduleName,
19
+ };
11
20
  }
12
21
 
13
22
  async findEntitiesByIds(entitiesIds) {
14
23
  const entitiesRecords = await Entity.find({ _id: { $in: entitiesIds } }, '', { lean: true }).populate('credential');
24
+
25
+ if (entitiesRecords.length !== entitiesIds.length) {
26
+ throw new Error(`Some entities not found`);
27
+ }
28
+
15
29
  return entitiesRecords.map(e => ({
16
30
  id: e._id,
17
31
  accountId: e.accountId,
18
32
  credential: e.credential,
19
- userId: e.user,
33
+ userId: e.user.toString(),
20
34
  name: e.name,
21
35
  externalId: e.externalId,
22
36
  type: e.__t,
@@ -21,13 +21,13 @@ class ModuleService {
21
21
  throw new Error(`Entity ${entityId} not found`);
22
22
  }
23
23
 
24
- if (entity.user.toString() !== userId.toString()) {
24
+ if (entity.userId !== userId) {
25
25
  throw new Error(
26
26
  `Entity ${entityId} does not belong to user ${userId}`
27
27
  );
28
28
  }
29
29
 
30
- const entityType = entity.__t;
30
+ const entityType = entity.type;
31
31
  const moduleDefinition = this.moduleDefinitions.find((def) => {
32
32
  const modelName = Module.getEntityModelFromDefinition(def).modelName;
33
33
  return entityType === modelName;
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.b594af8.0",
4
+ "version": "2.0.0--canary.396.accf516.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.b594af8.0",
26
- "@friggframework/prettier-config": "2.0.0--canary.396.b594af8.0",
27
- "@friggframework/test": "2.0.0--canary.396.b594af8.0",
25
+ "@friggframework/eslint-config": "2.0.0--canary.396.accf516.0",
26
+ "@friggframework/prettier-config": "2.0.0--canary.396.accf516.0",
27
+ "@friggframework/test": "2.0.0--canary.396.accf516.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": "b594af868c04045fe056644e6200ef9b78717f6b"
56
+ "gitHead": "accf516c6aef6b581e2fe68268c28676275efa0d"
57
57
  }