fix(orchestration,link-modules,pricing,types): fix shippingprofile errror outside of core + change link alias name (#5025)
* fix(orchestration,link-modules,pricing,types): fix shippingprofile error outside of core + change link alias name * chore: scope relationships and move condition inside * chore: remove islist * chore: fix merge conflict * chore: reverted serviceName scoping * chore: change shape to make methodOverride compatible * chore: added methodOverride to remote query * chore: revert override
This commit is contained in:
8
.changeset/shy-students-look.md
Normal file
8
.changeset/shy-students-look.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@medusajs/orchestration": patch
|
||||
"@medusajs/link-modules": patch
|
||||
"@medusajs/pricing": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix(orchestration,link-modules,pricing,types): fix shippingprofile error outside of core + change link alias name
|
||||
@@ -38,7 +38,6 @@ export const ProductShippingProfile: ModuleJoinerConfig = {
|
||||
},
|
||||
relationship: {
|
||||
serviceName: LINKS.ProductShippingProfile,
|
||||
isInternalService: true,
|
||||
primaryKey: "product_id",
|
||||
foreignKey: "id",
|
||||
alias: "shipping_profile",
|
||||
|
||||
@@ -43,8 +43,7 @@ export const ProductVariantPriceSet: ModuleJoinerConfig = {
|
||||
serviceName: LINKS.ProductVariantPriceSet,
|
||||
primaryKey: "variant_id",
|
||||
foreignKey: "id",
|
||||
alias: "prices",
|
||||
isList: false,
|
||||
alias: "price",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -157,7 +157,6 @@ export class RemoteQuery {
|
||||
"skip",
|
||||
"take",
|
||||
"limit",
|
||||
"order",
|
||||
"offset",
|
||||
"cursor",
|
||||
"sort",
|
||||
|
||||
@@ -197,6 +197,16 @@ export class RemoteJoiner {
|
||||
{ fieldAlias, relationships },
|
||||
] of expandedRelationships) {
|
||||
if (!this.serviceConfigCache.has(serviceName)) {
|
||||
// If true, the relationship is an internal service from the medusa core
|
||||
// If modules are being used ouside of the core, we should not be throwing
|
||||
// errors when the core services are not found in cache.
|
||||
// TODO: Remove when there are no more "internal" services
|
||||
const isInternalServicePresent = relationships.some(
|
||||
(rel) => rel.isInternalService === true
|
||||
)
|
||||
|
||||
if (isInternalServicePresent) continue
|
||||
|
||||
throw new Error(`Service "${serviceName}" was not found`)
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ describe("PricingModule Service - PriceSet", () => {
|
||||
describe("calculatePrices", () => {
|
||||
it("retrieves the calculated prices when no context is set", async () => {
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
["price-set-1", "price-set-2"],
|
||||
{ id: ["price-set-1", "price-set-2"] },
|
||||
{}
|
||||
)
|
||||
|
||||
@@ -96,9 +96,11 @@ describe("PricingModule Service - PriceSet", () => {
|
||||
|
||||
it("retrieves the calculated prices when a context is set", async () => {
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
["price-set-1", "price-set-2"],
|
||||
{ id: ["price-set-1", "price-set-2"] },
|
||||
{
|
||||
currency_code: "USD",
|
||||
context: {
|
||||
currency_code: "USD",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -122,9 +124,9 @@ describe("PricingModule Service - PriceSet", () => {
|
||||
|
||||
it("retrieves the calculated prices only when id exists in the database", async () => {
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
["price-set-doesnotexist", "price-set-1"],
|
||||
{ id: ["price-set-doesnotexist", "price-set-1"] },
|
||||
{
|
||||
currency_code: "USD",
|
||||
context: { currency_code: "USD" },
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
FindConfig,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
PricingTypes,
|
||||
} from "@medusajs/types"
|
||||
import { Currency, MoneyAmount, PriceSet } from "@models"
|
||||
@@ -25,10 +27,6 @@ type InjectedDependencies = {
|
||||
priceSetService: PriceSetService<any>
|
||||
}
|
||||
|
||||
type PricingContext = {
|
||||
currency_code?: string
|
||||
}
|
||||
|
||||
export default class PricingModuleService<
|
||||
TPriceSet extends PriceSet = PriceSet,
|
||||
TMoneyAmount extends MoneyAmount = MoneyAmount,
|
||||
@@ -61,14 +59,15 @@ export default class PricingModuleService<
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async calculatePrices(
|
||||
priceSetIds: string[],
|
||||
pricingContext: PricingContext,
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext = { context: {} },
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.CalculatedPriceSetDTO> {
|
||||
// Keeping this whole logic raw in here for now as they will undergo
|
||||
// some changes, will abstract them out once we have a final version
|
||||
const context = pricingContext.context || {}
|
||||
const priceSetFilters: PricingTypes.FilterablePriceSetProps = {
|
||||
id: priceSetIds,
|
||||
id: pricingFilters.id,
|
||||
}
|
||||
|
||||
const priceSets = await this.list(
|
||||
@@ -95,8 +94,7 @@ export default class PricingModuleService<
|
||||
// When no price is set, return null values for all cases
|
||||
const selectedMoneyAmount = priceSet.money_amounts?.find(
|
||||
(ma) =>
|
||||
pricingContext.currency_code &&
|
||||
ma.currency_code === pricingContext.currency_code
|
||||
context.currency_code && ma.currency_code === context.currency_code
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,6 +3,11 @@ export type JoinerRelationship = {
|
||||
foreignKey: string
|
||||
primaryKey: string
|
||||
serviceName: string
|
||||
/**
|
||||
* If true, the relationship is an internal service from the medusa core
|
||||
* TODO: Remove when there are no more "internal" services
|
||||
*/
|
||||
isInternalService?: boolean
|
||||
/**
|
||||
* In an inverted relationship the foreign key is on the other service and the primary key is on the current service
|
||||
*/
|
||||
|
||||
@@ -2,8 +2,15 @@ import { BaseFilterable } from "../../dal"
|
||||
import { FilterableMoneyAmountProps, MoneyAmountDTO } from "./money-amount"
|
||||
|
||||
export interface PricingContext {
|
||||
currency_code?: string
|
||||
context?: {
|
||||
currency_code?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface PricingFilters {
|
||||
id: string[]
|
||||
}
|
||||
|
||||
export interface PriceSetDTO {
|
||||
id: string
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
MoneyAmountDTO,
|
||||
PriceSetDTO,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
UpdateCurrencyDTO,
|
||||
UpdateMoneyAmountDTO,
|
||||
UpdatePriceSetDTO,
|
||||
@@ -22,8 +23,8 @@ export interface IPricingModuleService {
|
||||
__joinerConfig(): ModuleJoinerConfig
|
||||
|
||||
calculatePrices(
|
||||
priceSetIds: string[],
|
||||
pricingContext: PricingContext,
|
||||
filters: PricingFilters,
|
||||
context?: PricingContext,
|
||||
sharedContext?: Context
|
||||
): Promise<CalculatedPriceSetDTO>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user