From 34cf7a03a211614b4577a1711ae2ddbdf4873536 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Thu, 25 Jul 2024 08:38:19 +0200 Subject: [PATCH] feat(utils,link-modules): link between fulfillment provider and stock location (#8275) what: - adds link between fulfillment provider and stock location RESOLVES CC-233 --- packages/core/utils/src/link/links.ts | 6 ++ .../fulfillment-provider-location.ts | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts diff --git a/packages/core/utils/src/link/links.ts b/packages/core/utils/src/link/links.ts index 07b217fd0f..d579963772 100644 --- a/packages/core/utils/src/link/links.ts +++ b/packages/core/utils/src/link/links.ts @@ -44,6 +44,12 @@ export const LINKS = { Modules.STOCK_LOCATION, "location_id" ), + LocationFulfillmentProvider: composeLinkName( + Modules.STOCK_LOCATION, + "stock_location_id", + Modules.FULFILLMENT, + "fulfillment_provider_id" + ), LocationFulfillmentSet: composeLinkName( Modules.STOCK_LOCATION, "stock_location_id", diff --git a/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts new file mode 100644 index 0000000000..6847cab583 --- /dev/null +++ b/packages/modules/link-modules/src/definitions/fulfillment-provider-location.ts @@ -0,0 +1,68 @@ +import { ModuleJoinerConfig } from "@medusajs/types" +import { LINKS, Modules } from "@medusajs/utils" + +export const LocationFulfillmentProvider: ModuleJoinerConfig = { + serviceName: LINKS.LocationFulfillmentProvider, + isLink: true, + databaseConfig: { + tableName: "location_fulfillment_provider", + idPrefix: "locfp", + }, + alias: [ + { + name: ["location_fulfillment_provider", "location_fulfillment_providers"], + args: { entity: "LinkLocationFulfillmentProvider" }, + }, + ], + primaryKeys: ["id", "stock_location_id", "fulfillment_provider_id"], + relationships: [ + { + serviceName: Modules.STOCK_LOCATION, + primaryKey: "id", + foreignKey: "stock_location_id", + alias: "location", + args: { methodSuffix: "StockLocations" }, + }, + { + serviceName: Modules.FULFILLMENT, + primaryKey: "id", + foreignKey: "fulfillment_provider_id", + alias: "fulfillment_provider", + args: { methodSuffix: "FulfillmentProviders" }, + }, + ], + extends: [ + { + serviceName: Modules.STOCK_LOCATION, + relationship: { + serviceName: LINKS.LocationFulfillmentProvider, + primaryKey: "stock_location_id", + foreignKey: "id", + alias: "fulfillment_provider_link", + isList: true, + }, + fieldAlias: { + fulfillment_providers: { + path: "fulfillment_provider_link.fulfillment_provider", + isList: true, + }, + }, + }, + { + serviceName: Modules.FULFILLMENT, + relationship: { + serviceName: LINKS.LocationFulfillmentProvider, + primaryKey: "fulfillment_provider_id", + foreignKey: "id", + alias: "locations_link", + isList: true, + }, + fieldAlias: { + locations: { + path: "locations_link.location", + isList: true, + }, + }, + }, + ], +}