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

This commit is contained in:
Philip Korsholm
2022-12-16 12:16:34 +01:00
committed by GitHub
parent 6283010fd6
commit c16522d6ce
6 changed files with 42 additions and 6 deletions
+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 () => {
const api = useApi()
@@ -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
}
@@ -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()
+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"
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[]
+3 -2
View File
@@ -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()