fix(medusa): GET /admin/shipping-options params (#6208)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/client-types": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Enable pagination, search and ordering of shipping option list endpoint
|
||||||
@@ -5,15 +5,110 @@ import { SetRelation, Merge } from "../core/ModelUtils"
|
|||||||
|
|
||||||
export interface AdminGetShippingOptionsParams {
|
export interface AdminGetShippingOptionsParams {
|
||||||
/**
|
/**
|
||||||
* Filter by a region ID.
|
* Filter by name.
|
||||||
|
*/
|
||||||
|
name?: string
|
||||||
|
/**
|
||||||
|
* Filter by the ID of the region the shipping options belong to.
|
||||||
*/
|
*/
|
||||||
region_id?: string
|
region_id?: string
|
||||||
/**
|
/**
|
||||||
* Filter by whether the shipping option is used for returns or orders.
|
* Filter by whether the shipping options are return shipping options.
|
||||||
*/
|
*/
|
||||||
is_return?: boolean
|
is_return?: boolean
|
||||||
/**
|
/**
|
||||||
* Filter by whether the shipping option is used only by admins or not.
|
* Filter by whether the shipping options are available for admin users only.
|
||||||
*/
|
*/
|
||||||
admin_only?: boolean
|
admin_only?: boolean
|
||||||
|
/**
|
||||||
|
* Term used to search shipping options' name.
|
||||||
|
*/
|
||||||
|
q?: string
|
||||||
|
/**
|
||||||
|
* A shipping option field to sort-order the retrieved shipping options by.
|
||||||
|
*/
|
||||||
|
order?: string
|
||||||
|
/**
|
||||||
|
* Filter by shipping option IDs.
|
||||||
|
*/
|
||||||
|
id?: string | Array<string>
|
||||||
|
/**
|
||||||
|
* Filter by a creation date range.
|
||||||
|
*/
|
||||||
|
created_at?: {
|
||||||
|
/**
|
||||||
|
* filter by dates less than this date
|
||||||
|
*/
|
||||||
|
lt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than this date
|
||||||
|
*/
|
||||||
|
gt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates less than or equal to this date
|
||||||
|
*/
|
||||||
|
lte?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than or equal to this date
|
||||||
|
*/
|
||||||
|
gte?: string
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Filter by an update date range.
|
||||||
|
*/
|
||||||
|
updated_at?: {
|
||||||
|
/**
|
||||||
|
* filter by dates less than this date
|
||||||
|
*/
|
||||||
|
lt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than this date
|
||||||
|
*/
|
||||||
|
gt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates less than or equal to this date
|
||||||
|
*/
|
||||||
|
lte?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than or equal to this date
|
||||||
|
*/
|
||||||
|
gte?: string
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Filter by a deletion date range.
|
||||||
|
*/
|
||||||
|
deleted_at?: {
|
||||||
|
/**
|
||||||
|
* filter by dates less than this date
|
||||||
|
*/
|
||||||
|
lt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than this date
|
||||||
|
*/
|
||||||
|
gt?: string
|
||||||
|
/**
|
||||||
|
* filter by dates less than or equal to this date
|
||||||
|
*/
|
||||||
|
lte?: string
|
||||||
|
/**
|
||||||
|
* filter by dates greater than or equal to this date
|
||||||
|
*/
|
||||||
|
gte?: string
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The number of users to skip when retrieving the shipping options.
|
||||||
|
*/
|
||||||
|
offset?: number
|
||||||
|
/**
|
||||||
|
* Limit the number of shipping options returned.
|
||||||
|
*/
|
||||||
|
limit?: number
|
||||||
|
/**
|
||||||
|
* Comma-separated relations that should be expanded in the returned shipping options.
|
||||||
|
*/
|
||||||
|
expand?: string
|
||||||
|
/**
|
||||||
|
* Comma-separated fields that should be included in the returned shipping options.
|
||||||
|
*/
|
||||||
|
fields?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,6 @@
|
|||||||
import { SetRelation, Merge } from "../core/ModelUtils"
|
import { SetRelation, Merge } from "../core/ModelUtils"
|
||||||
|
|
||||||
export interface AdminGetUsersParams {
|
export interface AdminGetUsersParams {
|
||||||
/**
|
|
||||||
* Filter by a user ID.
|
|
||||||
*/
|
|
||||||
id?: string
|
|
||||||
/**
|
/**
|
||||||
* Filter by email.
|
* Filter by email.
|
||||||
*/
|
*/
|
||||||
@@ -21,13 +17,17 @@ export interface AdminGetUsersParams {
|
|||||||
*/
|
*/
|
||||||
last_name?: string
|
last_name?: string
|
||||||
/**
|
/**
|
||||||
* term used to search users' first name, last name, and email.
|
* Term used to search users' first name, last name, and email.
|
||||||
*/
|
*/
|
||||||
q?: string
|
q?: string
|
||||||
/**
|
/**
|
||||||
* A user field to sort-order the retrieved users by.
|
* A user field to sort-order the retrieved users by.
|
||||||
*/
|
*/
|
||||||
order?: string
|
order?: string
|
||||||
|
/**
|
||||||
|
* Filter by user IDs.
|
||||||
|
*/
|
||||||
|
id?: string | Array<string>
|
||||||
/**
|
/**
|
||||||
* Filter by a creation date range.
|
* Filter by a creation date range.
|
||||||
*/
|
*/
|
||||||
@@ -99,10 +99,6 @@ export interface AdminGetUsersParams {
|
|||||||
* Limit the number of users returned.
|
* Limit the number of users returned.
|
||||||
*/
|
*/
|
||||||
limit?: number
|
limit?: number
|
||||||
/**
|
|
||||||
* Comma-separated relations that should be expanded in the returned users.
|
|
||||||
*/
|
|
||||||
expand?: string
|
|
||||||
/**
|
/**
|
||||||
* Comma-separated fields that should be included in the returned users.
|
* Comma-separated fields that should be included in the returned users.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+9
-21
@@ -1,25 +1,10 @@
|
|||||||
import { IdMap } from "medusa-test-utils"
|
import { IdMap } from "medusa-test-utils"
|
||||||
import { request } from "../../../../../helpers/test-request"
|
import { request } from "../../../../../helpers/test-request"
|
||||||
import { ShippingOptionServiceMock } from "../../../../../services/__mocks__/shipping-option"
|
import { ShippingOptionServiceMock } from "../../../../../services/__mocks__/shipping-option"
|
||||||
|
import {
|
||||||
const defaultFields = [
|
shippingOptionsDefaultFields,
|
||||||
"id",
|
shippingOptionsDefaultRelations,
|
||||||
"name",
|
} from "../index"
|
||||||
"region_id",
|
|
||||||
"profile_id",
|
|
||||||
"provider_id",
|
|
||||||
"price_type",
|
|
||||||
"amount",
|
|
||||||
"is_return",
|
|
||||||
"admin_only",
|
|
||||||
"data",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"deleted_at",
|
|
||||||
"metadata",
|
|
||||||
]
|
|
||||||
|
|
||||||
const defaultRelations = ["region", "profile", "requirements"]
|
|
||||||
|
|
||||||
describe("GET /admin/shipping-options", () => {
|
describe("GET /admin/shipping-options", () => {
|
||||||
describe("successful retrieval", () => {
|
describe("successful retrieval", () => {
|
||||||
@@ -44,8 +29,11 @@ describe("GET /admin/shipping-options", () => {
|
|||||||
expect(ShippingOptionServiceMock.listAndCount).toHaveBeenCalledWith(
|
expect(ShippingOptionServiceMock.listAndCount).toHaveBeenCalledWith(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
select: defaultFields,
|
order: { created_at: "DESC" },
|
||||||
relations: defaultRelations,
|
select: shippingOptionsDefaultFields,
|
||||||
|
relations: shippingOptionsDefaultRelations,
|
||||||
|
skip: 0,
|
||||||
|
take: 50,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,16 +8,19 @@ import {
|
|||||||
IsString,
|
IsString,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
|
import {
|
||||||
|
shippingOptionsDefaultFields,
|
||||||
|
shippingOptionsDefaultRelations,
|
||||||
|
} from "."
|
||||||
import { RequirementType, ShippingOptionPriceType } from "../../../../models"
|
import { RequirementType, ShippingOptionPriceType } from "../../../../models"
|
||||||
import { defaultFields, defaultRelations } from "."
|
|
||||||
|
|
||||||
import { EntityManager } from "typeorm"
|
|
||||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
|
||||||
import { ShippingOptionService } from "../../../../services"
|
|
||||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
|
||||||
import { Type } from "class-transformer"
|
import { Type } from "class-transformer"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { EntityManager } from "typeorm"
|
||||||
|
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
|
import { ShippingOptionService } from "../../../../services"
|
||||||
import { CreateShippingOptionInput } from "../../../../types/shipping-options"
|
import { CreateShippingOptionInput } from "../../../../types/shipping-options"
|
||||||
|
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||||
|
import { validator } from "../../../../utils/validator"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /admin/shipping-options
|
* @oas [post] /admin/shipping-options
|
||||||
@@ -150,8 +153,8 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const data = await optionService.retrieve(result.id, {
|
const data = await optionService.retrieve(result.id, {
|
||||||
select: defaultFields,
|
select: shippingOptionsDefaultFields,
|
||||||
relations: defaultRelations,
|
relations: shippingOptionsDefaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
res.status(200).json({ shipping_option: data })
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { defaultFields, defaultRelations } from "."
|
import {
|
||||||
|
shippingOptionsDefaultFields,
|
||||||
|
shippingOptionsDefaultRelations,
|
||||||
|
} from "."
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /admin/shipping-options/{id}
|
* @oas [get] /admin/shipping-options/{id}
|
||||||
@@ -84,8 +87,8 @@ export default async (req, res) => {
|
|||||||
const optionService = req.scope.resolve("shippingOptionService")
|
const optionService = req.scope.resolve("shippingOptionService")
|
||||||
|
|
||||||
const data = await optionService.retrieve(option_id, {
|
const data = await optionService.retrieve(option_id, {
|
||||||
select: defaultFields,
|
select: shippingOptionsDefaultFields,
|
||||||
relations: defaultRelations,
|
relations: shippingOptionsDefaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
res.status(200).json({ shipping_option: data })
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { FlagRouter } from "@medusajs/utils"
|
import { FlagRouter } from "@medusajs/utils"
|
||||||
import { Router } from "express"
|
import { Router } from "express"
|
||||||
import { ShippingOption } from "../../../.."
|
|
||||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
|
import { ShippingOption } from "../../../../models"
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||||
import middlewares from "../../../middlewares"
|
import middlewares, { transformQuery } from "../../../middlewares"
|
||||||
|
import { AdminGetShippingOptionsParams } from "./list-shipping-options"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
@@ -11,10 +12,18 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
app.use("/shipping-options", route)
|
app.use("/shipping-options", route)
|
||||||
|
|
||||||
if (featureFlagRouter.isFeatureEnabled(TaxInclusivePricingFeatureFlag.key)) {
|
if (featureFlagRouter.isFeatureEnabled(TaxInclusivePricingFeatureFlag.key)) {
|
||||||
defaultFields.push("includes_tax")
|
shippingOptionsDefaultFields.push("includes_tax")
|
||||||
}
|
}
|
||||||
|
|
||||||
route.get("/", middlewares.wrap(require("./list-shipping-options").default))
|
route.get(
|
||||||
|
"/",
|
||||||
|
transformQuery(AdminGetShippingOptionsParams, {
|
||||||
|
defaultFields: shippingOptionsDefaultFields,
|
||||||
|
defaultRelations: shippingOptionsDefaultRelations,
|
||||||
|
isList: true,
|
||||||
|
}),
|
||||||
|
middlewares.wrap(require("./list-shipping-options").default)
|
||||||
|
)
|
||||||
route.post("/", middlewares.wrap(require("./create-shipping-option").default))
|
route.post("/", middlewares.wrap(require("./create-shipping-option").default))
|
||||||
|
|
||||||
route.get(
|
route.get(
|
||||||
@@ -33,7 +42,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultFields: (keyof ShippingOption)[] = [
|
export const shippingOptionsDefaultFields: (keyof ShippingOption)[] = [
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"name",
|
||||||
"region_id",
|
"region_id",
|
||||||
@@ -50,7 +59,11 @@ export const defaultFields: (keyof ShippingOption)[] = [
|
|||||||
"metadata",
|
"metadata",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const defaultRelations = ["region", "profile", "requirements"]
|
export const shippingOptionsDefaultRelations = [
|
||||||
|
"region",
|
||||||
|
"profile",
|
||||||
|
"requirements",
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @schema AdminShippingOptionsListRes
|
* @schema AdminShippingOptionsListRes
|
||||||
|
|||||||
@@ -1,33 +1,116 @@
|
|||||||
import { IsBoolean, IsOptional, IsString } from "class-validator"
|
import {
|
||||||
import { defaultFields, defaultRelations } from "."
|
IsBoolean,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
ValidateNested,
|
||||||
|
} from "class-validator"
|
||||||
|
|
||||||
import { PricingService } from "../../../../services"
|
import { Transform, Type } from "class-transformer"
|
||||||
import { Transform } from "class-transformer"
|
import { Request, Response } from "express"
|
||||||
|
import { PricingService, ShippingOptionService } from "../../../../services"
|
||||||
|
import {
|
||||||
|
DateComparisonOperator,
|
||||||
|
extendedFindParamsMixin,
|
||||||
|
} from "../../../../types/common"
|
||||||
|
import { IsType } from "../../../../utils"
|
||||||
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||||
import { validator } from "../../../../utils/validator"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /admin/shipping-options
|
* @oas [get] /admin/shipping-options
|
||||||
* operationId: "GetShippingOptions"
|
* operationId: "GetShippingOptions"
|
||||||
* summary: "List Shipping Options"
|
* summary: "List Shipping Options"
|
||||||
* description: "Retrieve a list of Shipping Options. The shipping options can be filtered by fields such as `region_id` or `is_return`."
|
* description: "Retrieve a list of Shipping Options. The shipping options can be filtered by fields such as `region_id` or `is_return`. The shipping options can also be sorted or paginated."
|
||||||
* x-authenticated: true
|
* x-authenticated: true
|
||||||
* parameters:
|
* parameters:
|
||||||
* - in: query
|
* - (query) name {string} Filter by name.
|
||||||
* name: region_id
|
* - (query) region_id {string} Filter by the ID of the region the shipping options belong to.
|
||||||
* schema:
|
* - (query) is_return {boolean} Filter by whether the shipping options are return shipping options.
|
||||||
* type: string
|
* - (query) admin_only {boolean} Filter by whether the shipping options are available for admin users only.
|
||||||
* description: Filter by a region ID.
|
* - (query) q {string} Term used to search shipping options' name.
|
||||||
* - in: query
|
* - (query) order {string} A shipping option field to sort-order the retrieved shipping options by.
|
||||||
* name: is_return
|
* - in: query
|
||||||
* description: Filter by whether the shipping option is used for returns or orders.
|
* name: id
|
||||||
* schema:
|
* style: form
|
||||||
* type: boolean
|
* explode: false
|
||||||
* - in: query
|
* description: Filter by shipping option IDs.
|
||||||
* name: admin_only
|
* schema:
|
||||||
* schema:
|
* oneOf:
|
||||||
* type: boolean
|
* - type: string
|
||||||
* description: Filter by whether the shipping option is used only by admins or not.
|
* description: ID of the shipping option.
|
||||||
|
* - type: array
|
||||||
|
* items:
|
||||||
|
* type: string
|
||||||
|
* description: ID of a shipping option.
|
||||||
|
* - in: query
|
||||||
|
* name: created_at
|
||||||
|
* description: Filter by a creation date range.
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* lt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than this date
|
||||||
|
* format: date
|
||||||
|
* gt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than this date
|
||||||
|
* format: date
|
||||||
|
* lte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* gte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* - in: query
|
||||||
|
* name: updated_at
|
||||||
|
* description: Filter by an update date range.
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* lt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than this date
|
||||||
|
* format: date
|
||||||
|
* gt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than this date
|
||||||
|
* format: date
|
||||||
|
* lte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* gte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* - in: query
|
||||||
|
* name: deleted_at
|
||||||
|
* description: Filter by a deletion date range.
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* lt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than this date
|
||||||
|
* format: date
|
||||||
|
* gt:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than this date
|
||||||
|
* format: date
|
||||||
|
* lte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates less than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* gte:
|
||||||
|
* type: string
|
||||||
|
* description: filter by dates greater than or equal to this date
|
||||||
|
* format: date
|
||||||
|
* - (query) offset=0 {integer} The number of users to skip when retrieving the shipping options.
|
||||||
|
* - (query) limit=20 {integer} Limit the number of shipping options returned.
|
||||||
|
* - (query) expand {string} Comma-separated relations that should be expanded in the returned shipping options.
|
||||||
|
* - (query) fields {string} Comma-separated fields that should be included in the returned shipping options.
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
* method: list
|
* method: list
|
||||||
* queryParams: AdminGetShippingOptionsParams
|
* queryParams: AdminGetShippingOptionsParams
|
||||||
@@ -103,37 +186,60 @@ import { validator } from "../../../../utils/validator"
|
|||||||
* "500":
|
* "500":
|
||||||
* $ref: "#/components/responses/500_error"
|
* $ref: "#/components/responses/500_error"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req: Request, res: Response) => {
|
||||||
const validatedParams = await validator(
|
const optionService: ShippingOptionService = req.scope.resolve(
|
||||||
AdminGetShippingOptionsParams,
|
"shippingOptionService"
|
||||||
req.query
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const optionService = req.scope.resolve("shippingOptionService")
|
|
||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
const [data, count] = await optionService.listAndCount(validatedParams, {
|
|
||||||
select: defaultFields,
|
const listConfig = req.listConfig
|
||||||
relations: defaultRelations,
|
const filterableFields = req.filterableFields
|
||||||
})
|
|
||||||
|
const [data, count] = await optionService.listAndCount(
|
||||||
|
filterableFields,
|
||||||
|
listConfig
|
||||||
|
)
|
||||||
|
|
||||||
const options = await pricingService.setShippingOptionPrices(data)
|
const options = await pricingService.setShippingOptionPrices(data)
|
||||||
|
|
||||||
res.status(200).json({ shipping_options: options, count })
|
res.status(200).json({
|
||||||
|
shipping_options: options,
|
||||||
|
count,
|
||||||
|
offset: listConfig.skip,
|
||||||
|
limit: listConfig.take,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters used to filter the retrieved shipping options.
|
* Parameters used to filter the retrieved shipping options.
|
||||||
*/
|
*/
|
||||||
export class AdminGetShippingOptionsParams {
|
export class AdminGetShippingOptionsParams extends extendedFindParamsMixin({
|
||||||
|
limit: 50,
|
||||||
|
offset: 0,
|
||||||
|
}) {
|
||||||
/**
|
/**
|
||||||
* Filter shipping options by the ID of the region they belong to.
|
* IDs to filter shipping options by.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsType([String, [String]])
|
||||||
|
id?: string | string[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name to filter shipping options by.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
name?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter by a region ID.
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
region_id?: string
|
region_id?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter shipping options by whether they're return shipping options.
|
* Filter by whether the shipping option is used for returns or orders.
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@@ -141,10 +247,62 @@ export class AdminGetShippingOptionsParams {
|
|||||||
is_return?: boolean
|
is_return?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter shipping options by whether they're available for admin users only.
|
* Filter by whether the shipping options are available for admin users only.
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@Transform(({ value }) => optionalBooleanMapper.get(value))
|
@Transform(({ value }) => optionalBooleanMapper.get(value))
|
||||||
admin_only?: boolean
|
admin_only?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter shipping options by a search query.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
q?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
order?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date filters to apply on shipping options' `created_at` field.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => DateComparisonOperator)
|
||||||
|
created_at?: DateComparisonOperator
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date filters to apply on shipping options' `updated_at` field.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => DateComparisonOperator)
|
||||||
|
updated_at?: DateComparisonOperator
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date filters to apply on shipping options' `deleted_at` field.
|
||||||
|
*/
|
||||||
|
@ValidateNested()
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => DateComparisonOperator)
|
||||||
|
deleted_at?: DateComparisonOperator
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comma-separated fields that should be included in the returned shipping options.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
fields?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comma-separated relations that should be expanded in the returned shipping options.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
expand?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ import {
|
|||||||
IsString,
|
IsString,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { defaultFields, defaultRelations } from "."
|
import {
|
||||||
|
shippingOptionsDefaultFields,
|
||||||
|
shippingOptionsDefaultRelations,
|
||||||
|
} from "."
|
||||||
|
|
||||||
|
import { Type } from "class-transformer"
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager } from "typeorm"
|
||||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
import { ShippingOptionPriceType } from "../../../../models"
|
import { ShippingOptionPriceType } from "../../../../models"
|
||||||
import { ShippingOptionService } from "../../../../services"
|
import { ShippingOptionService } from "../../../../services"
|
||||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
|
||||||
import { Type } from "class-transformer"
|
|
||||||
import { UpdateShippingOptionInput } from "../../../../types/shipping-options"
|
import { UpdateShippingOptionInput } from "../../../../types/shipping-options"
|
||||||
|
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,8 +155,8 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const data = await optionService.retrieve(option_id, {
|
const data = await optionService.retrieve(option_id, {
|
||||||
select: defaultFields,
|
select: shippingOptionsDefaultFields,
|
||||||
relations: defaultRelations,
|
relations: shippingOptionsDefaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).json({ shipping_option: data })
|
res.status(200).json({ shipping_option: data })
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe("GET /admin/users", () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
order: { created_at: "DESC" },
|
order: { created_at: "DESC" },
|
||||||
skip: 0,
|
skip: 0,
|
||||||
take: 20,
|
take: 50,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,13 +16,25 @@ import { IsType } from "../../../../utils"
|
|||||||
* description: "Retrieves a list of users. The users can be filtered by fields such as `q` or `email`. The users can also be sorted or paginated."
|
* description: "Retrieves a list of users. The users can be filtered by fields such as `q` or `email`. The users can also be sorted or paginated."
|
||||||
* x-authenticated: true
|
* x-authenticated: true
|
||||||
* parameters:
|
* parameters:
|
||||||
* - (query) id {string} Filter by a user ID.
|
|
||||||
* - (query) email {string} Filter by email.
|
* - (query) email {string} Filter by email.
|
||||||
* - (query) first_name {string} Filter by first name.
|
* - (query) first_name {string} Filter by first name.
|
||||||
* - (query) last_name {string} Filter by last name.
|
* - (query) last_name {string} Filter by last name.
|
||||||
* - (query) q {string} term used to search users' first name, last name, and email.
|
* - (query) q {string} Term used to search users' first name, last name, and email.
|
||||||
* - (query) order {string} A user field to sort-order the retrieved users by.
|
* - (query) order {string} A user field to sort-order the retrieved users by.
|
||||||
* - in: query
|
* - in: query
|
||||||
|
* name: id
|
||||||
|
* style: form
|
||||||
|
* explode: false
|
||||||
|
* description: Filter by user IDs.
|
||||||
|
* schema:
|
||||||
|
* oneOf:
|
||||||
|
* - type: string
|
||||||
|
* description: ID of the user.
|
||||||
|
* - type: array
|
||||||
|
* items:
|
||||||
|
* type: string
|
||||||
|
* description: ID of a user.
|
||||||
|
* - in: query
|
||||||
* name: created_at
|
* name: created_at
|
||||||
* description: Filter by a creation date range.
|
* description: Filter by a creation date range.
|
||||||
* schema:
|
* schema:
|
||||||
@@ -90,7 +102,6 @@ import { IsType } from "../../../../utils"
|
|||||||
* format: date
|
* format: date
|
||||||
* - (query) offset=0 {integer} The number of users to skip when retrieving the users.
|
* - (query) offset=0 {integer} The number of users to skip when retrieving the users.
|
||||||
* - (query) limit=20 {integer} Limit the number of users returned.
|
* - (query) limit=20 {integer} Limit the number of users returned.
|
||||||
* - (query) expand {string} Comma-separated relations that should be expanded in the returned users.
|
|
||||||
* - (query) fields {string} Comma-separated fields that should be included in the returned users.
|
* - (query) fields {string} Comma-separated fields that should be included in the returned users.
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
* method: list
|
* method: list
|
||||||
@@ -181,7 +192,10 @@ export default async (req: Request, res: Response) => {
|
|||||||
/**
|
/**
|
||||||
* Parameters used to filter and configure the pagination of the retrieved users.
|
* Parameters used to filter and configure the pagination of the retrieved users.
|
||||||
*/
|
*/
|
||||||
export class AdminGetUsersParams extends extendedFindParamsMixin() {
|
export class AdminGetUsersParams extends extendedFindParamsMixin({
|
||||||
|
limit: 50,
|
||||||
|
offset: 0,
|
||||||
|
}) {
|
||||||
/**
|
/**
|
||||||
* IDs to filter users by.
|
* IDs to filter users by.
|
||||||
*/
|
*/
|
||||||
@@ -254,4 +268,11 @@ export class AdminGetUsersParams extends extendedFindParamsMixin() {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(UserRole, { each: true })
|
@IsEnum(UserRole, { each: true })
|
||||||
role?: UserRole
|
role?: UserRole
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comma-separated fields that should be included in the returned users.
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
fields?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { FlagRouter, promiseAll } from "@medusajs/utils"
|
||||||
|
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||||
import {
|
import {
|
||||||
Cart,
|
Cart,
|
||||||
Order,
|
Order,
|
||||||
@@ -6,6 +8,7 @@ import {
|
|||||||
ShippingOptionPriceType,
|
ShippingOptionPriceType,
|
||||||
ShippingOptionRequirement,
|
ShippingOptionRequirement,
|
||||||
} from "../models"
|
} from "../models"
|
||||||
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import {
|
import {
|
||||||
CreateShippingMethodDto,
|
CreateShippingMethodDto,
|
||||||
CreateShippingOptionInput,
|
CreateShippingOptionInput,
|
||||||
@@ -14,19 +17,16 @@ import {
|
|||||||
ValidatePriceTypeAndAmountInput,
|
ValidatePriceTypeAndAmountInput,
|
||||||
ValidateRequirementTypeInput,
|
ValidateRequirementTypeInput,
|
||||||
} from "../types/shipping-options"
|
} from "../types/shipping-options"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
|
||||||
import { FlagRouter, promiseAll } from "@medusajs/utils"
|
|
||||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
|
||||||
import { buildQuery, isString, setMetadata } from "../utils"
|
import { buildQuery, isString, setMetadata } from "../utils"
|
||||||
|
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager, FindOptionsWhere, ILike } from "typeorm"
|
||||||
import FulfillmentProviderService from "./fulfillment-provider"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import RegionService from "./region"
|
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
import { ShippingMethodRepository } from "../repositories/shipping-method"
|
import { ShippingMethodRepository } from "../repositories/shipping-method"
|
||||||
import { ShippingOptionRepository } from "../repositories/shipping-option"
|
import { ShippingOptionRepository } from "../repositories/shipping-option"
|
||||||
import { ShippingOptionRequirementRepository } from "../repositories/shipping-option-requirement"
|
import { ShippingOptionRequirementRepository } from "../repositories/shipping-option-requirement"
|
||||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
import FulfillmentProviderService from "./fulfillment-provider"
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import RegionService from "./region"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -145,12 +145,31 @@ class ShippingOptionService extends TransactionBaseService {
|
|||||||
* @return {Promise} the result of the find operation
|
* @return {Promise} the result of the find operation
|
||||||
*/
|
*/
|
||||||
async list(
|
async list(
|
||||||
selector: Selector<ShippingOption>,
|
selector: Selector<ShippingOption> & { q?: string } = {},
|
||||||
config: FindConfig<ShippingOption> = { skip: 0, take: 50 }
|
config: FindConfig<ShippingOption> = { skip: 0, take: 50 }
|
||||||
): Promise<ShippingOption[]> {
|
): Promise<ShippingOption[]> {
|
||||||
const optRepo = this.activeManager_.withRepository(this.optionRepository_)
|
const optRepo = this.activeManager_.withRepository(this.optionRepository_)
|
||||||
|
|
||||||
|
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<ShippingOption>
|
||||||
|
delete where.name
|
||||||
|
|
||||||
|
query.where = [
|
||||||
|
{
|
||||||
|
...where,
|
||||||
|
name: ILike(`%${q}%`),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
return optRepo.find(query)
|
return optRepo.find(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,12 +179,31 @@ class ShippingOptionService extends TransactionBaseService {
|
|||||||
* @return the result of the find operation
|
* @return the result of the find operation
|
||||||
*/
|
*/
|
||||||
async listAndCount(
|
async listAndCount(
|
||||||
selector: Selector<ShippingOption>,
|
selector: Selector<ShippingOption> & { q?: string } = {},
|
||||||
config: FindConfig<ShippingOption> = { skip: 0, take: 50 }
|
config: FindConfig<ShippingOption> = { skip: 0, take: 50 }
|
||||||
): Promise<[ShippingOption[], number]> {
|
): Promise<[ShippingOption[], number]> {
|
||||||
const optRepo = this.activeManager_.withRepository(this.optionRepository_)
|
const optRepo = this.activeManager_.withRepository(this.optionRepository_)
|
||||||
|
|
||||||
|
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<ShippingOption>
|
||||||
|
delete where.name
|
||||||
|
|
||||||
|
query.where = [
|
||||||
|
{
|
||||||
|
...where,
|
||||||
|
name: ILike(`%${q}%`),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
return await optRepo.findAndCount(query)
|
return await optRepo.findAndCount(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class UserService extends TransactionBaseService {
|
|||||||
*/
|
*/
|
||||||
async list(
|
async list(
|
||||||
selector: Selector<FilterableUserProps> & { q?: string } = {},
|
selector: Selector<FilterableUserProps> & { q?: string } = {},
|
||||||
config: FindConfig<FilterableUserProps> = { skip: 0, take: 20 }
|
config: FindConfig<FilterableUserProps> = { skip: 0, take: 50 }
|
||||||
): Promise<User[]> {
|
): Promise<User[]> {
|
||||||
const userRepo = this.activeManager_.withRepository(this.userRepository_)
|
const userRepo = this.activeManager_.withRepository(this.userRepository_)
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ class UserService extends TransactionBaseService {
|
|||||||
|
|
||||||
async listAndCount(
|
async listAndCount(
|
||||||
selector: Selector<FilterableUserProps> & { q?: string } = {},
|
selector: Selector<FilterableUserProps> & { q?: string } = {},
|
||||||
config: FindConfig<FilterableUserProps> = { skip: 0, take: 20 }
|
config: FindConfig<FilterableUserProps> = { skip: 0, take: 50 }
|
||||||
) {
|
) {
|
||||||
const userRepo = this.activeManager_.withRepository(this.userRepository_)
|
const userRepo = this.activeManager_.withRepository(this.userRepository_)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user