feat(medusa, medusa-js, medusa-react): Implement Sales Channel creation (#1795)
This commit is contained in:
1 parent
428a801293
commit
0d1624cf6a
13 files changed
+270
-56
No files matched your search
@@ -12,6 +12,16 @@ Object {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`sales channels POST /admin/sales-channels successfully creates a sales channel 1`] = `
|
||||||
|
Object {
|
||||||
|
"sales_channel": ObjectContaining {
|
||||||
|
"description": "sales channel description",
|
||||||
|
"is_disabled": false,
|
||||||
|
"name": "sales channel name",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`sales channels POST /admin/sales-channels/:id updates sales channel properties 1`] = `
|
exports[`sales channels POST /admin/sales-channels/:id updates sales channel properties 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"created_at": Any<String>,
|
"created_at": Any<String>,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ describe("sales channels", () => {
|
|||||||
const [process, connection] = await startServerWithEnvironment({
|
const [process, connection] = await startServerWithEnvironment({
|
||||||
cwd,
|
cwd,
|
||||||
env: { MEDUSA_FF_SALES_CHANNELS: true },
|
env: { MEDUSA_FF_SALES_CHANNELS: true },
|
||||||
|
verbose: false,
|
||||||
})
|
})
|
||||||
dbConnection = connection
|
dbConnection = connection
|
||||||
medusaProcess = process
|
medusaProcess = process
|
||||||
@@ -38,14 +39,6 @@ describe("sales channels", () => {
|
|||||||
medusaProcess.kill()
|
medusaProcess.kill()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("GET /admin/sales-channels", () => {
|
|
||||||
it("is true", () => {
|
|
||||||
// dummy test to ensure test suite passes
|
|
||||||
expect(true).toBeTruthy()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe("POST /admin/sales-channels", () => {})
|
|
||||||
|
|
||||||
describe("GET /admin/sales-channels/:id", () => {
|
describe("GET /admin/sales-channels/:id", () => {
|
||||||
let salesChannel
|
let salesChannel
|
||||||
|
|
||||||
@@ -136,5 +129,49 @@ describe("sales channels", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe("POST /admin/sales-channels", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
try {
|
||||||
|
await adminSeeder(dbConnection)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const db = useDb()
|
||||||
|
await db.teardown()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("successfully creates a sales channel", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const newSalesChannel = {
|
||||||
|
name: "sales channel name",
|
||||||
|
description: "sales channel description",
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/sales-channels", newSalesChannel, adminReqConfig)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.sales_channel).toBeTruthy()
|
||||||
|
|
||||||
|
expect(response.data).toMatchSnapshot({
|
||||||
|
sales_channel: expect.objectContaining({
|
||||||
|
name: newSalesChannel.name,
|
||||||
|
description: newSalesChannel.description,
|
||||||
|
is_disabled: false,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /admin/sales-channels/:id", () => {})
|
||||||
|
describe("POST /admin/sales-channels/:id", () => {})
|
||||||
describe("DELETE /admin/sales-channels/:id", () => {})
|
describe("DELETE /admin/sales-channels/:id", () => {})
|
||||||
})
|
})
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
AdminPostSalesChannelsReq,
|
||||||
AdminSalesChannelsRes,
|
AdminSalesChannelsRes,
|
||||||
AdminPostSalesChannelsSalesChannelReq,
|
AdminPostSalesChannelsSalesChannelReq,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
@@ -20,10 +21,17 @@ class AdminSalesChannelsResource extends BaseResource {
|
|||||||
return this.client.request("GET", path, {}, {}, customHeaders)
|
return this.client.request("GET", path, {}, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create(
|
/* *
|
||||||
payload: any,
|
* Create a medusa sales channel
|
||||||
|
* @returns the created channel
|
||||||
|
*/
|
||||||
|
create(
|
||||||
|
payload: AdminPostSalesChannelsReq,
|
||||||
customHeaders: Record<string, any> = {}
|
customHeaders: Record<string, any> = {}
|
||||||
): ResponsePromise<any> {}*/
|
): ResponsePromise<AdminSalesChannelsRes> {
|
||||||
|
const path = `/admin/sales-channels`
|
||||||
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
|
}
|
||||||
|
|
||||||
/** update a sales channel
|
/** update a sales channel
|
||||||
* @experimental This feature is under development and may change in the future.
|
* @experimental This feature is under development and may change in the future.
|
||||||
|
|||||||
@@ -869,7 +869,7 @@ export const adminHandlers = [
|
|||||||
discount_condition: {
|
discount_condition: {
|
||||||
...fixtures
|
...fixtures
|
||||||
.get("discount")
|
.get("discount")
|
||||||
.rule.conditions.find(c => c.id === req.params.conditionId),
|
.rule.conditions.find((c) => c.id === req.params.conditionId),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -1692,5 +1692,15 @@ export const adminHandlers = [
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}),
|
||||||
|
|
||||||
|
rest.post("/admin/sales-channels", (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.status(200),
|
||||||
|
ctx.json({
|
||||||
|
sales_channel: fixtures.get("sales_channel"),
|
||||||
|
...(req.body as Record<string, unknown>),
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
@@ -1,13 +1,38 @@
|
|||||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
|
||||||
import {
|
import {
|
||||||
|
AdminPostSalesChannelsReq,
|
||||||
AdminSalesChannelsRes,
|
AdminSalesChannelsRes,
|
||||||
AdminPostSalesChannelsSalesChannelReq,
|
AdminPostSalesChannelsSalesChannelReq,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
import { Response } from "@medusajs/medusa-js"
|
import { Response } from "@medusajs/medusa-js"
|
||||||
|
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||||
|
|
||||||
import { useMedusa } from "../../../contexts"
|
import { useMedusa } from "../../../contexts"
|
||||||
import { buildOptions } from "../../utils/buildOptions"
|
import { buildOptions } from "../../utils/buildOptions"
|
||||||
import { adminSalesChannelsKeys } from "./queries"
|
import { adminSalesChannelsKeys } from "./queries"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook provides a mutation function for creating sales channel.
|
||||||
|
*
|
||||||
|
* @experimental This feature is under development and may change in the future.
|
||||||
|
* To use this feature please enable the corresponding feature flag in your medusa backend project.
|
||||||
|
*/
|
||||||
|
export const useAdminCreateSalesChannel = (
|
||||||
|
options?: UseMutationOptions<
|
||||||
|
Response<AdminSalesChannelsRes>,
|
||||||
|
Error,
|
||||||
|
AdminPostSalesChannelsReq
|
||||||
|
>
|
||||||
|
) => {
|
||||||
|
const { client } = useMedusa()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
(payload: AdminPostSalesChannelsReq) =>
|
||||||
|
client.admin.salesChannels.create(payload),
|
||||||
|
buildOptions(queryClient, [adminSalesChannelsKeys.list()], options)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/** update a sales channel
|
/** update a sales channel
|
||||||
* @experimental This feature is under development and may change in the future.
|
* @experimental This feature is under development and may change in the future.
|
||||||
* To use this feature please enable feature flag `sales_channels` in your medusa backend project.
|
* To use this feature please enable feature flag `sales_channels` in your medusa backend project.
|
||||||
@@ -34,35 +59,3 @@ export const useAdminUpdateSalesChannel = (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export const useAdminCreateSalesChannel = (
|
|
||||||
options?: UseMutationOptions<
|
|
||||||
Response<AdminSalesChannelsRes>,
|
|
||||||
Error,
|
|
||||||
AdminPostSalesChannelsReq
|
|
||||||
>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
return useMutation(
|
|
||||||
(payload: AdminPostSalesChannelsReq) => client.admin.salesChannels.create(payload),
|
|
||||||
buildOptions(queryClient, adminSalesChannelsKeys.lists(), options)
|
|
||||||
)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*export const useAdminDeleteSalesChannel = (
|
|
||||||
id: string,
|
|
||||||
options?: UseMutationOptions<Response<AdminSalesChannelsDeleteRes>, Error, void>
|
|
||||||
) => {
|
|
||||||
const { client } = useMedusa()
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
return useMutation(
|
|
||||||
() => client.admin.salesChannels.delete(id),
|
|
||||||
buildOptions(
|
|
||||||
queryClient,
|
|
||||||
[adminSalesChannelsKeys.lists(), adminSalesChannelsKeys.detail(id)],
|
|
||||||
options
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}*/
|
|
||||||
@@ -1,9 +1,35 @@
|
|||||||
import { useAdminUpdateSalesChannel } from "../../../../src"
|
|
||||||
import { renderHook } from "@testing-library/react-hooks"
|
import { renderHook } from "@testing-library/react-hooks"
|
||||||
|
|
||||||
|
import { useAdminCreateSalesChannel, useAdminUpdateSalesChannel } from "../../../../src"
|
||||||
import { fixtures } from "../../../../mocks/data"
|
import { fixtures } from "../../../../mocks/data"
|
||||||
import { createWrapper } from "../../../utils"
|
import { createWrapper } from "../../../utils"
|
||||||
|
|
||||||
describe("useAdminUpdateStore hook", () => {
|
describe("useAdminCreateSalesChannel hook", () => {
|
||||||
|
test("returns a sales channel", async () => {
|
||||||
|
const salesChannel = {
|
||||||
|
name: "sales channel 1 name",
|
||||||
|
description: "sales channel 1 description",
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result, waitFor } = renderHook(() => useAdminCreateSalesChannel(), {
|
||||||
|
wrapper: createWrapper(),
|
||||||
|
})
|
||||||
|
|
||||||
|
result.current.mutate(salesChannel)
|
||||||
|
|
||||||
|
await waitFor(() => result.current.isSuccess)
|
||||||
|
|
||||||
|
expect(result.current.data.response.status).toEqual(200)
|
||||||
|
expect(result.current.data.sales_channel).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
...fixtures.get("sales_channel"),
|
||||||
|
...salesChannel,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("useAdminUpdateSalesChannel hook", () => {
|
||||||
test("updates a store", async () => {
|
test("updates a store", async () => {
|
||||||
const salesChannel = {
|
const salesChannel = {
|
||||||
name: "medusa sales channel",
|
name: "medusa sales channel",
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import { createWrapper } from "../../../utils"
|
|||||||
describe("useAdminSalesChannel hook", () => {
|
describe("useAdminSalesChannel hook", () => {
|
||||||
test("returns a product", async () => {
|
test("returns a product", async () => {
|
||||||
const salesChannel = fixtures.get("sales_channel")
|
const salesChannel = fixtures.get("sales_channel")
|
||||||
const { result, waitFor } = renderHook(() => useAdminSalesChannel(salesChannel.id), {
|
const { result, waitFor } = renderHook(
|
||||||
|
() => useAdminSalesChannel(salesChannel.id),
|
||||||
|
{
|
||||||
wrapper: createWrapper(),
|
wrapper: createWrapper(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
await waitFor(() => result.current.isSuccess)
|
await waitFor(() => result.current.isSuccess)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { IdMap } from "medusa-test-utils"
|
||||||
|
|
||||||
|
import { request } from "../../../../../helpers/test-request"
|
||||||
|
import { SalesChannelServiceMock } from "../../../../../services/__mocks__/sales-channel"
|
||||||
|
|
||||||
|
describe("POST /admin/sales-channels", () => {
|
||||||
|
describe("successfully get a sales channel", () => {
|
||||||
|
let subject
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
subject = await request("POST", `/admin/sales-channels`, {
|
||||||
|
adminSession: {
|
||||||
|
jwt: {
|
||||||
|
userId: IdMap.getId("admin_user"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
name: "sales channel 1 name",
|
||||||
|
description: "sales channel 1 description",
|
||||||
|
},
|
||||||
|
flags: ["sales_channels"],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("calls the create method from the sales channel service", () => {
|
||||||
|
expect(SalesChannelServiceMock.create).toHaveBeenCalledTimes(1)
|
||||||
|
expect(SalesChannelServiceMock.create).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "sales channel 1 name",
|
||||||
|
description: "sales channel 1 description",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Request, Response } from "express"
|
||||||
|
import { IsObject, IsOptional, IsString } from "class-validator"
|
||||||
|
|
||||||
|
import SalesChannelService from "../../../../services/sales-channel"
|
||||||
|
import { CreateSalesChannelInput } from "../../../../types/sales-channels"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @oas [post] /sales-channels
|
||||||
|
* operationId: "PostSalesChannels"
|
||||||
|
* summary: "Create a sales channel"
|
||||||
|
* description: "Creates a sales channel."
|
||||||
|
* x-authenticated: true
|
||||||
|
* parameters:
|
||||||
|
* - (body) name=* {string} Name of the sales channel
|
||||||
|
* - (body) description=* {string} Description of the sales channel
|
||||||
|
* tags:
|
||||||
|
* - Sales Channels
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: OK
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* properties:
|
||||||
|
* sales_channel:
|
||||||
|
* $ref: "#/components/schemas/sales_channel"
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default async (req: Request, res: Response) => {
|
||||||
|
const salesChannelService: SalesChannelService = req.scope.resolve(
|
||||||
|
"salesChannelService"
|
||||||
|
)
|
||||||
|
|
||||||
|
const salesChannel = await salesChannelService.create(
|
||||||
|
req.validatedBody as CreateSalesChannelInput
|
||||||
|
)
|
||||||
|
res.status(200).json({ sales_channel: salesChannel })
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AdminPostSalesChannelsReq {
|
||||||
|
@IsString()
|
||||||
|
name: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
description: string
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ import SalesChannelService from "../../../../services/sales-channel"
|
|||||||
* schema:
|
* schema:
|
||||||
* properties:
|
* properties:
|
||||||
* sales_channel:
|
* sales_channel:
|
||||||
* $ref: "#/components/schemas/sales-channel"
|
* $ref: "#/components/schemas/sales_channel"
|
||||||
*/
|
*/
|
||||||
export default async (req: Request, res: Response): Promise<void> => {
|
export default async (req: Request, res: Response): Promise<void> => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
|||||||
import { SalesChannel } from "../../../../models"
|
import { SalesChannel } from "../../../../models"
|
||||||
import middlewares, { transformBody } from "../../../middlewares"
|
import middlewares, { transformBody } from "../../../middlewares"
|
||||||
import { AdminPostSalesChannelsSalesChannelReq } from "./update-sales-channel"
|
import { AdminPostSalesChannelsSalesChannelReq } from "./update-sales-channel"
|
||||||
|
import { AdminPostSalesChannelsReq } from "./create-sales-channel"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
@@ -21,7 +22,11 @@ export default (app) => {
|
|||||||
|
|
||||||
route.get("/", (req, res) => {})
|
route.get("/", (req, res) => {})
|
||||||
|
|
||||||
route.post("/", (req, res) => {})
|
route.post(
|
||||||
|
"/",
|
||||||
|
transformBody(AdminPostSalesChannelsReq),
|
||||||
|
middlewares.wrap(require("./create-sales-channel").default)
|
||||||
|
)
|
||||||
|
|
||||||
route.post(
|
route.post(
|
||||||
"/:id",
|
"/:id",
|
||||||
@@ -45,6 +50,7 @@ export type AdminSalesChannelListRes = PaginatedResponse & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export * from "./get-sales-channel"
|
export * from "./get-sales-channel"
|
||||||
|
export * from "./create-sales-channel"
|
||||||
// export * from './'
|
// export * from './'
|
||||||
// export * from './'
|
// export * from './'
|
||||||
export * from "./update-sales-channel"
|
export * from "./update-sales-channel"
|
||||||
|
|||||||
@@ -17,9 +17,14 @@ export const SalesChannelServiceMock = {
|
|||||||
|
|
||||||
listAndCount: jest.fn().mockImplementation(() => {}),
|
listAndCount: jest.fn().mockImplementation(() => {}),
|
||||||
|
|
||||||
create: jest.fn().mockImplementation(() => {}),
|
|
||||||
|
|
||||||
delete: jest.fn().mockImplementation(() => {}),
|
delete: jest.fn().mockImplementation(() => {}),
|
||||||
|
|
||||||
|
create: jest.fn().mockImplementation((data) => {
|
||||||
|
return Promise.resolve({
|
||||||
|
id: id,
|
||||||
|
...data,
|
||||||
|
})
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const mock = jest.fn().mockImplementation(() => {
|
const mock = jest.fn().mockImplementation(() => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { EntityManager } from "typeorm"
|
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
|
||||||
import { TransactionBaseService } from "../interfaces"
|
import { TransactionBaseService } from "../interfaces"
|
||||||
import { SalesChannel } from "../models"
|
import { SalesChannel } from "../models"
|
||||||
import { SalesChannelRepository } from "../repositories/sales-channel"
|
import { SalesChannelRepository } from "../repositories/sales-channel"
|
||||||
@@ -10,6 +11,7 @@ import {
|
|||||||
} from "../types/sales-channels"
|
} from "../types/sales-channels"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
import { buildQuery } from "../utils"
|
import { buildQuery } from "../utils"
|
||||||
|
import { PostgresError } from "../utils/exception-formatter"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
salesChannelRepository: typeof SalesChannelRepository
|
salesChannelRepository: typeof SalesChannelRepository
|
||||||
@@ -20,6 +22,7 @@ type InjectedDependencies = {
|
|||||||
class SalesChannelService extends TransactionBaseService<SalesChannelService> {
|
class SalesChannelService extends TransactionBaseService<SalesChannelService> {
|
||||||
static Events = {
|
static Events = {
|
||||||
UPDATED: "sales_channel.updated",
|
UPDATED: "sales_channel.updated",
|
||||||
|
CREATED: "sales_channel.created",
|
||||||
}
|
}
|
||||||
|
|
||||||
protected manager_: EntityManager
|
protected manager_: EntityManager
|
||||||
@@ -41,6 +44,13 @@ class SalesChannelService extends TransactionBaseService<SalesChannelService> {
|
|||||||
this.eventBusService_ = eventBusService
|
this.eventBusService_ = eventBusService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a SalesChannel by id
|
||||||
|
*
|
||||||
|
* @experimental This feature is under development and may change in the future.
|
||||||
|
* To use this feature please enable the corresponding feature flag in your medusa backend project.
|
||||||
|
* @returns a sales channel
|
||||||
|
*/
|
||||||
async retrieve(
|
async retrieve(
|
||||||
salesChannelId: string,
|
salesChannelId: string,
|
||||||
config: FindConfig<SalesChannel> = {}
|
config: FindConfig<SalesChannel> = {}
|
||||||
@@ -77,8 +87,28 @@ class SalesChannelService extends TransactionBaseService<SalesChannelService> {
|
|||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateSalesChannelInput): Promise<SalesChannel> {
|
/**
|
||||||
throw new Error("Method not implemented.")
|
* Creates a SalesChannel
|
||||||
|
*
|
||||||
|
* @experimental This feature is under development and may change in the future.
|
||||||
|
* To use this feature please enable the corresponding feature flag in your medusa backend project.
|
||||||
|
* @returns the created channel
|
||||||
|
*/
|
||||||
|
async create(data: CreateSalesChannelInput): Promise<SalesChannel | never> {
|
||||||
|
return await this.atomicPhase_(async (manager) => {
|
||||||
|
const salesChannelRepo: SalesChannelRepository =
|
||||||
|
manager.getCustomRepository(this.salesChannelRepository_)
|
||||||
|
|
||||||
|
const salesChannel = salesChannelRepo.create(data)
|
||||||
|
|
||||||
|
await this.eventBusService_
|
||||||
|
.withTransaction(manager)
|
||||||
|
.emit(SalesChannelService.Events.CREATED, {
|
||||||
|
id: salesChannel.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
return await salesChannelRepo.save(salesChannel)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
|
|||||||
Reference in new issue
Block a user