@friggframework/core 2.0.0--canary.397.4cedf64.0 → 2.0.0--canary.397.17c930a.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.
@@ -1,5 +1,7 @@
1
1
  const { IntegrationMapping } = require('./integration-mapping');
2
2
  const { Options } = require('./options');
3
+ const { EnableIntegration } = require('./use-cases/enable-integration');
4
+ const { IntegrationRepository } = require('./integration-repository');
3
5
 
4
6
  const constantsToBeMigrated = {
5
7
  defaultEvents: {
@@ -76,6 +78,13 @@ class IntegrationBase {
76
78
  }
77
79
 
78
80
  constructor(params) {
81
+
82
+ // todo: maybe we can pass this as Dependency Injection in the sub-class constructor
83
+ const { integrationRepository } = new IntegrationRepository();
84
+ this.enableIntegration = new EnableIntegration({
85
+ integrationRepository,
86
+ });
87
+
79
88
  this.defaultEvents = {
80
89
  [constantsToBeMigrated.defaultEvents.ON_CREATE]: {
81
90
  type: constantsToBeMigrated.types.LIFE_CYCLE_EVENT,
@@ -194,10 +203,8 @@ class IntegrationBase {
194
203
  /**
195
204
  * CHILDREN CAN OVERRIDE THESE CONFIGURATION METHODS
196
205
  */
197
- async onCreate(params) {
198
- this.record.status = 'ENABLED';
199
- await this.record.save();
200
- return this.record;
206
+ async onCreate({ integrationId }) {
207
+ await this.enableIntegration.execute(integrationId);
201
208
  }
202
209
 
203
210
  async onUpdate(params) { }
@@ -31,6 +31,19 @@ class IntegrationRepository {
31
31
  }
32
32
  }
33
33
 
34
+ async updateIntegration(integrationId, status) {
35
+ const integrationRecord = await IntegrationModel.updateOne({ _id: integrationId }, { status });
36
+ return {
37
+ id: integrationRecord._id,
38
+ entitiesIds: integrationRecord.entities.map(e => e._id),
39
+ userId: integrationRecord.user.toString(),
40
+ config: integrationRecord.config,
41
+ version: integrationRecord.version,
42
+ status: integrationRecord.status,
43
+ messages: integrationRecord.messages,
44
+ };
45
+ }
46
+
34
47
  async createIntegration(entities, userId, config) {
35
48
  const integrationRecord = await IntegrationModel.create({
36
49
  entities: entities,
@@ -0,0 +1,12 @@
1
+ class EnableIntegration {
2
+ constructor({ integrationRepository }) {
3
+ this.integrationRepository = integrationRepository;
4
+ }
5
+
6
+ async execute(integrationId) {
7
+ const integration = await this.integrationRepository.updateIntegration(integrationId, 'ENABLED');
8
+ return integration;
9
+ }
10
+ }
11
+
12
+ module.exports = { EnableIntegration };
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.397.4cedf64.0",
4
+ "version": "2.0.0--canary.397.17c930a.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.397.4cedf64.0",
26
- "@friggframework/prettier-config": "2.0.0--canary.397.4cedf64.0",
27
- "@friggframework/test": "2.0.0--canary.397.4cedf64.0",
25
+ "@friggframework/eslint-config": "2.0.0--canary.397.17c930a.0",
26
+ "@friggframework/prettier-config": "2.0.0--canary.397.17c930a.0",
27
+ "@friggframework/test": "2.0.0--canary.397.17c930a.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": "4cedf648a1675ba589e66f40ee9b3c700b12f0b5"
56
+ "gitHead": "17c930a2dfe417f16b61c1facd6c04b17a6b7d83"
57
57
  }