feat(medusa): Admin get product with isolated module (#5054)
* feat(medusa): Admin get product with isolated module * Create pretty-dryers-prove.md * use object instead of string * fix merge * fix * fix
This commit is contained in:
committed by
GitHub
parent
adb6fb3f7d
commit
5f76b967d9
5
.changeset/pretty-dryers-prove.md
Normal file
5
.changeset/pretty-dryers-prove.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat(medusa): Admin get product with isolated module
|
||||
@@ -1,4 +1,6 @@
|
||||
import { PricingService, ProductService } from "../../../../services"
|
||||
import IsolateProductDomainFeatureFlag from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import { defaultAdminProductRemoteQueryObject } from "./index"
|
||||
|
||||
/**
|
||||
* @oas [get] /admin/products/{id}
|
||||
@@ -56,8 +58,18 @@ export default async (req, res) => {
|
||||
|
||||
const productService: ProductService = req.scope.resolve("productService")
|
||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||
const featureFlagRouter = req.scope.resolve("featureFlagRouter")
|
||||
|
||||
const rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
||||
let rawProduct
|
||||
if (featureFlagRouter.isFeatureEnabled(IsolateProductDomainFeatureFlag.key)) {
|
||||
rawProduct = await getProductWithIsolatedProductModule(
|
||||
req,
|
||||
id,
|
||||
req.retrieveConfig
|
||||
)
|
||||
} else {
|
||||
rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
||||
}
|
||||
|
||||
// We only set prices if variants.prices are requested
|
||||
const shouldSetPricing = ["variants", "variants.prices"].every((relation) =>
|
||||
@@ -72,3 +84,23 @@ export default async (req, res) => {
|
||||
|
||||
res.json({ product })
|
||||
}
|
||||
|
||||
async function getProductWithIsolatedProductModule(req, id, retrieveConfig) {
|
||||
// TODO: Add support for fields/expands
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const variables = { id }
|
||||
|
||||
const query = {
|
||||
product: {
|
||||
__args: variables,
|
||||
...defaultAdminProductRemoteQueryObject,
|
||||
},
|
||||
}
|
||||
|
||||
const [product] = await remoteQuery(query)
|
||||
|
||||
product.profile_id = product.profile?.id
|
||||
|
||||
return product
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { IsOptional, IsString } from "class-validator"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { cleanResponseData } from "../../../../utils"
|
||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import { defaultStoreRemoteQueryFields } from "./index"
|
||||
import { defaultStoreProductRemoteQueryObject } from "./index"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products/{id}
|
||||
@@ -170,7 +170,7 @@ async function getProductWithIsolatedProductModule(req, id: string) {
|
||||
const query = {
|
||||
product: {
|
||||
__args: variables,
|
||||
...defaultStoreRemoteQueryFields,
|
||||
...defaultStoreProductRemoteQueryObject,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ export const allowedStoreProductsRelations = [
|
||||
/**
|
||||
* This is temporary.
|
||||
*/
|
||||
export const defaultStoreRemoteQueryFields = {
|
||||
export const defaultStoreProductRemoteQueryObject = {
|
||||
fields: defaultStoreProductsFields,
|
||||
images: {
|
||||
fields: ["id", "created_at", "updated_at", "deleted_at", "url", "metadata"],
|
||||
|
||||
@@ -24,7 +24,7 @@ import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { defaultStoreCategoryScope } from "../product-categories"
|
||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import { defaultStoreRemoteQueryFields } from "./index"
|
||||
import { defaultStoreProductRemoteQueryObject } from "./index"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products
|
||||
@@ -397,7 +397,7 @@ async function listAndCountProductWithIsolatedProductModule(
|
||||
const query = {
|
||||
product: {
|
||||
__args: variables,
|
||||
...defaultStoreRemoteQueryFields,
|
||||
...defaultStoreProductRemoteQueryObject,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user