fix(): Event group id propagation and event managements (#12157)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
Context,
|
||||
ILinkModule,
|
||||
LinkDefinition,
|
||||
LoadedModule,
|
||||
@@ -7,7 +8,9 @@ import {
|
||||
|
||||
import {
|
||||
isObject,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaModuleType,
|
||||
Modules,
|
||||
promiseAll,
|
||||
toPascalCase,
|
||||
@@ -55,6 +58,9 @@ type LinkDataConfig = {
|
||||
}
|
||||
|
||||
export class Link {
|
||||
// To not lose the context chain, we need to set the type to MedusaModuleType
|
||||
static __type = MedusaModuleType
|
||||
|
||||
private modulesMap: Map<string, LoadedLinkModule> = new Map()
|
||||
private relationsPairs: Map<string, LoadedLinkModule> = new Map()
|
||||
private relations: Map<string, Map<string, RemoteRelationship[]>> = new Map()
|
||||
@@ -171,7 +177,8 @@ export class Link {
|
||||
|
||||
private async executeCascade(
|
||||
removedServices: DeleteEntityInput,
|
||||
executionMethod: "softDelete" | "restore"
|
||||
executionMethod: "softDelete" | "restore",
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[CascadeError[] | null, RemovedIds]> {
|
||||
const removedIds: RemovedIds = {}
|
||||
const returnIdsList: RemovedIds = {}
|
||||
@@ -254,9 +261,13 @@ export class Link {
|
||||
method += toPascalCase(args.methodSuffix)
|
||||
}
|
||||
|
||||
const removed = await service[method](cascadeDelKeys, {
|
||||
returnLinkableKeys: returnFields,
|
||||
})
|
||||
const removed = await service[method](
|
||||
cascadeDelKeys,
|
||||
{
|
||||
returnLinkableKeys: returnFields,
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
deletedEntities = removed as Record<string, string[]>
|
||||
} catch (error) {
|
||||
@@ -382,7 +393,10 @@ export class Link {
|
||||
}
|
||||
}
|
||||
|
||||
async create(link: LinkDefinition | LinkDefinition[]): Promise<unknown[]> {
|
||||
async create(
|
||||
link: LinkDefinition | LinkDefinition[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<unknown[]> {
|
||||
const allLinks = Array.isArray(link) ? link : [link]
|
||||
const serviceLinks = new Map<
|
||||
string,
|
||||
@@ -489,7 +503,8 @@ export class Link {
|
||||
},
|
||||
{
|
||||
take: 1,
|
||||
}
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
if (existingLinks.length > 0) {
|
||||
@@ -507,13 +522,18 @@ export class Link {
|
||||
const promises: Promise<unknown[]>[] = []
|
||||
for (const [serviceName, data] of serviceLinks) {
|
||||
const service = this.modulesMap.get(serviceName)!
|
||||
promises.push(service.create(data.linksToCreate))
|
||||
promises.push(
|
||||
service.create(data.linksToCreate, undefined, undefined, sharedContext)
|
||||
)
|
||||
}
|
||||
|
||||
return (await promiseAll(promises)).flat()
|
||||
}
|
||||
|
||||
async dismiss(link: LinkDefinition | LinkDefinition[]): Promise<unknown[]> {
|
||||
async dismiss(
|
||||
link: LinkDefinition | LinkDefinition[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<unknown[]> {
|
||||
const allLinks = Array.isArray(link) ? link : [link]
|
||||
const serviceLinks = new Map<string, [string | string[], string][]>()
|
||||
|
||||
@@ -541,27 +561,34 @@ export class Link {
|
||||
for (const [serviceName, links] of serviceLinks) {
|
||||
const service = this.modulesMap.get(serviceName)!
|
||||
|
||||
promises.push(service.dismiss(links))
|
||||
promises.push(service.dismiss(links, undefined, sharedContext))
|
||||
}
|
||||
|
||||
return (await promiseAll(promises)).flat()
|
||||
}
|
||||
|
||||
async delete(
|
||||
removedServices: DeleteEntityInput
|
||||
removedServices: DeleteEntityInput,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[CascadeError[] | null, RemovedIds]> {
|
||||
return await this.executeCascade(removedServices, "softDelete")
|
||||
return await this.executeCascade(
|
||||
removedServices,
|
||||
"softDelete",
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
async restore(
|
||||
removedServices: DeleteEntityInput
|
||||
removedServices: DeleteEntityInput,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[CascadeError[] | null, RestoredIds]> {
|
||||
return await this.executeCascade(removedServices, "restore")
|
||||
return await this.executeCascade(removedServices, "restore", sharedContext)
|
||||
}
|
||||
|
||||
async list(
|
||||
link: LinkDefinition | LinkDefinition[],
|
||||
options?: { asLinkDefinition?: boolean }
|
||||
options?: { asLinkDefinition?: boolean },
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<(object | LinkDefinition)[]> {
|
||||
const allLinks = Array.isArray(link) ? link : [link]
|
||||
const serviceLinks = new Map<string, object[]>()
|
||||
@@ -587,7 +614,7 @@ export class Link {
|
||||
|
||||
promises.push(
|
||||
service
|
||||
.list({ $or: filters })
|
||||
.list({ $or: filters }, {}, sharedContext)
|
||||
.then((links: any[]) =>
|
||||
options?.asLinkDefinition
|
||||
? convertRecordsToLinkDefinition(links, service)
|
||||
|
||||
Reference in New Issue
Block a user