From ab7fa8ce0e4d01ad4fea605a97f21222a5d504b7 Mon Sep 17 00:00:00 2001 From: fPolic Date: Fri, 13 Dec 2024 14:25:38 +0100 Subject: [PATCH] wip setup endpoint --- .../fulfillment-provider/admin/entities.ts | 8 +++++- .../fulfillment-provider/admin/responses.ts | 10 ++++++- .../src/http/fulfillment-provider/common.ts | 11 ++++++++ .../[id]/options/route.ts | 27 +++++++++++++++++++ .../fulfillment-providers/middlewares.ts | 5 ++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 packages/medusa/src/api/admin/fulfillment-providers/[id]/options/route.ts diff --git a/packages/core/types/src/http/fulfillment-provider/admin/entities.ts b/packages/core/types/src/http/fulfillment-provider/admin/entities.ts index 1f56c491fcd63..fa0f14769e04c 100644 --- a/packages/core/types/src/http/fulfillment-provider/admin/entities.ts +++ b/packages/core/types/src/http/fulfillment-provider/admin/entities.ts @@ -1,3 +1,9 @@ -import { BaseFulfillmentProvider } from "../common" +import { + BaseFulfillmentProvider, + BaseFulfillmentProviderOption, +} from "../common" export interface AdminFulfillmentProvider extends BaseFulfillmentProvider {} + +export interface AdminFulfillmentProviderOption + extends BaseFulfillmentProviderOption {} diff --git a/packages/core/types/src/http/fulfillment-provider/admin/responses.ts b/packages/core/types/src/http/fulfillment-provider/admin/responses.ts index 6d88a194c304d..979700e0e053d 100644 --- a/packages/core/types/src/http/fulfillment-provider/admin/responses.ts +++ b/packages/core/types/src/http/fulfillment-provider/admin/responses.ts @@ -1,5 +1,8 @@ import { PaginatedResponse } from "../../common" -import { AdminFulfillmentProvider } from "./entities" +import { + AdminFulfillmentProvider, + AdminFulfillmentProviderOption, +} from "./entities" export interface AdminFulfillmentProviderListResponse extends PaginatedResponse<{ @@ -8,3 +11,8 @@ export interface AdminFulfillmentProviderListResponse */ fulfillment_providers: AdminFulfillmentProvider[] }> {} + +export interface AdminFulfillmentProviderOptionsListResponse + extends PaginatedResponse<{ + fulfillment_options: AdminFulfillmentProviderOption[] + }> {} diff --git a/packages/core/types/src/http/fulfillment-provider/common.ts b/packages/core/types/src/http/fulfillment-provider/common.ts index a89e79175c6ce..b98caccc746a9 100644 --- a/packages/core/types/src/http/fulfillment-provider/common.ts +++ b/packages/core/types/src/http/fulfillment-provider/common.ts @@ -8,3 +8,14 @@ export interface BaseFulfillmentProvider { */ is_enabled: boolean } + +export interface BaseFulfillmentProviderOption { + /** + * The fulfillment provider option's ID. + */ + id: string + /** + * Whether the fulfillment provider option can be used for returns. + */ + is_returned: boolean +} diff --git a/packages/medusa/src/api/admin/fulfillment-providers/[id]/options/route.ts b/packages/medusa/src/api/admin/fulfillment-providers/[id]/options/route.ts new file mode 100644 index 0000000000000..5b5b1ec946fca --- /dev/null +++ b/packages/medusa/src/api/admin/fulfillment-providers/[id]/options/route.ts @@ -0,0 +1,27 @@ +import { + AdminFulfillmentProviderOption, + HttpTypes, +} from "@medusajs/framework/types" +import { Modules } from "@medusajs/framework/utils" +import { + AuthenticatedMedusaRequest, + MedusaResponse, +} from "@medusajs/framework/http" + +export const GET = async ( + req: AuthenticatedMedusaRequest, + res: MedusaResponse +) => { + const fulfillmentProviderService = req.scope.resolve(Modules.FULFILLMENT) + + const fulfillmentOptions = + await fulfillmentProviderService.retrieveFulfillmentOptions(req.params.id) + + res.json({ + fulfillment_options: + fulfillmentOptions as unknown as AdminFulfillmentProviderOption[], + count: fulfillmentOptions.length, + limit: fulfillmentOptions.length, + offset: 0, + }) +} diff --git a/packages/medusa/src/api/admin/fulfillment-providers/middlewares.ts b/packages/medusa/src/api/admin/fulfillment-providers/middlewares.ts index 82b3a22d47db1..ea5875f280997 100644 --- a/packages/medusa/src/api/admin/fulfillment-providers/middlewares.ts +++ b/packages/medusa/src/api/admin/fulfillment-providers/middlewares.ts @@ -20,4 +20,9 @@ export const adminFulfillmentProvidersRoutesMiddlewares: MiddlewareRoute[] = [ }), ], }, + { + method: ["GET"], + matcher: "/admin/fulfillment-providers/:id/options", + middlewares: [], + }, ]