feat(medusa): variants expand inventory_items (#4203)
* add expand params for inventory items to product and variant endpoints in store * add changeset * update integration test naming * make priceSeelctionParams extends findParams and adjust api accordingly
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
import {
|
||||
CartService,
|
||||
PricingService,
|
||||
@@ -6,6 +5,8 @@ import {
|
||||
ProductVariantInventoryService,
|
||||
RegionService,
|
||||
} from "../../../../services"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
|
||||
@@ -148,12 +149,4 @@ export class StoreGetProductsProductParams extends PriceSelectionParams {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
sales_channel_id?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
fields?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
expand?: string
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ export const allowedStoreProductsFields = [
|
||||
export const allowedStoreProductsRelations = [
|
||||
...defaultStoreProductsRelations,
|
||||
"variants.title",
|
||||
"variants.inventory_items",
|
||||
"variants.prices.amount",
|
||||
"sales_channels",
|
||||
]
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Transform, Type } from "class-transformer"
|
||||
import {
|
||||
CartService,
|
||||
ProductService,
|
||||
ProductVariantInventoryService,
|
||||
} from "../../../../services"
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
@@ -7,20 +11,17 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import {
|
||||
CartService,
|
||||
ProductService,
|
||||
ProductVariantInventoryService,
|
||||
} from "../../../../services"
|
||||
import PricingService from "../../../../services/pricing"
|
||||
import { Transform, Type } from "class-transformer"
|
||||
|
||||
import { DateComparisonOperator } from "../../../../types/common"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import PricingService from "../../../../services/pricing"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { defaultStoreCategoryScope } from "../product-categories"
|
||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/products
|
||||
@@ -283,14 +284,6 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
export class StoreGetProductsPaginationParams extends PriceSelectionParams {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
fields?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
expand?: string
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
|
||||
@@ -5,11 +5,12 @@ import {
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
} from "../../../../services"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { defaultStoreVariantRelations } from "."
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/variants/{variant_id}
|
||||
@@ -75,9 +76,7 @@ export default async (req, res) => {
|
||||
|
||||
const customer_id = req.user?.customer_id
|
||||
|
||||
const rawVariant = await variantService.retrieve(id, {
|
||||
relations: defaultStoreVariantRelations,
|
||||
})
|
||||
const rawVariant = await variantService.retrieve(id, req.retrieveConfig)
|
||||
|
||||
let sales_channel_id = validated.sales_channel_id
|
||||
if (req.publishableApiKeyScopes?.sales_channel_ids.length === 1) {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import middlewares, { transformStoreQuery } from "../../../middlewares"
|
||||
|
||||
import { PricedVariant } from "../../../../types/pricing"
|
||||
import { Router } from "express"
|
||||
import { StoreGetVariantsParams } from "./list-variants"
|
||||
import { StoreGetVariantsVariantParams } from "./get-variant"
|
||||
import { extendRequestParams } from "../../../middlewares/publishable-api-key/extend-request-params"
|
||||
import middlewares from "../../../middlewares"
|
||||
import { validateProductVariantSalesChannelAssociation } from "../../../middlewares/publishable-api-key/validate-variant-sales-channel-association"
|
||||
import { validateSalesChannelParam } from "../../../middlewares/publishable-api-key/validate-sales-channel-param"
|
||||
import { PricedVariant } from "../../../../types/pricing"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -12,14 +15,33 @@ export default (app) => {
|
||||
|
||||
route.use("/:id", validateProductVariantSalesChannelAssociation)
|
||||
|
||||
route.get("/", middlewares.wrap(require("./list-variants").default))
|
||||
route.get("/:id", middlewares.wrap(require("./get-variant").default))
|
||||
route.get(
|
||||
"/",
|
||||
transformStoreQuery(StoreGetVariantsParams, {
|
||||
defaultRelations: defaultStoreVariantRelations,
|
||||
allowedRelations: allowedStoreVariantRelations,
|
||||
isList: true,
|
||||
}),
|
||||
middlewares.wrap(require("./list-variants").default)
|
||||
)
|
||||
route.get(
|
||||
"/:id",
|
||||
transformStoreQuery(StoreGetVariantsVariantParams, {
|
||||
defaultRelations: defaultStoreVariantRelations,
|
||||
allowedRelations: allowedStoreVariantRelations,
|
||||
}),
|
||||
middlewares.wrap(require("./get-variant").default)
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
export const defaultStoreVariantRelations = ["prices", "options", "product"]
|
||||
|
||||
export const allowedStoreVariantRelations = [
|
||||
...defaultStoreVariantRelations,
|
||||
"inventory_items",
|
||||
]
|
||||
/**
|
||||
* @schema StoreVariantsRes
|
||||
* type: object
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { IsInt, IsOptional, IsString } from "class-validator"
|
||||
import {
|
||||
CartService,
|
||||
PricingService,
|
||||
@@ -6,15 +5,16 @@ import {
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
} from "../../../../services"
|
||||
import { IsInt, IsOptional, IsString } from "class-validator"
|
||||
|
||||
import { Type } from "class-transformer"
|
||||
import { omit } from "lodash"
|
||||
import { defaultStoreVariantRelations } from "."
|
||||
import { FilterableProductVariantProps } from "../../../../types/product-variant"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
import { NumericalComparisonOperator } from "../../../../types/common"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { FilterableProductVariantProps } from "../../../../types/product-variant"
|
||||
import { Type } from "class-transformer"
|
||||
import { defaultStoreVariantRelations } from "."
|
||||
import { omit } from "lodash"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
|
||||
/**
|
||||
* @oas [get] /store/variants
|
||||
@@ -183,10 +183,6 @@ export class StoreGetVariantsParams extends PriceSelectionParams {
|
||||
@Type(() => Number)
|
||||
offset?: number = 0
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
expand?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ids?: string
|
||||
|
||||
Reference in New Issue
Block a user