@monorise/core 1.0.2 → 1.0.4-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.
- package/dist/mock/monorise/chapter.d.ts +1 -1
- package/dist/mock/monorise/course.d.ts +1 -1
- package/dist/mock/monorise/learning-journey-config.d.ts +1 -1
- package/dist/mock/monorise/module.d.ts +1 -1
- package/dist/mock/monorise/organization.d.ts +1 -1
- package/dist/services/entity.service.d.ts +2 -2
- package/dist/services/entity.service.d.ts.map +1 -1
- package/package.json +4 -1
- package/configs/service.config.ts +0 -14
- package/constants/table.ts +0 -3
- package/controllers/entity/create-entity.controller.ts +0 -51
- package/controllers/entity/delete-entity.controller.ts +0 -35
- package/controllers/entity/entity.http +0 -62
- package/controllers/entity/get-entity.controller.ts +0 -33
- package/controllers/entity/list-entities.controller.ts +0 -69
- package/controllers/entity/update-entity.controller.ts +0 -56
- package/controllers/entity/upsert-entity.controller.ts +0 -97
- package/controllers/mutual/create-mutual.controller.ts +0 -89
- package/controllers/mutual/delete-mutual.controller.ts +0 -40
- package/controllers/mutual/get-mutual.controller.ts +0 -38
- package/controllers/mutual/list-entities-by-entity.controller.ts +0 -76
- package/controllers/mutual/mutual.http +0 -88
- package/controllers/mutual/update-mutual.controller.ts +0 -50
- package/controllers/setupRoutes.ts +0 -73
- package/controllers/tag/list-tags.controller.ts +0 -57
- package/data/DbUtils.ts +0 -40
- package/data/Entity.ts +0 -499
- package/data/EventUtils.ts +0 -47
- package/data/FileObject.ts +0 -16
- package/data/Mutual.ts +0 -779
- package/data/ProjectionExpression.ts +0 -8
- package/data/Tag.ts +0 -470
- package/data/abstract/Item.base.ts +0 -19
- package/data/abstract/Repository.base.ts +0 -92
- package/errors/api-error.ts +0 -39
- package/errors/extendable-error.ts +0 -35
- package/errors/standard-error.ts +0 -29
- package/helpers/dependencies.ts +0 -10
- package/helpers/event.ts +0 -85
- package/helpers/fromLastKeyQuery.ts +0 -11
- package/helpers/sleep.ts +0 -1
- package/helpers/toLastKeyResponse.ts +0 -11
- package/index.ts +0 -23
- package/middlewares/entity-type-check.ts +0 -20
- package/middlewares/mutual-type-check.ts +0 -26
- package/mock/entity.ts +0 -12
- package/mock/monorise/admin.ts +0 -35
- package/mock/monorise/chapter.ts +0 -94
- package/mock/monorise/course.ts +0 -149
- package/mock/monorise/index.ts +0 -143
- package/mock/monorise/learner.ts +0 -66
- package/mock/monorise/learning-activity.ts +0 -62
- package/mock/monorise/learning-journey-config.ts +0 -34
- package/mock/monorise/module.ts +0 -108
- package/mock/monorise/organization.ts +0 -63
- package/mock/monorise/reference.ts +0 -28
- package/mock/monorise/video.ts +0 -36
- package/processors/create-entity-processor.ts +0 -55
- package/processors/mutual-processor.ts +0 -262
- package/processors/prejoin-processor.ts +0 -264
- package/processors/replication-processor.ts +0 -261
- package/processors/tag-processor.ts +0 -174
- package/services/DependencyContainer.ts +0 -208
- package/services/entity-service-lifecycle.ts +0 -41
- package/services/entity.service.ts +0 -201
- package/services/mutual.service.ts +0 -285
- package/tsconfig.json +0 -116
- package/types/entity.type.ts +0 -62
- package/types/event.ts +0 -84
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { DynamoDB } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
import { CORE_TABLE } from '../configs/service.config';
|
|
3
|
-
import { getDependencies } from '../helpers/dependencies';
|
|
4
|
-
import type { publishEvent as publishEventType } from '../helpers/event';
|
|
5
|
-
|
|
6
|
-
import { DbUtils } from '../data/DbUtils';
|
|
7
|
-
import { EntityRepository } from '../data/Entity';
|
|
8
|
-
import { EventUtils } from '../data/EventUtils';
|
|
9
|
-
import { MutualRepository } from '../data/Mutual';
|
|
10
|
-
import { TagRepository } from '../data/Tag';
|
|
11
|
-
|
|
12
|
-
import { CreateEntityController } from '../controllers/entity/create-entity.controller';
|
|
13
|
-
import { DeleteEntityController } from '../controllers/entity/delete-entity.controller';
|
|
14
|
-
import { GetEntityController } from '../controllers/entity/get-entity.controller';
|
|
15
|
-
import { ListEntitiesController } from '../controllers/entity/list-entities.controller';
|
|
16
|
-
import { UpdateEntityController } from '../controllers/entity/update-entity.controller';
|
|
17
|
-
import { UpsertEntityController } from '../controllers/entity/upsert-entity.controller';
|
|
18
|
-
import { CreateMutualController } from '../controllers/mutual/create-mutual.controller';
|
|
19
|
-
import { DeleteMutualController } from '../controllers/mutual/delete-mutual.controller';
|
|
20
|
-
import { GetMutualController } from '../controllers/mutual/get-mutual.controller';
|
|
21
|
-
import { ListEntitiesByEntityController } from '../controllers/mutual/list-entities-by-entity.controller';
|
|
22
|
-
import { UpdateMutualController } from '../controllers/mutual/update-mutual.controller';
|
|
23
|
-
import { EntityService } from './entity.service';
|
|
24
|
-
import { MutualService } from './mutual.service';
|
|
25
|
-
|
|
26
|
-
import { ListTagsController } from '../controllers/tag/list-tags.controller';
|
|
27
|
-
|
|
28
|
-
export class DependencyContainer {
|
|
29
|
-
private _instanceCache: Map<string, any>;
|
|
30
|
-
private _publishEvent: typeof publishEventType | null;
|
|
31
|
-
private _tableName: string;
|
|
32
|
-
|
|
33
|
-
constructor() {
|
|
34
|
-
this._instanceCache = new Map();
|
|
35
|
-
this._publishEvent = null;
|
|
36
|
-
this._tableName = CORE_TABLE;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
createCachedInstance<T extends new (...args: any[]) => any>(
|
|
40
|
-
ClassRef: T,
|
|
41
|
-
...args: ConstructorParameters<T>
|
|
42
|
-
): InstanceType<T> {
|
|
43
|
-
const cacheKey = ClassRef.name;
|
|
44
|
-
|
|
45
|
-
if (this._instanceCache.has(cacheKey)) {
|
|
46
|
-
return this._instanceCache.get(cacheKey) as InstanceType<T>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const instance = new ClassRef(...args);
|
|
50
|
-
this._instanceCache.set(cacheKey, instance);
|
|
51
|
-
return instance;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get coreTable(): string {
|
|
55
|
-
if (this._tableName) return this._tableName;
|
|
56
|
-
|
|
57
|
-
this._tableName = CORE_TABLE;
|
|
58
|
-
return this._tableName;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get publishEvent(): typeof publishEventType {
|
|
62
|
-
// for non class based function you can still have your own way of constructing
|
|
63
|
-
if (this._publishEvent) return this._publishEvent;
|
|
64
|
-
|
|
65
|
-
this._publishEvent = getDependencies().publishEvent;
|
|
66
|
-
return this._publishEvent;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get dynamodbClient(): DynamoDB {
|
|
70
|
-
return this.createCachedInstance(DynamoDB);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get dbUtils(): DbUtils {
|
|
74
|
-
return this.createCachedInstance(DbUtils, this.dynamodbClient);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get eventUtils(): EventUtils {
|
|
78
|
-
return this.createCachedInstance(EventUtils, this.publishEvent);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get entityRepository(): EntityRepository {
|
|
82
|
-
return this.createCachedInstance(
|
|
83
|
-
EntityRepository,
|
|
84
|
-
this.coreTable,
|
|
85
|
-
this.dynamodbClient,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get mutualRepository(): MutualRepository {
|
|
90
|
-
return this.createCachedInstance(
|
|
91
|
-
MutualRepository,
|
|
92
|
-
this.coreTable,
|
|
93
|
-
this.dynamodbClient,
|
|
94
|
-
this.dbUtils,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get entityService(): EntityService {
|
|
99
|
-
return this.createCachedInstance(
|
|
100
|
-
EntityService,
|
|
101
|
-
this.entityRepository,
|
|
102
|
-
this.publishEvent,
|
|
103
|
-
this.eventUtils,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get mutualService(): MutualService {
|
|
108
|
-
return this.createCachedInstance(
|
|
109
|
-
MutualService,
|
|
110
|
-
this.entityRepository,
|
|
111
|
-
this.mutualRepository,
|
|
112
|
-
this.publishEvent,
|
|
113
|
-
this.eventUtils,
|
|
114
|
-
this.dbUtils,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get tagRepository(): TagRepository {
|
|
119
|
-
return this.createCachedInstance(
|
|
120
|
-
TagRepository,
|
|
121
|
-
this.coreTable,
|
|
122
|
-
this.dynamodbClient,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
get getEntityController(): GetEntityController {
|
|
127
|
-
return this.createCachedInstance(
|
|
128
|
-
GetEntityController,
|
|
129
|
-
this.entityRepository,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get listEntitiesController(): ListEntitiesController {
|
|
134
|
-
return this.createCachedInstance(
|
|
135
|
-
ListEntitiesController,
|
|
136
|
-
this.entityRepository,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get createEntityController(): CreateEntityController {
|
|
141
|
-
return this.createCachedInstance(
|
|
142
|
-
CreateEntityController,
|
|
143
|
-
this.entityService,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
get upsertEntityController(): UpsertEntityController {
|
|
148
|
-
return this.createCachedInstance(
|
|
149
|
-
UpsertEntityController,
|
|
150
|
-
this.entityRepository,
|
|
151
|
-
this.publishEvent,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
get updateEntityController(): UpdateEntityController {
|
|
156
|
-
return this.createCachedInstance(
|
|
157
|
-
UpdateEntityController,
|
|
158
|
-
this.entityService,
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
get deleteEntityController(): DeleteEntityController {
|
|
163
|
-
return this.createCachedInstance(
|
|
164
|
-
DeleteEntityController,
|
|
165
|
-
this.entityService,
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
get listEntitiesByEntityController(): ListEntitiesByEntityController {
|
|
170
|
-
return this.createCachedInstance(
|
|
171
|
-
ListEntitiesByEntityController,
|
|
172
|
-
this.mutualRepository,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
get getMutualController(): GetMutualController {
|
|
177
|
-
return this.createCachedInstance(
|
|
178
|
-
GetMutualController,
|
|
179
|
-
this.mutualRepository,
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
get createMutualController(): CreateMutualController {
|
|
184
|
-
return this.createCachedInstance(
|
|
185
|
-
CreateMutualController,
|
|
186
|
-
this.mutualService,
|
|
187
|
-
this.publishEvent,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
get updateMutualController(): UpdateMutualController {
|
|
192
|
-
return this.createCachedInstance(
|
|
193
|
-
UpdateMutualController,
|
|
194
|
-
this.mutualService,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
get deleteMutualController(): DeleteMutualController {
|
|
199
|
-
return this.createCachedInstance(
|
|
200
|
-
DeleteMutualController,
|
|
201
|
-
this.mutualService,
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
get listTagsController(): ListTagsController {
|
|
206
|
-
return this.createCachedInstance(ListTagsController, this.tagRepository);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Entity as EntityType } from '@monorise/base';
|
|
2
|
-
import { EntityConfig } from '#/lambda-layer/monorise';
|
|
3
|
-
import type { Entity } from '../data/Entity';
|
|
4
|
-
import type { EventUtils } from '../data/EventUtils';
|
|
5
|
-
import type { publishEvent as publishEventType } from '../helpers/event';
|
|
6
|
-
import { EVENT } from '../types/event';
|
|
7
|
-
|
|
8
|
-
export const afterCreateEntityHook = async <T extends EntityType>({
|
|
9
|
-
entity,
|
|
10
|
-
entityPayload = {},
|
|
11
|
-
accountId,
|
|
12
|
-
publishEvent,
|
|
13
|
-
eventUtils,
|
|
14
|
-
}: {
|
|
15
|
-
entity: Entity<T>;
|
|
16
|
-
entityPayload?: Record<string, unknown>;
|
|
17
|
-
accountId?: string | string[];
|
|
18
|
-
publishEvent: typeof publishEventType;
|
|
19
|
-
eventUtils: EventUtils;
|
|
20
|
-
}) => {
|
|
21
|
-
const mutualSchema = EntityConfig[entity.entityType].mutual?.mutualSchema;
|
|
22
|
-
const parsedMutualPayload = mutualSchema?.parse(entityPayload);
|
|
23
|
-
|
|
24
|
-
if (parsedMutualPayload) {
|
|
25
|
-
await eventUtils.publishCreateMutualsEvent({
|
|
26
|
-
entity,
|
|
27
|
-
mutualPayload: parsedMutualPayload,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
await publishEvent({
|
|
32
|
-
event: EVENT.CORE.ENTITY_CREATED,
|
|
33
|
-
payload: {
|
|
34
|
-
entityType: entity.entityType,
|
|
35
|
-
entityId: entity.entityId,
|
|
36
|
-
data: entity.data,
|
|
37
|
-
createdByAccountId: accountId,
|
|
38
|
-
publishedAt: entity.updatedAt || new Date().toISOString(),
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
};
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import type { Entity, EntitySchemaMap } from '@monorise/base';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
EmailAuthEnabledEntities,
|
|
5
|
-
EntityConfig,
|
|
6
|
-
} from '#/lambda-layer/monorise';
|
|
7
|
-
import type { EntityRepository } from '../data/Entity';
|
|
8
|
-
import type { EventUtils } from '../data/EventUtils';
|
|
9
|
-
import { StandardError } from '../errors/standard-error';
|
|
10
|
-
import type { publishEvent as publishEventType } from '../helpers/event';
|
|
11
|
-
import type { EventDetailBody as MutualProcessorEventDetailBody } from '../processors/mutual-processor';
|
|
12
|
-
import { EVENT } from '../types/event';
|
|
13
|
-
import { afterCreateEntityHook } from './entity-service-lifecycle';
|
|
14
|
-
|
|
15
|
-
export class EntityService {
|
|
16
|
-
constructor(
|
|
17
|
-
private entityRepository: EntityRepository,
|
|
18
|
-
private publishEvent: typeof publishEventType,
|
|
19
|
-
private eventUtils: EventUtils,
|
|
20
|
-
) {}
|
|
21
|
-
|
|
22
|
-
createEntity = async <T extends Entity>({
|
|
23
|
-
entityType,
|
|
24
|
-
entityId,
|
|
25
|
-
entityPayload,
|
|
26
|
-
accountId,
|
|
27
|
-
options,
|
|
28
|
-
}: {
|
|
29
|
-
entityType: T;
|
|
30
|
-
entityPayload: EntitySchemaMap[T];
|
|
31
|
-
entityId?: string;
|
|
32
|
-
accountId?: string | string[];
|
|
33
|
-
options?: {
|
|
34
|
-
createAndUpdateDatetime?: string;
|
|
35
|
-
mutualId?: string;
|
|
36
|
-
};
|
|
37
|
-
}) => {
|
|
38
|
-
const finalSchema = EntityConfig[entityType].finalSchema;
|
|
39
|
-
const entitySchema =
|
|
40
|
-
EntityConfig[entityType]?.createSchema ||
|
|
41
|
-
EntityConfig[entityType]?.baseSchema ||
|
|
42
|
-
z.object({});
|
|
43
|
-
// const mutualSchema = EntityConfig[entityType]?.mutual?.mutualSchema;
|
|
44
|
-
|
|
45
|
-
if (!finalSchema || !entitySchema) {
|
|
46
|
-
throw new StandardError('INVALID_ENTITY_TYPE', 'Invalid entity type');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
finalSchema.parse(entityPayload);
|
|
50
|
-
|
|
51
|
-
const parsedEntityPayload = entitySchema.parse(
|
|
52
|
-
entityPayload,
|
|
53
|
-
) as EntitySchemaMap[T] & { email: string };
|
|
54
|
-
|
|
55
|
-
// TODO: Create entity to accept mutual payload, so that mutual
|
|
56
|
-
// relationship can be formed when creating entity
|
|
57
|
-
// const parsedMutualPayload = mutualSchema?.parse(entityPayload);
|
|
58
|
-
|
|
59
|
-
if (EmailAuthEnabledEntities.includes(entityType)) {
|
|
60
|
-
await this.entityRepository.getEmailAvailability(
|
|
61
|
-
entityType,
|
|
62
|
-
parsedEntityPayload.email,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const entity = await this.entityRepository.createEntity(
|
|
67
|
-
entityType,
|
|
68
|
-
parsedEntityPayload,
|
|
69
|
-
entityId,
|
|
70
|
-
{
|
|
71
|
-
...(options?.mutualId
|
|
72
|
-
? {
|
|
73
|
-
mutualId: `MUTUAL#${options.mutualId}`,
|
|
74
|
-
}
|
|
75
|
-
: {}),
|
|
76
|
-
createAndUpdateDatetime: options?.createAndUpdateDatetime
|
|
77
|
-
? new Date(options.createAndUpdateDatetime)
|
|
78
|
-
: new Date(),
|
|
79
|
-
},
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
await afterCreateEntityHook({
|
|
83
|
-
entity,
|
|
84
|
-
entityPayload,
|
|
85
|
-
accountId,
|
|
86
|
-
publishEvent: this.publishEvent,
|
|
87
|
-
eventUtils: this.eventUtils,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return entity;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
updateEntity = async <T extends Entity>({
|
|
94
|
-
entityType,
|
|
95
|
-
entityId,
|
|
96
|
-
entityPayload,
|
|
97
|
-
accountId,
|
|
98
|
-
}: {
|
|
99
|
-
entityType: T;
|
|
100
|
-
entityId: string;
|
|
101
|
-
entityPayload: Partial<EntitySchemaMap[T]>;
|
|
102
|
-
accountId?: string | string[];
|
|
103
|
-
}) => {
|
|
104
|
-
const errorContext: Record<string, unknown> = {};
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
const entitySchema = EntityConfig[entityType].baseSchema;
|
|
108
|
-
const mutualSchema = EntityConfig[entityType].mutual?.mutualSchema;
|
|
109
|
-
|
|
110
|
-
if (!entitySchema) {
|
|
111
|
-
throw new StandardError('Invalid entity type', 'INVALID_ENTITY_TYPE');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const parsedEntityPayload = entitySchema.parse(entityPayload) as Partial<
|
|
115
|
-
EntitySchemaMap[T]
|
|
116
|
-
>;
|
|
117
|
-
const parsedMutualPayload = mutualSchema?.parse(entityPayload);
|
|
118
|
-
errorContext.parsedMutualPayload = parsedMutualPayload;
|
|
119
|
-
|
|
120
|
-
const entity = await this.entityRepository.updateEntity(
|
|
121
|
-
entityType,
|
|
122
|
-
entityId,
|
|
123
|
-
{ data: parsedEntityPayload },
|
|
124
|
-
);
|
|
125
|
-
errorContext.entity = entity;
|
|
126
|
-
|
|
127
|
-
if (parsedMutualPayload) {
|
|
128
|
-
const byEntityType = entityType;
|
|
129
|
-
const byEntityId = entityId;
|
|
130
|
-
const publishEventPromises = [];
|
|
131
|
-
|
|
132
|
-
for (const [fieldKey, config] of Object.entries(
|
|
133
|
-
EntityConfig[entityType].mutual?.mutualFields || {},
|
|
134
|
-
)) {
|
|
135
|
-
const toMutualIds = config.toMutualIds;
|
|
136
|
-
const mutualPayload = (parsedMutualPayload as Record<string, any>)[
|
|
137
|
-
fieldKey
|
|
138
|
-
];
|
|
139
|
-
if (!mutualPayload) continue;
|
|
140
|
-
|
|
141
|
-
publishEventPromises.push(
|
|
142
|
-
this.publishEvent<MutualProcessorEventDetailBody>({
|
|
143
|
-
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
144
|
-
payload: {
|
|
145
|
-
byEntityType,
|
|
146
|
-
byEntityId,
|
|
147
|
-
entityType: config.entityType,
|
|
148
|
-
field: fieldKey,
|
|
149
|
-
mutualIds: toMutualIds
|
|
150
|
-
? toMutualIds(mutualPayload)
|
|
151
|
-
: mutualPayload,
|
|
152
|
-
customContext: toMutualIds ? mutualPayload : {},
|
|
153
|
-
publishedAt: entity.updatedAt || new Date().toISOString(),
|
|
154
|
-
},
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
await Promise.allSettled(publishEventPromises);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
await this.publishEvent({
|
|
162
|
-
event: EVENT.CORE.ENTITY_UPDATED,
|
|
163
|
-
payload: {
|
|
164
|
-
entityType,
|
|
165
|
-
entityId,
|
|
166
|
-
data: entity.data,
|
|
167
|
-
updatedByAccountId: accountId,
|
|
168
|
-
publishedAt: entity.updatedAt || new Date().toISOString(),
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return entity;
|
|
173
|
-
} catch (error) {
|
|
174
|
-
if (error && typeof error === 'object') {
|
|
175
|
-
(error as Record<string, unknown>).context = errorContext;
|
|
176
|
-
}
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
deleteEntity = async <T extends Entity>({
|
|
182
|
-
entityType,
|
|
183
|
-
entityId,
|
|
184
|
-
accountId,
|
|
185
|
-
}: {
|
|
186
|
-
entityType: T;
|
|
187
|
-
entityId: string;
|
|
188
|
-
accountId?: string | string[];
|
|
189
|
-
}) => {
|
|
190
|
-
await this.entityRepository.deleteEntity(entityType, entityId);
|
|
191
|
-
|
|
192
|
-
await this.publishEvent({
|
|
193
|
-
event: EVENT.CORE.ENTITY_DELETED,
|
|
194
|
-
payload: {
|
|
195
|
-
entityType,
|
|
196
|
-
entityId,
|
|
197
|
-
deletedByAccountId: accountId,
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
}
|