feat(medusa): add q param to PKs sales channels retrieval (#2810)

**What**
- enable to filter sales channels of a Publishable API Key with a free text search param

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Frane Polić
2022-12-15 19:12:44 +00:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 0fa5042e35
commit ea460b4e0b
5 changed files with 67 additions and 9 deletions
@@ -1,6 +1,8 @@
import { Request, Response } from "express"
import { IsOptional, IsString } from "class-validator"
import PublishableApiKeyService from "../../../../services/publishable-api-key"
import { extendedFindParamsMixin } from "../../../../types/common"
/**
* @oas [get] /publishable-api-keys/{id}/sales-channels
@@ -10,6 +12,7 @@ import PublishableApiKeyService from "../../../../services/publishable-api-key"
* x-authenticated: true
* parameters:
* - (path) id=* {string} The ID of the Publishable Api Key.
* - (query) q {string} Query used for searching sales channels' names and descriptions.
* x-codeSamples:
* - lang: JavaScript
* label: JS Client
@@ -61,11 +64,19 @@ export default async (req: Request, res: Response) => {
"publishableApiKeyService"
)
const salesChannels = await publishableApiKeyService.listSalesChannels(id)
const filterableFields = req.filterableFields
const salesChannels = await publishableApiKeyService.listSalesChannels(id, {
q: filterableFields.q as string | undefined,
})
return res.json({
sales_channels: salesChannels,
})
}
export class GetPublishableApiKeySalesChannelsParams {}
export class GetPublishableApiKeySalesChannelsParams extends extendedFindParamsMixin() {
@IsOptional()
@IsString()
q?: string
}