Skip to content

Commit

Permalink
Fix findInterface to return an actual DeliveryInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Nov 9, 2023
1 parent bf84575 commit e00d351
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
9 changes: 1 addition & 8 deletions packages/api/src/resolvers/type/delivery-provider-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@ export interface DeliveryProviderHelperTypes {
export const DeliveryProvider: DeliveryProviderHelperTypes = {
interface(obj, _, { modules }) {
const Interface = modules.delivery.findInterface(obj);

// TODO: Harmonize with Payment, eliminate double mappings (_id -> key -> _id ...)
if (!Interface) return null;

return {
_id: Interface.key,
label: Interface.label,
version: Interface.version,
};
return Interface;
},

async isActive(deliveryProvider, _, requestContext) {
Expand Down
10 changes: 8 additions & 2 deletions packages/core-delivery/src/module/configureDeliveryModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ export const configureDeliveryModule = async ({

// Delivery Adapter

findInterface: (deliveryProvider) => {
return DeliveryDirector.getAdapter(deliveryProvider.adapterKey);
findInterface: (paymentProvider) => {
const Adapter = DeliveryDirector.getAdapter(paymentProvider.adapterKey);
if (!Adapter) return null;
return {
_id: Adapter.key,
label: Adapter.label,
version: Adapter.version,
};
},

findInterfaces: ({ type }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { UnchainedCore } from '@unchainedshop/types/core.js';
import { Order } from '@unchainedshop/types/orders.js';
import { OrderPricingRowCategory } from '@unchainedshop/types/orders.pricing.js';
import { Locale } from '@unchainedshop/types/common.js';
import { DeliveryInterface } from '@unchainedshop/types/delivery.js';
import formatPrice from './formatPrice.js';
import { formatAddress } from './formatAddress.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/types/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type DeliveryModule = ModuleMutationsWithReturnDoc<DeliveryProvider> & {
}) => IDeliveryPricingSheet;

// Delivery adapter
findInterface: (params: DeliveryProvider) => IDeliveryAdapter;
findInterface: (params: DeliveryProvider) => DeliveryInterface;
findInterfaces: (params: { type: DeliveryProviderType }) => Array<DeliveryInterface>;
findSupported: (
params: { order: Order },
Expand Down

0 comments on commit e00d351

Please sign in to comment.