feat(utils): update joiner config for campaigns (#6161)
This commit is contained in:
5
.changeset/quiet-cycles-doubt.md
Normal file
5
.changeset/quiet-cycles-doubt.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
feat(utils): update joiner config for campaigns
|
||||
@@ -1,31 +1,32 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import { Promotion } from "@models"
|
||||
import { generateLinkableKeysMap } from "@medusajs/utils"
|
||||
import { Campaign, Promotion } from "@models"
|
||||
|
||||
export const LinkableKeys = {
|
||||
promotion_id: Promotion.name,
|
||||
campaign_id: Campaign.name,
|
||||
}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
Object.entries(LinkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
export const entityNameToLinkableKeysMap = generateLinkableKeysMap(LinkableKeys)
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.PROMOTION,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: {
|
||||
name: ["promotion", "promotions"],
|
||||
args: {
|
||||
entity: Promotion.name,
|
||||
alias: [
|
||||
{
|
||||
name: ["promotion", "promotions"],
|
||||
args: {
|
||||
entity: Promotion.name,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["campaign", "campaigns"],
|
||||
args: {
|
||||
entity: Campaign.name,
|
||||
methodSuffix: "Campaigns",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
17
packages/utils/src/common/generate-linkable-keys-map.ts
Normal file
17
packages/utils/src/common/generate-linkable-keys-map.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { MapToConfig } from "./map-object-to"
|
||||
|
||||
export function generateLinkableKeysMap(
|
||||
linkableKeys: Record<string, string>
|
||||
): MapToConfig {
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
|
||||
Object.entries(linkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
})
|
||||
|
||||
return entityLinkableKeysMap
|
||||
}
|
||||
@@ -7,6 +7,7 @@ export * from "./deduplicate"
|
||||
export * from "./deep-equal-obj"
|
||||
export * from "./errors"
|
||||
export * from "./generate-entity-id"
|
||||
export * from "./generate-linkable-keys-map"
|
||||
export * from "./get-config-file"
|
||||
export * from "./get-iso-string-from-date"
|
||||
export * from "./get-selects-and-relations-from-object-array"
|
||||
|
||||
Reference in New Issue
Block a user