Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

ISalesChannelModuleService

The main service interface for the Sales Channel Module.

Methods

create

**create**(data, sharedContext?): Promise<[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)[]>

This method creates sales channels.

Example

const salesChannels = await salesChannelModuleService.create([
{
name: "B2B",
},
])

Parameters

dataCreateSalesChannelDTO[]Required
The sales channels to be created.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO[]>Required
The created sales channels.

**create**(data, sharedContext?): Promise&#60;[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)&#62;

This method creates a sales channel.

Example

const salesChannel = await salesChannelModuleService.create({
name: "B2B",
})

Parameters

The sales channel to be created.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO>Required
The created sales channel.

update

**update**(channelId, data, sharedContext?): Promise&#60;[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)&#62;

This method updates an existing sales channel.

Example

const salesChannel = await salesChannelModuleService.update(
"sc_123",
{
description: "Sales channel for B2B customers",
}
)

Parameters

channelIdstringRequired
The sales channel's ID.
The attributes to update in the sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO>Required
The updated sales channel.

**update**(selector, data, sharedContext?): Promise&#60;[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)[]&#62;

This method updates existing sales channels matching the specified filters

Example

const salesChannels = await salesChannelModuleService.update(
{
name: "B2B",
},
{
description: "Sales channel for B2B customers",
}
)

Parameters

The filters specifying which sales channels to update.
The attributes to update in the sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO[]>Required
The updated sales channels.

upsert

**upsert**(data, sharedContext?): Promise&#60;[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)&#62;

This method updates or creates a sales channel if it doesn't exist.

Example

const salesChannel = await salesChannelModuleService.upsert({
name: "B2B",
})

Parameters

The attributes in the sales channel to be created or updated.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO>Required
The created or updated sales channel.

**upsert**(data, sharedContext?): Promise&#60;[SalesChannelDTO](types.SalesChannelTypes.SalesChannelDTO.mdx)[]&#62;

This method updates or creates sales channels if they don't exist.

Example

const salesChannels = await salesChannelModuleService.upsert([
{
name: "B2B",
},
{
id: "sc_123",
description: "Sales channel for B2B customers",
},
])

Parameters

dataUpsertSalesChannelDTO[]Required
The attributes in the sales channels to be created or updated.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO[]>Required
The created or updated sales channels.

delete

**delete**(ids, sharedContext?): Promise&#60;void&#62;

This method deletes sales channel by their IDs.

Example

await salesChannelModuleService.delete(["sc_123", "sc_321"])

Parameters

idsstring[]Required
The IDs of the sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void>Required
Resolves when the sales channels are deleted successfully.

**delete**(id, sharedContext?): Promise&#60;void&#62;

This method deletes a sales channel by its ID.

Example

await salesChannelModuleService.delete("sc_123")

Parameters

idstringRequired
The ID of the sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void>Required
Resolves when the sales channel is deleted successfully.

retrieve

This method retrieves a sales channel by its ID.

Example

const salesChannel =
await salesChannelModuleService.retrieve("sc_123")

Parameters

idstringRequired
The ID of the sales channel.
The configurations determining how the sales channel is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO>Required
The retrieved sales channel.

list

This method retrieves a paginated list of sales channels based on optional filters and configuration.

Example

To retrieve a list of sales channels using their IDs:

const salesChannels = await salesChannelModuleService.list({
id: ["sc_123", "sc_321"],
})

By default, only the first 15 records are retrieved. You can control pagination by specifying the skip and take properties of the config parameter:

const salesChannels = await salesChannelModuleService.list(
{
id: ["sc_123", "sc_321"],
},
{
take: 20,
skip: 2,
}
)

Parameters

The filters to apply on the retrieved sales channels.
The configurations determining how the sales channel is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<SalesChannelDTO[]>Required
The list of sales channels.

listAndCount

This method retrieves a paginated list of sales channels along with the total count of available sales channels satisfying the provided filters.

Example

To retrieve a list of sales channels using their IDs:

const [salesChannels, count] =
await salesChannelModuleService.listAndCount({
id: ["sc_123", "sc_321"],
})

By default, only the first 15 records are retrieved. You can control pagination by specifying the skip and take properties of the config parameter:

const [salesChannels, count] =
await salesChannelModuleService.listAndCount(
{
id: ["sc_123", "sc_321"],
},
{
take: 20,
skip: 2,
}
)

Parameters

The filters to apply on the retrieved sales channels.
The configurations determining how the sales channel is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a sales channel.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<[SalesChannelDTO[], number]>Required
The list of sales channels along with their total count.

softDelete

This method soft deletes sales channels by their IDs.

Example

await salesChannelModuleService.delete(["sc_123", "sc_321"])

Type Parameters

TReturnableLinkableKeysstringRequired

Parameters

salesChannelIdsstring[]Required
The sales channels' ID.
configSoftDeleteReturn<TReturnableLinkableKeys>
An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void | Record<string, string[]>>Required
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restore

This method restores a soft deleted sales channel by its IDs.

Example

await salesChannelModuleService.restore(["sc_123", "sc_321"])

Type Parameters

TReturnableLinkableKeysstringRequired

Parameters

salesChannelIdsstring[]Required
The list of {summary}
configRestoreReturn<TReturnableLinkableKeys>
Configurations determining which relations to restore along with each of the sales channel. You can pass to its returnLinkableKeys property any of the sales channel's relation attribute names.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void | Record<string, string[]>>Required
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.
Was this section helpful?