- );
-};
+ )
+}
diff --git a/packages/admin-next/dashboard/src/routes/discounts/list/loader.ts b/packages/admin-next/dashboard/src/routes/discounts/list/loader.ts
new file mode 100644
index 0000000000..026655de47
--- /dev/null
+++ b/packages/admin-next/dashboard/src/routes/discounts/list/loader.ts
@@ -0,0 +1,24 @@
+import { QueryClient } from "@tanstack/react-query"
+
+import { Response } from "@medusajs/medusa-js"
+import { AdminDiscountsListRes } from "@medusajs/medusa"
+import { adminDiscountKeys } from "medusa-react"
+
+import { medusa, queryClient } from "../../../lib/medusa"
+
+const discountsListQuery = () => ({
+ queryKey: adminDiscountKeys.list({ limit: 20, offset: 0 }),
+ queryFn: async () => medusa.admin.discounts.list({ limit: 20, offset: 0 }),
+})
+
+export const discountsLoader = (client: QueryClient) => {
+ return async () => {
+ const query = discountsListQuery()
+
+ return (
+ queryClient.getQueryData>(
+ query.queryKey
+ ) ?? (await client.fetchQuery(query))
+ )
+ }
+}
diff --git a/packages/generated/client-types/src/lib/models/AdminGetDiscountsParams.ts b/packages/generated/client-types/src/lib/models/AdminGetDiscountsParams.ts
index baf5329143..428a128704 100644
--- a/packages/generated/client-types/src/lib/models/AdminGetDiscountsParams.ts
+++ b/packages/generated/client-types/src/lib/models/AdminGetDiscountsParams.ts
@@ -41,4 +41,50 @@ export interface AdminGetDiscountsParams {
* Comma-separated relations that should be expanded in each returned discount.
*/
expand?: string
+ /**
+ * A discount field to sort-order the retrieved discounts by.
+ */
+ order?: 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
+ }
}
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 bce231e7c2..1a786920dd 100644
--- a/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts
+++ b/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts
@@ -7,7 +7,10 @@ import {
import { Transform, Type } from "class-transformer"
import { AdminGetDiscountsDiscountRuleParams } from "../../../../types/discount"
-import { extendedFindParamsMixin } from "../../../../types/common"
+import {
+ DateComparisonOperator,
+ extendedFindParamsMixin,
+} from "../../../../types/common"
import { Request, Response } from "express"
import { DiscountService } from "../../../../services"
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
@@ -39,6 +42,51 @@ import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
* - (query) limit=20 {number} The number of discounts to return
* - (query) offset=0 {number} The number of discounts to skip when retrieving the discounts.
* - (query) expand {string} Comma-separated relations that should be expanded in each returned discount.
+ * - (query) order {string} A discount field to sort-order the retrieved discounts by.
+ * - 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
* x-codegen:
* method: list
* queryParams: AdminGetDiscountsParams
@@ -167,4 +215,27 @@ export class AdminGetDiscountsParams extends extendedFindParamsMixin({
@IsOptional()
@Transform(({ value }) => optionalBooleanMapper.get(value))
is_disabled?: boolean
+
+ /**
+ * Date filters to apply on the discounts' `created_at` date.
+ */
+ @IsOptional()
+ @ValidateNested()
+ @Type(() => DateComparisonOperator)
+ created_at?: DateComparisonOperator
+
+ /**
+ * Date filters to apply on the discounts' `updated_at` date.
+ */
+ @IsOptional()
+ @ValidateNested()
+ @Type(() => DateComparisonOperator)
+ updated_at?: DateComparisonOperator
+
+ /**
+ * 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 `-`.
+ */
+ @IsString()
+ @IsOptional()
+ order?: string
}
diff --git a/packages/medusa/src/types/discount.ts b/packages/medusa/src/types/discount.ts
index a22f1bd89c..d54a7d07b4 100644
--- a/packages/medusa/src/types/discount.ts
+++ b/packages/medusa/src/types/discount.ts
@@ -18,6 +18,7 @@ import {
import { optionalBooleanMapper } from "../utils/validators/is-boolean"
import { IsType } from "../utils/validators/is-type"
import { ExactlyOne } from "./validators/exactly-one"
+import { DateComparisonOperator } from "./common"
export type QuerySelector = {
q?: string
@@ -46,6 +47,16 @@ export class FilterableDiscountProps {
@IsOptional()
@Type(() => AdminGetDiscountsDiscountRuleParams)
rule?: AdminGetDiscountsDiscountRuleParams
+
+ @IsOptional()
+ @ValidateNested()
+ @Type(() => DateComparisonOperator)
+ created_at?: DateComparisonOperator
+
+ @IsOptional()
+ @ValidateNested()
+ @Type(() => DateComparisonOperator)
+ updated_at?: DateComparisonOperator
}
/**