@monorise/core 0.1.2 → 0.1.3
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.
- package/dist/base/utils/index.js +2 -9
- package/dist/base/utils/index.js.map +1 -1
- package/dist/core/controllers/entity/create-entity.controller.js +39 -32
- package/dist/core/controllers/entity/create-entity.controller.js.map +1 -1
- package/dist/core/controllers/entity/delete-entity.controller.js +26 -20
- package/dist/core/controllers/entity/delete-entity.controller.js.map +1 -1
- package/dist/core/controllers/entity/get-entity-by-unique-field-value.controller.js +25 -17
- package/dist/core/controllers/entity/get-entity-by-unique-field-value.controller.js.map +1 -1
- package/dist/core/controllers/entity/get-entity.controller.js +25 -17
- package/dist/core/controllers/entity/get-entity.controller.js.map +1 -1
- package/dist/core/controllers/entity/list-entities.controller.js +39 -36
- package/dist/core/controllers/entity/list-entities.controller.js.map +1 -1
- package/dist/core/controllers/entity/update-entity.controller.js +40 -33
- package/dist/core/controllers/entity/update-entity.controller.js.map +1 -1
- package/dist/core/controllers/entity/upsert-entity.controller.js +64 -59
- package/dist/core/controllers/entity/upsert-entity.controller.js.map +1 -1
- package/dist/core/controllers/mutual/create-mutual.controller.js +42 -38
- package/dist/core/controllers/mutual/create-mutual.controller.js.map +1 -1
- package/dist/core/controllers/mutual/delete-mutual.controller.js +28 -22
- package/dist/core/controllers/mutual/delete-mutual.controller.js.map +1 -1
- package/dist/core/controllers/mutual/get-mutual.controller.js +25 -17
- package/dist/core/controllers/mutual/get-mutual.controller.js.map +1 -1
- package/dist/core/controllers/mutual/list-entities-by-entity.controller.js +52 -44
- package/dist/core/controllers/mutual/list-entities-by-entity.controller.js.map +1 -1
- package/dist/core/controllers/mutual/update-mutual.controller.js +38 -32
- package/dist/core/controllers/mutual/update-mutual.controller.js.map +1 -1
- package/dist/core/controllers/tag/list-tags.controller.js +39 -31
- package/dist/core/controllers/tag/list-tags.controller.js.map +1 -1
- package/dist/core/data/DbUtils.js +23 -12
- package/dist/core/data/DbUtils.js.map +1 -1
- package/dist/core/data/Entity.js +298 -334
- package/dist/core/data/Entity.js.map +1 -1
- package/dist/core/data/EventUtils.js +35 -27
- package/dist/core/data/EventUtils.js.map +1 -1
- package/dist/core/data/Mutual.js +282 -342
- package/dist/core/data/Mutual.js.map +1 -1
- package/dist/core/data/Tag.js +225 -228
- package/dist/core/data/Tag.js.map +1 -1
- package/dist/core/data/abstract/Repository.base.js +4 -7
- package/dist/core/data/abstract/Repository.base.js.map +1 -1
- package/dist/core/errors/extendable-error.js +0 -7
- package/dist/core/errors/extendable-error.js.map +1 -1
- package/dist/core/errors/standard-error.js +0 -3
- package/dist/core/errors/standard-error.js.map +1 -1
- package/dist/core/helpers/event.js +35 -34
- package/dist/core/helpers/event.js.map +1 -1
- package/dist/core/helpers/test/test-utils.js +60 -58
- package/dist/core/helpers/test/test-utils.js.map +1 -1
- package/dist/core/index.js +0 -8
- package/dist/core/index.js.map +1 -1
- package/dist/core/processors/create-entity-processor.js +12 -3
- package/dist/core/processors/create-entity-processor.js.map +1 -1
- package/dist/core/processors/mutual-processor.js +33 -23
- package/dist/core/processors/mutual-processor.js.map +1 -1
- package/dist/core/processors/prejoin-processor.js +117 -105
- package/dist/core/processors/prejoin-processor.js.map +1 -1
- package/dist/core/processors/replication-processor.js +27 -26
- package/dist/core/processors/replication-processor.js.map +1 -1
- package/dist/core/processors/tag-processor.js +47 -35
- package/dist/core/processors/tag-processor.js.map +1 -1
- package/dist/core/services/DependencyContainer.js +0 -4
- package/dist/core/services/DependencyContainer.js.map +1 -1
- package/dist/core/services/entity-service-lifecycle.js +29 -20
- package/dist/core/services/entity-service-lifecycle.js.map +1 -1
- package/dist/core/services/entity.service.js +95 -92
- package/dist/core/services/entity.service.js.map +1 -1
- package/dist/core/services/mutual.service.js +117 -113
- package/dist/core/services/mutual.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,74 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
import { ZodError } from 'zod';
|
|
3
12
|
import { StandardError } from '../../errors/standard-error';
|
|
4
13
|
import { EVENT } from '../../types/event';
|
|
5
14
|
export class UpsertEntityController {
|
|
6
|
-
EntityConfig;
|
|
7
|
-
entityRepository;
|
|
8
|
-
publishEvent;
|
|
9
15
|
constructor(EntityConfig, entityRepository, publishEvent) {
|
|
10
16
|
this.EntityConfig = EntityConfig;
|
|
11
17
|
this.entityRepository = entityRepository;
|
|
12
18
|
this.publishEvent = publishEvent;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const parsedEntityPayload = entitySchema.parse(req.body);
|
|
25
|
-
const parsedMutualPayload = mutualSchema.parse(req.body);
|
|
26
|
-
const entity = await this.entityRepository.upsertEntity(entityType, entityId, parsedEntityPayload);
|
|
27
|
-
if (parsedMutualPayload) {
|
|
28
|
-
const byEntityType = entityType;
|
|
29
|
-
const byEntityId = entity.entityId;
|
|
30
|
-
const publishEventPromises = [];
|
|
31
|
-
for (const [fieldKey, config] of Object.entries(this.EntityConfig[entityType].mutual?.mutualFields || {})) {
|
|
32
|
-
publishEventPromises.push(this.publishEvent({
|
|
33
|
-
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
34
|
-
payload: {
|
|
35
|
-
byEntityType,
|
|
36
|
-
byEntityId,
|
|
37
|
-
entityType: config.entityType,
|
|
38
|
-
field: fieldKey,
|
|
39
|
-
mutualIds: parsedMutualPayload[fieldKey],
|
|
40
|
-
publishedAt: entity.updatedAt || new Date().toISOString(),
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
19
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const accountId = req.headers['account-id'];
|
|
22
|
+
const { entityType, entityId } = req.params;
|
|
23
|
+
try {
|
|
24
|
+
const entitySchema = this.EntityConfig[entityType].createSchema ||
|
|
25
|
+
this.EntityConfig[entityType].baseSchema;
|
|
26
|
+
const mutualSchema = (_a = this.EntityConfig[entityType].mutual) === null || _a === void 0 ? void 0 : _a.mutualSchema;
|
|
27
|
+
if (!entitySchema || !mutualSchema) {
|
|
28
|
+
throw new StandardError('Invalid entity type', 'INVALID_ENTITY_TYPE');
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
30
|
+
const parsedEntityPayload = entitySchema.parse(req.body);
|
|
31
|
+
const parsedMutualPayload = mutualSchema.parse(req.body);
|
|
32
|
+
const entity = yield this.entityRepository.upsertEntity(entityType, entityId, parsedEntityPayload);
|
|
33
|
+
if (parsedMutualPayload) {
|
|
34
|
+
const byEntityType = entityType;
|
|
35
|
+
const byEntityId = entity.entityId;
|
|
36
|
+
const publishEventPromises = [];
|
|
37
|
+
for (const [fieldKey, config] of Object.entries(((_b = this.EntityConfig[entityType].mutual) === null || _b === void 0 ? void 0 : _b.mutualFields) || {})) {
|
|
38
|
+
publishEventPromises.push(this.publishEvent({
|
|
39
|
+
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
40
|
+
payload: {
|
|
41
|
+
byEntityType,
|
|
42
|
+
byEntityId,
|
|
43
|
+
entityType: config.entityType,
|
|
44
|
+
field: fieldKey,
|
|
45
|
+
mutualIds: parsedMutualPayload[fieldKey],
|
|
46
|
+
publishedAt: entity.updatedAt || new Date().toISOString(),
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
yield Promise.allSettled(publishEventPromises);
|
|
51
|
+
}
|
|
52
|
+
yield this.publishEvent({
|
|
53
|
+
event: EVENT.CORE.ENTITY_UPSERTED,
|
|
54
|
+
payload: {
|
|
55
|
+
entityType,
|
|
56
|
+
entityId: entity.entityId,
|
|
57
|
+
payload: req.body,
|
|
58
|
+
createdByAccountId: accountId,
|
|
59
|
+
},
|
|
63
60
|
});
|
|
61
|
+
return res.status(httpStatus.OK).json(entity);
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (err instanceof ZodError) {
|
|
65
|
+
return res.status(httpStatus.BAD_REQUEST).json({
|
|
66
|
+
code: 'API_VALIDATION_ERROR',
|
|
67
|
+
message: 'API validation failed',
|
|
68
|
+
details: err.flatten(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (err instanceof StandardError && err.code === 'EMAIL_EXISTS') {
|
|
72
|
+
return res.status(httpStatus.BAD_REQUEST).json(Object.assign({}, err.toJSON()));
|
|
73
|
+
}
|
|
74
|
+
throw err;
|
|
69
75
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
//# sourceMappingURL=upsert-entity.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsert-entity.controller.js","sourceRoot":"","sources":["../../../../controllers/entity/upsert-entity.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,MAAM,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"file":"upsert-entity.controller.js","sourceRoot":"","sources":["../../../../controllers/entity/upsert-entity.controller.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,MAAM,OAAO,sBAAsB;IACjC,YACU,YAAmE,EACnE,gBAAkC,EAClC,YAAqC;QAFrC,iBAAY,GAAZ,YAAY,CAAuD;QACnE,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,iBAAY,GAAZ,YAAY,CAAyB;QAG/C,eAAU,GAA0C,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;;YACrE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC5C,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAGpC,CAAC;YAEF,IAAI,CAAC;gBACH,MAAM,YAAY,GAChB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,YAAY;oBAC1C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC;gBAC3C,MAAM,YAAY,GAAG,MAAA,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,0CAAE,YAAY,CAAC;gBAExE,IAAI,CAAC,YAAY,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,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe;oBACjC,OAAO,EAAE;wBACP,UAAU;wBACV,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,OAAO,EAAE,GAAG,CAAC,IAAI;wBACjB,kBAAkB,EAAE,SAAS;qBAC9B;iBACF,CAAC,CAAC;gBAEH,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;oBAC5B,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;wBAC7C,IAAI,EAAE,sBAAsB;wBAC5B,OAAO,EAAE,uBAAuB;wBAChC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;qBACvB,CAAC,CAAC;gBACL,CAAC;gBAED,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;oBAChE,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,mBACzC,GAAG,CAAC,MAAM,EAAE,EACf,CAAC;gBACL,CAAC;gBAED,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC,CAAA,CAAC;IAjFC,CAAC;CAkFL"}
|
|
@@ -1,49 +1,53 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
import { ZodError } from 'zod';
|
|
3
12
|
import { StandardError } from '../../errors/standard-error';
|
|
4
13
|
export class CreateMutualController {
|
|
5
|
-
mutualService;
|
|
6
14
|
constructor(mutualService) {
|
|
7
15
|
this.mutualService = mutualService;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
return res.status(httpStatus.OK).json(mutual);
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
if (err instanceof ZodError) {
|
|
29
|
-
return res.status(httpStatus.BAD_REQUEST).json({
|
|
30
|
-
code: 'API_VALIDATION_ERROR',
|
|
31
|
-
message: 'API validation failed',
|
|
32
|
-
details: err.flatten(),
|
|
16
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const accountId = req.headers['account-id'];
|
|
18
|
+
const { byEntityType, byEntityId, entityType, entityId } = req.params;
|
|
19
|
+
const { asEntity } = req.query;
|
|
20
|
+
try {
|
|
21
|
+
const { mutual, eventPayload } = yield this.mutualService.createMutual({
|
|
22
|
+
byEntityType,
|
|
23
|
+
byEntityId,
|
|
24
|
+
entityType,
|
|
25
|
+
entityId,
|
|
26
|
+
mutualPayload: req.body,
|
|
27
|
+
accountId,
|
|
28
|
+
options: {
|
|
29
|
+
asEntity: asEntity,
|
|
30
|
+
},
|
|
33
31
|
});
|
|
32
|
+
return res.status(httpStatus.OK).json(mutual);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof ZodError) {
|
|
36
|
+
return res.status(httpStatus.BAD_REQUEST).json({
|
|
37
|
+
code: 'API_VALIDATION_ERROR',
|
|
38
|
+
message: 'API validation failed',
|
|
39
|
+
details: err.flatten(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (err instanceof StandardError && err.code === 'MUTUAL_EXISTS') {
|
|
43
|
+
return res.status(httpStatus.BAD_REQUEST).json(Object.assign({}, err.toJSON()));
|
|
44
|
+
}
|
|
45
|
+
if (err instanceof StandardError && err.code === 'ENTITY_IS_UNDEFINED') {
|
|
46
|
+
return res.status(httpStatus.BAD_REQUEST).json(Object.assign({}, err.toJSON()));
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
39
49
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
...err.toJSON(),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
throw err;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
//# sourceMappingURL=create-mutual.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/create-mutual.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAAM,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"file":"create-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/create-mutual.controller.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAA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AAC;gBAED,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;oBACvE,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,mBACzC,GAAG,CAAC,MAAM,EAAE,EACf,CAAC;gBACL,CAAC;gBAED,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC,CAAA,CAAC;IAnDiD,CAAC;CAoDrD"}
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
import { StandardError } from '../../errors/standard-error';
|
|
3
12
|
export class DeleteMutualController {
|
|
4
|
-
mutualService;
|
|
5
13
|
constructor(mutualService) {
|
|
6
14
|
this.mutualService = mutualService;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
accountId,
|
|
18
|
-
});
|
|
19
|
-
return res.json(mutual);
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
if (err instanceof StandardError && err.code === 'MUTUAL_NOT_FOUND') {
|
|
23
|
-
return res.status(httpStatus.BAD_REQUEST).json({
|
|
24
|
-
...err.toJSON(),
|
|
15
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const accountId = req.headers['account-id'];
|
|
17
|
+
const { byEntityType, byEntityId, entityType, entityId } = req.params;
|
|
18
|
+
try {
|
|
19
|
+
const mutual = yield this.mutualService.deleteMutual({
|
|
20
|
+
byEntityType,
|
|
21
|
+
byEntityId,
|
|
22
|
+
entityType,
|
|
23
|
+
entityId,
|
|
24
|
+
accountId,
|
|
25
25
|
});
|
|
26
|
+
return res.json(mutual);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (err instanceof StandardError && err.code === 'MUTUAL_NOT_FOUND') {
|
|
30
|
+
return res.status(httpStatus.BAD_REQUEST).json(Object.assign({}, err.toJSON()));
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
//# sourceMappingURL=delete-mutual.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/delete-mutual.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAAM,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"file":"delete-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/delete-mutual.controller.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAAM,OAAO,sBAAsB;IACjC,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAEhD,eAAU,GAA0C,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;YACrE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC5C,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,GACtD,GAAG,CAAC,MAKH,CAAC;YAEJ,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;oBACnD,YAAY;oBACZ,UAAU;oBACV,UAAU;oBACV,QAAQ;oBACR,SAAS;iBACV,CAAC,CAAC;gBAEH,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;oBACpE,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,mBACzC,GAAG,CAAC,MAAM,EAAE,EACf,CAAC;gBACL,CAAC;gBAED,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC,CAAA,CAAC;IA/BiD,CAAC;CAgCrD"}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
export class GetMutualController {
|
|
3
|
-
associateRepository;
|
|
4
12
|
constructor(associateRepository) {
|
|
5
13
|
this.associateRepository = associateRepository;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { byEntityType, byEntityId, entityType, entityId } = req.params;
|
|
16
|
+
try {
|
|
17
|
+
const associate = yield this.associateRepository.getMutual(byEntityType, byEntityId, entityType, entityId);
|
|
18
|
+
return res.status(httpStatus.OK).json(associate);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err.code === 'MUTUAL_IS_UNDEFINED') {
|
|
22
|
+
return res.status(httpStatus.NOT_FOUND).json({
|
|
23
|
+
code: 'MUTUAL_NOT_FOUND',
|
|
24
|
+
message: 'Mutual not found',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
//# sourceMappingURL=get-mutual.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/get-mutual.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,OAAO,mBAAmB;
|
|
1
|
+
{"version":3,"file":"get-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/get-mutual.controller.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,OAAO,mBAAmB;IAC9B,YAAoB,mBAAqC;QAArC,wBAAmB,GAAnB,mBAAmB,CAAkB;QAEzD,eAAU,GAA0C,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;YACrE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,GACtD,GAAG,CAAC,MAKH,CAAC;YAEJ,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,SAAS,CACxD,YAAY,EACZ,UAAU,EACV,UAAU,EACV,QAAQ,CACT,CAAC;gBAEF,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAK,GAAW,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;oBAChD,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;wBAC3C,IAAI,EAAE,kBAAkB;wBACxB,OAAO,EAAE,kBAAkB;qBAC5B,CAAC,CAAC;gBACL,CAAC;gBAED,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC,CAAA,CAAC;IA9B0D,CAAC;CA+B9D"}
|
|
@@ -1,56 +1,64 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
import { z } from 'zod';
|
|
3
12
|
export class ListEntitiesByEntityController {
|
|
4
|
-
associateRepository;
|
|
5
13
|
constructor(associateRepository) {
|
|
6
14
|
this.associateRepository = associateRepository;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { byEntityType, byEntityId, entityType } = req.params;
|
|
17
|
+
/**
|
|
18
|
+
* Chain query is a query that allows to query entities by a chain of mutual types.
|
|
19
|
+
* if /core/mutual/learner/:learnerId/pathways?chainEntityQuery=type1,type2
|
|
20
|
+
* then the query will look for list of type1 in learner based on learnerId,
|
|
21
|
+
* then look for list of type2 in type1 by list of entityId of type1,
|
|
22
|
+
* then finally look for list of pathways in type2 by list of entityId of type2.
|
|
23
|
+
*/
|
|
24
|
+
const querySchema = z.object({
|
|
25
|
+
chainEntityQuery: z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
const queryParam = querySchema.parse(req.query);
|
|
28
|
+
if (queryParam === null || queryParam === void 0 ? void 0 : queryParam.chainEntityQuery) {
|
|
29
|
+
try {
|
|
30
|
+
const mutualTypes = queryParam.chainEntityQuery.split(',');
|
|
31
|
+
const chainMutualTypes = [byEntityType, ...mutualTypes, entityType];
|
|
32
|
+
let byIds = [byEntityId];
|
|
33
|
+
let items = [];
|
|
34
|
+
for (let i = 1; i < chainMutualTypes.length; i++) {
|
|
35
|
+
const byType = chainMutualTypes[i - 1];
|
|
36
|
+
const type = chainMutualTypes[i];
|
|
37
|
+
items = [];
|
|
38
|
+
for (const byId of byIds) {
|
|
39
|
+
const resp = yield this.associateRepository.listEntitiesByEntity(byType, byId, type);
|
|
40
|
+
items = items.concat(resp.items);
|
|
41
|
+
}
|
|
42
|
+
byIds = items.map((item) => item.entityId);
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
return res.json({
|
|
45
|
+
entities: items,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return res.status(httpStatus.BAD_REQUEST).json({
|
|
50
|
+
code: 'INVALID_CHAIN_QUERY',
|
|
51
|
+
message: 'Chain query is invalid. Please double check the chainEntityQuery param',
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
|
-
return res.json({
|
|
38
|
-
entities: items,
|
|
39
|
-
});
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
else {
|
|
56
|
+
const resp = yield this.associateRepository.listEntitiesByEntity(byEntityType, byEntityId, entityType);
|
|
57
|
+
return res.json({
|
|
58
|
+
entities: resp.items,
|
|
45
59
|
});
|
|
46
60
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const resp = await this.associateRepository.listEntitiesByEntity(byEntityType, byEntityId, entityType);
|
|
50
|
-
return res.json({
|
|
51
|
-
entities: resp.items,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
55
63
|
}
|
|
56
64
|
//# sourceMappingURL=list-entities-by-entity.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-entities-by-entity.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/list-entities-by-entity.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,OAAO,8BAA8B;
|
|
1
|
+
{"version":3,"file":"list-entities-by-entity.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/list-entities-by-entity.controller.ts"],"names":[],"mappings":";;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,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAC9D,MAAM,EACN,IAAI,EACJ,IAAI,CACL,CAAC;4BACF,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACnC,CAAC;wBACD,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBAC7C,CAAC;oBAED,OAAO,GAAG,CAAC,IAAI,CAAC;wBACd,QAAQ,EAAE,KAAK;qBAChB,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;wBAC7C,IAAI,EAAE,qBAAqB;wBAC3B,OAAO,EACL,wEAAwE;qBAC3E,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAC9D,YAAY,EACZ,UAAU,EACV,UAAU,CACX,CAAC;gBAEF,OAAO,GAAG,CAAC,IAAI,CAAC;oBACd,QAAQ,EAAE,IAAI,CAAC,KAAK;iBACrB,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAA,CAAC;IAnE0D,CAAC;CAoE9D"}
|
|
@@ -1,43 +1,49 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import httpStatus from 'http-status';
|
|
2
11
|
import { ZodError } from 'zod';
|
|
3
12
|
import { StandardError } from '../../errors/standard-error';
|
|
4
13
|
export class UpdateMutualController {
|
|
5
|
-
mutualService;
|
|
6
14
|
constructor(mutualService) {
|
|
7
15
|
this.mutualService = mutualService;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
return res.status(httpStatus.OK).json(mutual);
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
if (err instanceof ZodError) {
|
|
28
|
-
return res.status(httpStatus.BAD_REQUEST).json({
|
|
29
|
-
code: 'API_VALIDATION_ERROR',
|
|
30
|
-
message: 'API validation failed',
|
|
31
|
-
details: err.flatten(),
|
|
16
|
+
this.controller = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const accountId = req.headers['account-id'];
|
|
18
|
+
const { byEntityType, byEntityId, entityType, entityId } = req.params;
|
|
19
|
+
try {
|
|
20
|
+
const mutual = yield this.mutualService.updateMutual({
|
|
21
|
+
byEntityType,
|
|
22
|
+
byEntityId,
|
|
23
|
+
entityType,
|
|
24
|
+
entityId,
|
|
25
|
+
mutualPayload: req.body,
|
|
26
|
+
accountId,
|
|
27
|
+
options: {
|
|
28
|
+
returnUpdatedValue: true,
|
|
29
|
+
},
|
|
32
30
|
});
|
|
31
|
+
return res.status(httpStatus.OK).json(mutual);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof ZodError) {
|
|
35
|
+
return res.status(httpStatus.BAD_REQUEST).json({
|
|
36
|
+
code: 'API_VALIDATION_ERROR',
|
|
37
|
+
message: 'API validation failed',
|
|
38
|
+
details: err.flatten(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (err instanceof StandardError && err.code === 'MUTUAL_NOT_FOUND') {
|
|
42
|
+
return res.status(httpStatus.BAD_REQUEST).json(Object.assign({}, err.toJSON()));
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
//# sourceMappingURL=update-mutual.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/update-mutual.controller.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAAM,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"file":"update-mutual.controller.js","sourceRoot":"","sources":["../../../../controllers/mutual/update-mutual.controller.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,MAAM,OAAO,sBAAsB;IACjC,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAEhD,eAAU,GAA0C,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;YACrE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC5C,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,GACtD,GAAG,CAAC,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