feat(medusa, stock-location): Sales channel filtering when listing locations (#3324)
* only add ordering select if not already selected * add integration test * add changeset * remove catch * linting and suggestion from adrien * add sales channel filtering when listing locations * add changeset * add exception back into sales channel location service --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
cbbf3ca054
commit
a1e59313c9
@@ -148,6 +148,8 @@ export default async (req: Request, res: Response) => {
|
||||
const { filterableFields, listConfig } = req
|
||||
const { skip, take } = listConfig
|
||||
|
||||
const filterOnSalesChannel = !!filterableFields.sales_channel_id
|
||||
|
||||
const includeSalesChannels =
|
||||
!!listConfig.relations?.includes("sales_channels")
|
||||
|
||||
@@ -157,6 +159,18 @@ export default async (req: Request, res: Response) => {
|
||||
)
|
||||
}
|
||||
|
||||
if (filterOnSalesChannel) {
|
||||
const ids: string[] = Array.isArray(filterableFields.sales_channel_id)
|
||||
? filterableFields.sales_channel_id
|
||||
: [filterableFields.sales_channel_id]
|
||||
|
||||
delete filterableFields.sales_channel_id
|
||||
|
||||
const locationIds = await channelLocationService.listLocationIds(ids)
|
||||
|
||||
filterableFields.id = [...new Set(locationIds.flat())]
|
||||
}
|
||||
|
||||
let [locations, count] = await stockLocationService.listAndCount(
|
||||
filterableFields,
|
||||
listConfig
|
||||
@@ -193,4 +207,8 @@ export class AdminGetStockLocationsParams extends extendedFindParamsMixin({
|
||||
@IsOptional()
|
||||
@IsType([String, [String]])
|
||||
address_id?: string | string[]
|
||||
|
||||
@IsOptional()
|
||||
@IsType([String, [String]])
|
||||
sales_channel_id?: string | string[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user