feat(medusa,types): add fulfillment provider list api (#7124)
* feat(medusa,types): add fulfillment provider list api * chore: remove timestamps
This commit is contained in:
1 parent
0df523594f
commit
38c971f111
11 files changed
+178
-2
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa,types): add fulfillment provider list api
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
|
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||||
|
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||||
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
|
|
||||||
|
jest.setTimeout(100000)
|
||||||
|
|
||||||
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||||
|
const adminHeaders = {
|
||||||
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
|
}
|
||||||
|
|
||||||
|
medusaIntegrationTestRunner({
|
||||||
|
env,
|
||||||
|
testSuite: ({ getContainer, api, dbConnection }) => {
|
||||||
|
let service: IFulfillmentModuleService
|
||||||
|
let container
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
container = getContainer()
|
||||||
|
service = container.resolve(ModuleRegistrationName.FULFILLMENT)
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createAdminUser(dbConnection, adminHeaders, container)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /admin/fulfillment-providers", () => {
|
||||||
|
it("should list all fulfillment providers", async () => {
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/fulfillment-providers`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.fulfillment_providers).toEqual([
|
||||||
|
{ id: "manual_test-provider", is_enabled: true },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -3,6 +3,7 @@ import { ModuleJoinerConfig } from "@medusajs/types"
|
|||||||
import { MapToConfig } from "@medusajs/utils"
|
import { MapToConfig } from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
Fulfillment,
|
Fulfillment,
|
||||||
|
FulfillmentProvider,
|
||||||
FulfillmentSet,
|
FulfillmentSet,
|
||||||
GeoZone,
|
GeoZone,
|
||||||
ServiceZone,
|
ServiceZone,
|
||||||
@@ -59,6 +60,13 @@ export const joinerConfig: ModuleJoinerConfig = {
|
|||||||
methodSuffix: "Fulfillments",
|
methodSuffix: "Fulfillments",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: ["fulfillment_provider", "fulfillment_providers"],
|
||||||
|
args: {
|
||||||
|
entity: FulfillmentProvider.name,
|
||||||
|
methodSuffix: "FulfillmentProviders",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: ["service_zone", "service_zones"],
|
name: ["service_zone", "service_zones"],
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -20,15 +20,16 @@ import {
|
|||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
|
Modules,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
arrayDifference,
|
arrayDifference,
|
||||||
getSetDifference,
|
getSetDifference,
|
||||||
isString,
|
isString,
|
||||||
promiseAll,
|
promiseAll,
|
||||||
Modules
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
Fulfillment,
|
Fulfillment,
|
||||||
|
FulfillmentProvider,
|
||||||
FulfillmentSet,
|
FulfillmentSet,
|
||||||
GeoZone,
|
GeoZone,
|
||||||
ServiceZone,
|
ServiceZone,
|
||||||
@@ -39,8 +40,8 @@ import {
|
|||||||
} from "@models"
|
} from "@models"
|
||||||
import { isContextValid, validateRules } from "@utils"
|
import { isContextValid, validateRules } from "@utils"
|
||||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||||
import FulfillmentProviderService from "./fulfillment-provider"
|
|
||||||
import { UpdateShippingOptionsInput } from "../types/service"
|
import { UpdateShippingOptionsInput } from "../types/service"
|
||||||
|
import FulfillmentProviderService from "./fulfillment-provider"
|
||||||
|
|
||||||
const generateMethodForModels = [
|
const generateMethodForModels = [
|
||||||
ServiceZone,
|
ServiceZone,
|
||||||
@@ -49,6 +50,7 @@ const generateMethodForModels = [
|
|||||||
ShippingProfile,
|
ShippingProfile,
|
||||||
ShippingOptionRule,
|
ShippingOptionRule,
|
||||||
ShippingOptionType,
|
ShippingOptionType,
|
||||||
|
FulfillmentProvider,
|
||||||
// Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose8
|
// Not adding Fulfillment to not auto generate the methods under the hood and only provide the methods we want to expose8
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -86,6 +88,7 @@ export default class FulfillmentModuleService<
|
|||||||
ShippingProfile: { dto: FulfillmentTypes.ShippingProfileDTO }
|
ShippingProfile: { dto: FulfillmentTypes.ShippingProfileDTO }
|
||||||
ShippingOptionRule: { dto: FulfillmentTypes.ShippingOptionRuleDTO }
|
ShippingOptionRule: { dto: FulfillmentTypes.ShippingOptionRuleDTO }
|
||||||
ShippingOptionType: { dto: FulfillmentTypes.ShippingOptionTypeDTO }
|
ShippingOptionType: { dto: FulfillmentTypes.ShippingOptionTypeDTO }
|
||||||
|
FulfillmentProvider: { dto: FulfillmentTypes.FulfillmentProviderDTO }
|
||||||
}
|
}
|
||||||
>(FulfillmentSet, generateMethodForModels, entityNameToLinkableKeysMap)
|
>(FulfillmentSet, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||||
implements IFulfillmentModuleService
|
implements IFulfillmentModuleService
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { MiddlewareRoute } from "../../../types/middlewares"
|
||||||
|
import { authenticate } from "../../../utils/authenticate-middleware"
|
||||||
|
import { validateAndTransformQuery } from "../../utils/validate-query"
|
||||||
|
import * as QueryConfig from "./query-config"
|
||||||
|
import { AdminFulfillmentProvidersParams } from "./validators"
|
||||||
|
|
||||||
|
export const adminFulfillmentProvidersRoutesMiddlewares: MiddlewareRoute[] = [
|
||||||
|
{
|
||||||
|
method: "ALL",
|
||||||
|
matcher: "/admin/fulfillment-providers*",
|
||||||
|
middlewares: [authenticate("admin", ["session", "bearer", "api-key"])],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: ["GET"],
|
||||||
|
matcher: "/admin/fulfillment-providers",
|
||||||
|
middlewares: [
|
||||||
|
validateAndTransformQuery(
|
||||||
|
AdminFulfillmentProvidersParams,
|
||||||
|
QueryConfig.listTransformQueryConfig
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export const defaultAdminFulfillmentProvidersFields = ["id", "is_enabled"]
|
||||||
|
|
||||||
|
export const retrieveTransformQueryConfig = {
|
||||||
|
defaults: defaultAdminFulfillmentProvidersFields,
|
||||||
|
isList: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const listTransformQueryConfig = {
|
||||||
|
...retrieveTransformQueryConfig,
|
||||||
|
isList: true,
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import {
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
remoteQueryObjectFromString,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {
|
||||||
|
AuthenticatedMedusaRequest,
|
||||||
|
MedusaResponse,
|
||||||
|
} from "../../../types/routing"
|
||||||
|
import { AdminFulfillmentProvidersParamsType } from "./validators"
|
||||||
|
|
||||||
|
export const GET = async (
|
||||||
|
req: AuthenticatedMedusaRequest<AdminFulfillmentProvidersParamsType>,
|
||||||
|
res: MedusaResponse
|
||||||
|
) => {
|
||||||
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
entryPoint: "fulfillment_provider",
|
||||||
|
variables: {
|
||||||
|
filters: req.filterableFields,
|
||||||
|
...req.remoteQueryConfig.pagination,
|
||||||
|
},
|
||||||
|
fields: req.remoteQueryConfig.fields,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { rows: fulfillment_providers, metadata } = await remoteQuery(
|
||||||
|
queryObject
|
||||||
|
)
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
fulfillment_providers,
|
||||||
|
count: metadata.count,
|
||||||
|
offset: metadata.skip,
|
||||||
|
limit: metadata.take,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
import { createSelectParams } from "../../utils/validators"
|
||||||
|
|
||||||
|
export type AdminFulfillmentProvidersParamsType = z.infer<
|
||||||
|
typeof AdminFulfillmentProvidersParams
|
||||||
|
>
|
||||||
|
export const AdminFulfillmentProvidersParams = createSelectParams()
|
||||||
@@ -6,6 +6,7 @@ import { adminCurrencyRoutesMiddlewares } from "./admin/currencies/middlewares"
|
|||||||
import { adminCustomerGroupRoutesMiddlewares } from "./admin/customer-groups/middlewares"
|
import { adminCustomerGroupRoutesMiddlewares } from "./admin/customer-groups/middlewares"
|
||||||
import { adminCustomerRoutesMiddlewares } from "./admin/customers/middlewares"
|
import { adminCustomerRoutesMiddlewares } from "./admin/customers/middlewares"
|
||||||
import { adminDraftOrderRoutesMiddlewares } from "./admin/draft-orders/middlewares"
|
import { adminDraftOrderRoutesMiddlewares } from "./admin/draft-orders/middlewares"
|
||||||
|
import { adminFulfillmentProvidersRoutesMiddlewares } from "./admin/fulfillment-providers/middlewares"
|
||||||
import { adminFulfillmentSetsRoutesMiddlewares } from "./admin/fulfillment-sets/middlewares"
|
import { adminFulfillmentSetsRoutesMiddlewares } from "./admin/fulfillment-sets/middlewares"
|
||||||
import { adminFulfillmentsRoutesMiddlewares } from "./admin/fulfillments/middlewares"
|
import { adminFulfillmentsRoutesMiddlewares } from "./admin/fulfillments/middlewares"
|
||||||
import { adminInventoryRoutesMiddlewares } from "./admin/inventory-items/middlewares"
|
import { adminInventoryRoutesMiddlewares } from "./admin/inventory-items/middlewares"
|
||||||
@@ -78,5 +79,6 @@ export const config: MiddlewaresConfig = {
|
|||||||
...adminReservationRoutesMiddlewares,
|
...adminReservationRoutesMiddlewares,
|
||||||
...adminShippingProfilesMiddlewares,
|
...adminShippingProfilesMiddlewares,
|
||||||
...adminFulfillmentsRoutesMiddlewares,
|
...adminFulfillmentsRoutesMiddlewares,
|
||||||
|
...adminFulfillmentProvidersRoutesMiddlewares,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||||
import { ShippingOptionDTO } from "./shipping-option"
|
import { ShippingOptionDTO } from "./shipping-option"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,3 +40,14 @@ export interface FulfillmentProviderDTO {
|
|||||||
*/
|
*/
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The filters to apply on the retrieved fulfillment providers.
|
||||||
|
*/
|
||||||
|
export interface FilterableFulfillmentProviderProps
|
||||||
|
extends BaseFilterable<FilterableFulfillmentProviderProps> {
|
||||||
|
/**
|
||||||
|
* The IDs to filter the provider by.
|
||||||
|
*/
|
||||||
|
id?: string | string[] | OperatorMap<string | string[]>
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import { IModuleService } from "../modules-sdk"
|
|||||||
import { Context } from "../shared-context"
|
import { Context } from "../shared-context"
|
||||||
import {
|
import {
|
||||||
FilterableFulfillmentProps,
|
FilterableFulfillmentProps,
|
||||||
|
FilterableFulfillmentProviderProps,
|
||||||
FilterableFulfillmentSetProps,
|
FilterableFulfillmentSetProps,
|
||||||
FilterableGeoZoneProps,
|
FilterableGeoZoneProps,
|
||||||
FilterableServiceZoneProps,
|
FilterableServiceZoneProps,
|
||||||
@@ -13,6 +14,7 @@ import {
|
|||||||
FilterableShippingOptionTypeProps,
|
FilterableShippingOptionTypeProps,
|
||||||
FilterableShippingProfileProps,
|
FilterableShippingProfileProps,
|
||||||
FulfillmentDTO,
|
FulfillmentDTO,
|
||||||
|
FulfillmentProviderDTO,
|
||||||
FulfillmentSetDTO,
|
FulfillmentSetDTO,
|
||||||
GeoZoneDTO,
|
GeoZoneDTO,
|
||||||
ServiceZoneDTO,
|
ServiceZoneDTO,
|
||||||
@@ -2498,4 +2500,29 @@ export interface IFulfillmentModuleService extends IModuleService {
|
|||||||
shippingOptionId: string,
|
shippingOptionId: string,
|
||||||
context: Record<string, unknown>
|
context: Record<string, unknown>
|
||||||
): Promise<boolean>
|
): Promise<boolean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method retrieves a paginated list of fulfillment providers based on optional filters and configuration.
|
||||||
|
*
|
||||||
|
* @param {FilterableFulfillmentProviderProps} filters - The filters to apply on the retrieved fulfillment providers.
|
||||||
|
* @param {FindConfig<FulfillmentProviderDTO>} config - The configurations determining how the fulfillment provider is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
|
* attributes or relations associated with a fulfillment provider.
|
||||||
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
|
* @returns {Promise<FulfillmentProviderDTO[]>} The list of fulfillment providers.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* To retrieve a list of fulfillment providers using their IDs:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const providers = await fulfillmentModuleService.listFulfillmentProviders({
|
||||||
|
* id: ["sepro_123", "sepro_321"],
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
listFulfillmentProviders(
|
||||||
|
filters?: FilterableFulfillmentProviderProps,
|
||||||
|
config?: FindConfig<FulfillmentProviderDTO>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<FulfillmentProviderDTO[]>
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user