feat(medusa): Add has_account to list-customers query params (#2811)

This commit is contained in:
Philip Korsholm authored and GitHub committed 2022-12-16 12:16:34 +01:00
1 parent 6283010fd6
commit c16522d6ce
6 files changed
+42 -6

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Add has_account to filter only registered or unregistered customer in the admin
@@ -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 () => { it("lists customers in group and count", async () => {
const api = useApi() const api = useApi()
@@ -10,6 +10,7 @@ import { AdminGetDiscountsDiscountRuleParams } from "../../../../types/discount"
import { extendedFindParamsMixin } from "../../../../types/common" import { extendedFindParamsMixin } from "../../../../types/common"
import { Request, Response } from "express" import { Request, Response } from "express"
import { DiscountService } from "../../../../services" import { DiscountService } from "../../../../services"
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
/** /**
* @oas [get] /discounts * @oas [get] /discounts
@@ -127,11 +128,11 @@ export class AdminGetDiscountsParams extends extendedFindParamsMixin({
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
@Transform(({ value }) => value === "true") @Transform(({ value }) => optionalBooleanMapper.get(value))
is_dynamic?: boolean is_dynamic?: boolean
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
@Transform(({ value }) => value === "true") @Transform(({ value }) => optionalBooleanMapper.get(value))
is_disabled?: boolean is_disabled?: boolean
} }
@@ -14,6 +14,7 @@ import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "."
import { EntityManager } from "typeorm" import { EntityManager } from "typeorm"
import { OrderService } from "../../../../services" import { OrderService } from "../../../../services"
import { validator } from "../../../../utils/validator" import { validator } from "../../../../utils/validator"
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
/** /**
* @oas [post] /orders/{id}/fulfillment * @oas [post] /orders/{id}/fulfillment
@@ -147,7 +148,7 @@ export class AdminPostOrdersOrderFulfillmentsReq {
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
@Transform(({ value }) => value === "true") @Transform(({ value }) => optionalBooleanMapper.get(value))
no_notification?: boolean no_notification?: boolean
@IsObject() @IsObject()
+8 -1
View File
@@ -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" import { AddressPayload } from "./common"
export class AdminListCustomerSelector { export class AdminListCustomerSelector {
@@ -6,6 +8,11 @@ export class AdminListCustomerSelector {
@IsOptional() @IsOptional()
q?: string q?: string
@IsBoolean()
@IsOptional()
@Transform(({ value }) => optionalBooleanMapper.get(value))
has_account?: boolean
@IsOptional() @IsOptional()
@IsString({ each: true }) @IsString({ each: true })
groups?: string[] groups?: string[]
+3 -2
View File
@@ -15,6 +15,7 @@ import {
DiscountRuleType, DiscountRuleType,
Region, Region,
} from "../models" } from "../models"
import { optionalBooleanMapper } from "../utils/validators/is-boolean"
import { ExactlyOne } from "./validators/exactly-one" import { ExactlyOne } from "./validators/exactly-one"
export type QuerySelector = { export type QuerySelector = {
@@ -28,12 +29,12 @@ export class FilterableDiscountProps {
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
@Transform(({ value }) => value === "true") @Transform(({ value }) => optionalBooleanMapper.get(value))
is_dynamic?: boolean is_dynamic?: boolean
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
@Transform(({ value }) => value === "true") @Transform(({ value }) => optionalBooleanMapper.get(value))
is_disabled?: boolean is_disabled?: boolean
@ValidateNested() @ValidateNested()