@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/client-types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Support q search in currencies
|
||||||
@@ -53,6 +53,35 @@ describe("/admin/currencies", () => {
|
|||||||
|
|
||||||
expect(response.data).toMatchSnapshot()
|
expect(response.data).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should retrieve the currencies filtered with q param", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/currencies?q=us&order=code`,
|
||||||
|
adminReqConfig
|
||||||
|
)
|
||||||
|
|
||||||
|
const { currencies } = response.data
|
||||||
|
|
||||||
|
expect(currencies).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "aud",
|
||||||
|
name: "Australian Dollar",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "byn",
|
||||||
|
name: "Belarusian Ruble",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "rub",
|
||||||
|
name: "Russian Ruble",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "usd",
|
||||||
|
name: "US Dollar",
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies", () => {
|
describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/currencies", () => {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ export interface AdminGetCurrenciesParams {
|
|||||||
* A field to sort order the retrieved currencies by.
|
* A field to sort order the retrieved currencies by.
|
||||||
*/
|
*/
|
||||||
order?: string
|
order?: string
|
||||||
|
/**
|
||||||
|
* Term used to search currencies' name and code.
|
||||||
|
*/
|
||||||
|
q?: string
|
||||||
/**
|
/**
|
||||||
* The number of currencies to skip when retrieving the currencies.
|
* The number of currencies to skip when retrieving the currencies.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators
|
|||||||
* type: boolean
|
* type: boolean
|
||||||
* x-featureFlag: "tax_inclusive_pricing"
|
* x-featureFlag: "tax_inclusive_pricing"
|
||||||
* - (query) order {string} A field to sort order the retrieved currencies by.
|
* - (query) order {string} A field to sort order the retrieved currencies by.
|
||||||
|
* - (query) q {string} Term used to search currencies' name and code.
|
||||||
* - (query) offset=0 {number} The number of currencies to skip when retrieving the currencies.
|
* - (query) offset=0 {number} The number of currencies to skip when retrieving the currencies.
|
||||||
* - (query) limit=20 {number} The number of currencies to return.
|
* - (query) limit=20 {number} The number of currencies to return.
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
@@ -128,6 +129,13 @@ export class AdminGetCurrenciesParams extends FindPaginationParams {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
code?: string
|
code?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search parameter for currencies.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
q?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter currencies by whether they include tax.
|
* Filter currencies by whether they include tax.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FlagRouter } from "@medusajs/utils"
|
import { FlagRouter } from "@medusajs/utils"
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager, FindOptionsWhere, ILike } from "typeorm"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
import { Currency } from "../models"
|
import { Currency } from "../models"
|
||||||
@@ -76,7 +76,7 @@ export default class CurrencyService extends TransactionBaseService {
|
|||||||
* as the second element.
|
* as the second element.
|
||||||
*/
|
*/
|
||||||
async listAndCount(
|
async listAndCount(
|
||||||
selector: Selector<Currency>,
|
selector: Selector<Currency> & { q?: string },
|
||||||
config: FindConfig<Currency> = {
|
config: FindConfig<Currency> = {
|
||||||
skip: 0,
|
skip: 0,
|
||||||
take: 20,
|
take: 20,
|
||||||
@@ -86,8 +86,33 @@ export default class CurrencyService extends TransactionBaseService {
|
|||||||
this.currencyRepository_
|
this.currencyRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let q: string | undefined
|
||||||
|
|
||||||
|
if (selector.q) {
|
||||||
|
q = selector.q
|
||||||
|
delete selector.q
|
||||||
|
}
|
||||||
|
|
||||||
const query = buildQuery(selector, config)
|
const query = buildQuery(selector, config)
|
||||||
|
|
||||||
|
if (q) {
|
||||||
|
const where = query.where as FindOptionsWhere<Currency>
|
||||||
|
|
||||||
|
delete where.code
|
||||||
|
delete where.name
|
||||||
|
|
||||||
|
query.where = [
|
||||||
|
{
|
||||||
|
...where,
|
||||||
|
code: ILike(`%${q}%`),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...where,
|
||||||
|
name: ILike(`%${q}%`),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
return await productRepo.findAndCount(query)
|
return await productRepo.findAndCount(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user