diff --git a/.changeset/dull-games-boil.md b/.changeset/dull-games-boil.md new file mode 100644 index 0000000000000..4382358743bf9 --- /dev/null +++ b/.changeset/dull-games-boil.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +Add has_account to filter only registered or unregistered customer in the admin diff --git a/integration-tests/api/__tests__/admin/customer.js b/integration-tests/api/__tests__/admin/customer.js index b515203b78978..2d89a6c0b7b52 100644 --- a/integration-tests/api/__tests__/admin/customer.js +++ b/integration-tests/api/__tests__/admin/customer.js @@ -70,6 +70,27 @@ describe("/admin/customers", () => { ) }) + it("lists only registered customers", async () => { + const api = useApi() + + const response = await api + .get("/admin/customers?has_account=true", { + headers: { + Authorization: "Bearer test_token", + }, + }) + .catch((err) => { + console.log(err) + }) + + expect(response.status).toEqual(200) + expect(response.data.customers).toEqual( + expect.not.arrayContaining([ + expect.objectContaining({ has_account: false }), + ]) + ) + }) + it("lists customers in group and count", async () => { const api = useApi() diff --git a/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts b/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts index a01e2248038bb..236d6cd8045d8 100644 --- a/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts +++ b/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts @@ -10,6 +10,7 @@ import { AdminGetDiscountsDiscountRuleParams } from "../../../../types/discount" import { extendedFindParamsMixin } from "../../../../types/common" import { Request, Response } from "express" import { DiscountService } from "../../../../services" +import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean" /** * @oas [get] /discounts @@ -127,11 +128,11 @@ export class AdminGetDiscountsParams extends extendedFindParamsMixin({ @IsBoolean() @IsOptional() - @Transform(({ value }) => value === "true") + @Transform(({ value }) => optionalBooleanMapper.get(value)) is_dynamic?: boolean @IsBoolean() @IsOptional() - @Transform(({ value }) => value === "true") + @Transform(({ value }) => optionalBooleanMapper.get(value)) is_disabled?: boolean } diff --git a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts index f9e6334c349ba..28a783f0dbef4 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts @@ -14,6 +14,7 @@ import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "." import { EntityManager } from "typeorm" import { OrderService } from "../../../../services" import { validator } from "../../../../utils/validator" +import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean" /** * @oas [post] /orders/{id}/fulfillment @@ -147,7 +148,7 @@ export class AdminPostOrdersOrderFulfillmentsReq { @IsBoolean() @IsOptional() - @Transform(({ value }) => value === "true") + @Transform(({ value }) => optionalBooleanMapper.get(value)) no_notification?: boolean @IsObject() diff --git a/packages/medusa/src/types/customers.ts b/packages/medusa/src/types/customers.ts index 873c12a237b3b..9711e772ac585 100644 --- a/packages/medusa/src/types/customers.ts +++ b/packages/medusa/src/types/customers.ts @@ -1,4 +1,6 @@ -import { IsOptional, IsString } from "class-validator" +import { Transform } from "class-transformer" +import { IsBoolean, IsOptional, IsString } from "class-validator" +import { optionalBooleanMapper } from "../utils/validators/is-boolean" import { AddressPayload } from "./common" export class AdminListCustomerSelector { @@ -6,6 +8,11 @@ export class AdminListCustomerSelector { @IsOptional() q?: string + @IsBoolean() + @IsOptional() + @Transform(({ value }) => optionalBooleanMapper.get(value)) + has_account?: boolean + @IsOptional() @IsString({ each: true }) groups?: string[] diff --git a/packages/medusa/src/types/discount.ts b/packages/medusa/src/types/discount.ts index 196fbec68fe66..83e8553b3b24c 100644 --- a/packages/medusa/src/types/discount.ts +++ b/packages/medusa/src/types/discount.ts @@ -15,6 +15,7 @@ import { DiscountRuleType, Region, } from "../models" +import { optionalBooleanMapper } from "../utils/validators/is-boolean" import { ExactlyOne } from "./validators/exactly-one" export type QuerySelector = { @@ -28,12 +29,12 @@ export class FilterableDiscountProps { @IsBoolean() @IsOptional() - @Transform(({ value }) => value === "true") + @Transform(({ value }) => optionalBooleanMapper.get(value)) is_dynamic?: boolean @IsBoolean() @IsOptional() - @Transform(({ value }) => value === "true") + @Transform(({ value }) => optionalBooleanMapper.get(value)) is_disabled?: boolean @ValidateNested()