Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa): add has_account to possible list_customers query params #2811

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-games-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

Add has_account to filter only registered or unregistered customer in the admin
21 changes: 21 additions & 0 deletions integration-tests/api/__tests__/admin/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -147,7 +148,7 @@ export class AdminPostOrdersOrderFulfillmentsReq {

@IsBoolean()
@IsOptional()
@Transform(({ value }) => value === "true")
@Transform(({ value }) => optionalBooleanMapper.get(value))
no_notification?: boolean

@IsObject()
Expand Down
9 changes: 8 additions & 1 deletion packages/medusa/src/types/customers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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 {
@IsString()
@IsOptional()
q?: string

@IsBoolean()
@IsOptional()
@Transform(({ value }) => optionalBooleanMapper.get(value))
has_account?: boolean

@IsOptional()
@IsString({ each: true })
groups?: string[]
Expand Down
5 changes: 3 additions & 2 deletions packages/medusa/src/types/discount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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()
Expand Down