---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# SwapService

Handles swaps

## Constructors

### constructor

`**new SwapService**(«destructured»)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "[InjectedProps](../types/InjectedProps.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__container__",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__moduleDeclaration__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "cartService_",
    "type": "[CartService](CartService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customShippingOptionService_",
    "type": "[CustomShippingOptionService](CustomShippingOptionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "eventBus_",
    "type": "[EventBusService](EventBusService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "fulfillmentService_",
    "type": "[FulfillmentService](FulfillmentService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "lineItemAdjustmentService_",
    "type": "[LineItemAdjustmentService](LineItemAdjustmentService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "lineItemService_",
    "type": "[LineItemService](LineItemService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "EntityManager",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "orderService_",
    "type": "[OrderService](OrderService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "paymentProviderService_",
    "type": "[PaymentProviderService](PaymentProviderService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productVariantInventoryService_",
    "type": "[ProductVariantInventoryService](ProductVariantInventoryService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "returnService_",
    "type": "[ReturnService](ReturnService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "shippingOptionService_",
    "type": "[ShippingOptionService](ShippingOptionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "swapRepository_",
    "type": "Repository&#60;[Swap](Swap.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "totalsService_",
    "type": "[TotalsService](TotalsService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| EntityManager",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.created\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.FULFILLMENT_CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.fulfillment_created\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.PAYMENT_CAPTURED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.payment_captured\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.PAYMENT_CAPTURE_FAILED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.payment_capture_failed\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.PAYMENT_COMPLETED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.payment_completed\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.PROCESS_REFUND_FAILED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.process_refund_failed\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.RECEIVED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.received\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.REFUND_PROCESSED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.refund_processed\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.SHIPMENT_CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"swap.shipment_created\"",
    "expandable": false,
    "children": []
  }
]} />

## Accessors

### activeManager\_

`Protected get**activeManager_**(): EntityManager`

#### Returns

EntityManager

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "EntityManager",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

## Methods

### areReturnItemsValid

`Protected **areReturnItemsValid**(returnItems): Promise&#60;boolean&#62;`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "returnItems",
    "type": "[WithRequiredProperty](../types/WithRequiredProperty.mdx)&#60;[Partial](../types/Partial.mdx)&#60;[ReturnItem](ReturnItem.mdx)&#62;, \"item_id\"&#62;[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;boolean&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;boolean&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### atomicPhase\_

`Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;`

Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: EntityManager) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;TResult&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### cancel

`**cancel**(swapId): Promise&#60;[Swap](Swap.mdx)&#62;`

Cancels a given swap if possible. A swap can only be canceled if all
related returns, fulfillments, and payments have been canceled. If a swap
is associated with a refund, it cannot be canceled.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the id of the swap to cancel.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the canceled swap.",
    "expandable": false,
    "children": []
  }
]} />

___

### cancelFulfillment

`**cancelFulfillment**(fulfillmentId): Promise&#60;[Swap](Swap.mdx)&#62;`

Cancels a fulfillment (if related to a swap)

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "fulfillmentId",
    "type": "`string`",
    "description": "the ID of the fulfillment to cancel",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "updated swap",
    "expandable": false,
    "children": []
  }
]} />

___

### create

`**create**(order, returnItems, additionalItems?, returnShipping?, custom?): Promise&#60;[Swap](Swap.mdx)&#62;`

Creates a swap from an order, with given return items, additional items
and an optional return shipping method.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "order",
    "type": "[Order](Order.mdx)",
    "description": "the order to base the swap off",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "returnItems",
    "type": "[WithRequiredProperty](../types/WithRequiredProperty.mdx)&#60;[Partial](../types/Partial.mdx)&#60;[ReturnItem](ReturnItem.mdx)&#62;, \"item_id\"&#62;[]",
    "description": "the items to return in the swap",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "additionalItems",
    "type": "[Pick](../types/Pick.mdx)&#60;[LineItem](LineItem.mdx), \"variant_id\" \\| \"quantity\"&#62;[]",
    "description": "the items to send to the customer",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "returnShipping",
    "type": "`object`",
    "description": "an optional shipping method for returning the returnItems",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "returnShipping.option_id",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "returnShipping.price",
    "type": "`number`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom",
    "type": "`object`",
    "description": "contains relevant custom information. This object may include no\\_notification which will disable sending notification when creating swap. If set, it overrules the attribute inherited from the order",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom.allow_backorder",
    "type": "`boolean`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom.idempotency_key",
    "type": "`string`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom.location_id",
    "type": "`string`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "custom.no_notification",
    "type": "`boolean`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the newly created swap",
    "expandable": false,
    "children": []
  }
]} />

___

### createCart

`**createCart**(swapId, customShippingOptions?, context?): Promise&#60;[Swap](Swap.mdx)&#62;`

Creates a cart from the given swap. The cart can be used to pay
for differences associated with the swap. The swap represented by the
swapId must belong to the order. Fails if there is already a cart on the
swap.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the id of the swap to create the cart from",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customShippingOptions",
    "type": "``{ option_id: string ; price: number  }``[]",
    "description": "the shipping options",
    "optional": false,
    "defaultValue": "[]",
    "expandable": false,
    "children": []
  },
  {
    "name": "context",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "context.sales_channel_id",
    "type": "`string`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the swap with its cart\\_id prop set to the id of the new cart.",
    "expandable": false,
    "children": []
  }
]} />

___

### createFulfillment

`**createFulfillment**(swapId, config?): Promise&#60;[Swap](Swap.mdx)&#62;`

Fulfills the additional items associated with the swap. Will call the
fulfillment providers associated with the shipping methods.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the id of the swap to fulfill,",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[CreateShipmentConfig](../types/CreateShipmentConfig.mdx)",
    "description": "optional configurations, includes optional metadata to attach to the shipment, and a no\\_notification flag.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the updated swap with new status and fulfillments.",
    "expandable": false,
    "children": []
  }
]} />

___

### createShipment

`**createShipment**(swapId, fulfillmentId, trackingLinks?, config?): Promise&#60;[Swap](Swap.mdx)&#62;`

Marks a fulfillment as shipped and attaches tracking numbers.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the id of the swap that has been shipped.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "fulfillmentId",
    "type": "`string`",
    "description": "the id of the specific fulfillment that has been shipped",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "trackingLinks",
    "type": "``{ tracking_number: string  }``[]",
    "description": "the tracking numbers associated with the shipment",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[CreateShipmentConfig](../types/CreateShipmentConfig.mdx)",
    "description": "optional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the updated swap with new fulfillments and status.",
    "expandable": false,
    "children": []
  }
]} />

___

### deleteMetadata

`**deleteMetadata**(swapId, key): Promise&#60;[Swap](Swap.mdx)&#62;`

Dedicated method to delete metadata for a swap.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the order to delete metadata from.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "key",
    "type": "`string`",
    "description": "key for metadata field",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "resolves to the updated result.",
    "expandable": false,
    "children": []
  }
]} />

___

### list

`**list**(selector, config?): Promise&#60;[Swap](Swap.mdx)[]&#62;`

List swaps.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[Selector](../types/Selector.mdx)&#60;[Swap](Swap.mdx)&#62;",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;",
    "description": "the configuration used to find the objects. contains relations, skip, and take.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)[]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

`**listAndCount**(selector, config?): Promise&#60;[[Swap](Swap.mdx)[], number]&#62;`

List swaps.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[Selector](../types/Selector.mdx)&#60;[Swap](Swap.mdx)&#62;",
    "description": "the query object for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;",
    "description": "the configuration used to find the objects. contains relations, skip, and take.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[[Swap](Swap.mdx)[], number]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[Swap](Swap.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the find operation",
    "expandable": false,
    "children": []
  }
]} />

___

### processDifference

`**processDifference**(swapId): Promise&#60;[Swap](Swap.mdx)&#62;`

Process difference for the requested swap.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "id of a swap being processed",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "processed swap",
    "expandable": false,
    "children": []
  }
]} />

___

### registerCartCompletion

`**registerCartCompletion**(swapId): Promise&#60;[Swap](Swap.mdx)&#62;`

Register a cart completion

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "The id of the swap",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "swap related to the cart",
    "expandable": false,
    "children": []
  }
]} />

___

### registerReceived

`**registerReceived**(id): Promise&#60;[Swap](Swap.mdx)&#62;`

Registers the swap return items as received so that they cannot be used
as a part of other swaps/returns.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`any`",
    "description": "the id of the order with the swap.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the resulting order",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

`**retrieve**(swapId, config?): Promise&#60;[Swap](Swap.mdx)&#62;`

Retrieves a swap with the given id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "the id of the swap to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[Omit](../types/Omit.mdx)&#60;[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;, \"select\"&#62; & ``{ select?: string[]  }``",
    "description": "the configuration to retrieve the swap",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the swap",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieveByCartId

`**retrieveByCartId**(cartId, relations?): Promise&#60;[Swap](Swap.mdx)&#62;`

Retrieves a swap based on its associated cart id

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "cartId",
    "type": "`string`",
    "description": "the cart id that the swap's cart has",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "relations",
    "type": "`undefined` \\| `string`[]",
    "description": "the relations to retrieve swap",
    "optional": false,
    "defaultValue": "[]",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the swap",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

`Protected **shouldRetryTransaction_**(err): boolean`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| ``{ code: string  }``",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`boolean`

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### transformQueryForCart

`Protected **transformQueryForCart**(config): [Omit](../types/Omit.mdx)&#60;[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;, "select"&#62; & &#123; select?: string[]  &#125; & &#123; cartRelations: undefined \| string[] ; cartSelects: undefined \| keyof [Cart](Cart.mdx)[]  &#125;`

Transform find config object for retrieval.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "config",
    "type": "[Omit](../types/Omit.mdx)&#60;[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;, \"select\"&#62; & ``{ select?: string[]  }``",
    "description": "parsed swap find config",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[Omit](../types/Omit.mdx)&#60;[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;, "select"&#62; & ``{ select?: string[]  }`` & ``{ cartRelations: undefined \| string[] ; cartSelects: undefined \| keyof [Cart](Cart.mdx)[]  }``

<ParameterTypes parameters={[
  {
    "name": "Omit&#60;FindConfig&#60;Swap&#62;, \"select\"&#62; & &#123; select?: string[]  &#125; & &#123; cartRelations: undefined \\| string[] ; cartSelects: undefined \\| keyof Cart[]  &#125;",
    "type": "[Omit](../types/Omit.mdx)&#60;[FindConfig](../interfaces/FindConfig.mdx)&#60;[Swap](Swap.mdx)&#62;, \"select\"&#62; & ``{ select?: string[]  }`` & ``{ cartRelations: undefined \\| string[] ; cartSelects: undefined \\| keyof [Cart](Cart.mdx)[]  }``",
    "optional": true,
    "defaultValue": "",
    "description": "transformed find swap config",
    "expandable": false,
    "children": []
  }
]} />

___

### update

`**update**(swapId, update): Promise&#60;[Swap](Swap.mdx)&#62;`

Update the swap record.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "swapId",
    "type": "`string`",
    "description": "id of a swap to update",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "update",
    "type": "[Partial](../types/Partial.mdx)&#60;[Swap](Swap.mdx)&#62;",
    "description": "new data",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[Swap](Swap.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[Swap](Swap.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "updated swap record",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

`**withTransaction**(transactionManager?): [SwapService](SwapService.mdx)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "EntityManager",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[SwapService](SwapService.mdx)

<ParameterTypes parameters={[
  {
    "name": "SwapService",
    "type": "[SwapService](SwapService.mdx)",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />
