feat(medusa): SC service (#1784)
* add sales channel service and empty api index * add integration testing file * add tyeps * remove ts directive * add sales channel test * update import * remove unused import * fix tests
This commit is contained in:
42
integration-tests/api/__tests__/admin/sales-channels.js
Normal file
42
integration-tests/api/__tests__/admin/sales-channels.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const path = require("path")
|
||||
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { useDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const startServerWithEnvironment =
|
||||
require("../../../helpers/start-server-with-environment").default
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("sales channels", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_SALES_CHANNELS: true },
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
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("POST /admin/sales-channels/:id", () => {})
|
||||
describe("DELETE /admin/sales-channels/:id", () => {})
|
||||
})
|
||||
41
packages/medusa/src/api/routes/admin/sales-channels/index.ts
Normal file
41
packages/medusa/src/api/routes/admin/sales-channels/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import { Router } from "express"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares from "../../../middlewares"
|
||||
import "reflect-metadata"
|
||||
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
||||
import { SalesChannel } from "../../../../models/sales-channel"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default (app) => {
|
||||
app.use("/sales-channels", isFeatureFlagEnabled("sales_channels"), route)
|
||||
|
||||
route.get("/:id", (req, res) => {})
|
||||
|
||||
route.get("/", (req, res) => {})
|
||||
|
||||
route.post("/", (req, res) => {})
|
||||
|
||||
route.post("/:id", (req, res) => {})
|
||||
|
||||
route.delete("/:id", (req, res) => {})
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
export type AdminSalesChanenlRes = {
|
||||
sales_channel: SalesChannel
|
||||
}
|
||||
|
||||
export type AdminSalesChannelDeleteRes = DeleteResponse
|
||||
|
||||
export type AdminSalesChannelListRes = PaginatedResponse & {
|
||||
sales_channels: SalesChannel[]
|
||||
}
|
||||
|
||||
// export * from './'
|
||||
// export * from './'
|
||||
// export * from './'
|
||||
// export * from './'
|
||||
// export * from './'
|
||||
65
packages/medusa/src/services/sales-channel.ts
Normal file
65
packages/medusa/src/services/sales-channel.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { EntityManager } from "typeorm"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { SalesChannel } from "../models/sales-channel"
|
||||
import { SalesChannelRepository } from "../repositories/sales-channel"
|
||||
import { FindConfig, QuerySelector } from "../types/common"
|
||||
import {
|
||||
CreateSalesChannelInput,
|
||||
UpdateSalesChannelInput,
|
||||
} from "../types/sales-channels"
|
||||
import EventBusService from "./event-bus"
|
||||
|
||||
type InjectedDependencies = {
|
||||
salesChannelRepository: typeof SalesChannelRepository
|
||||
eventBusService: EventBusService
|
||||
manager: EntityManager
|
||||
}
|
||||
|
||||
class SalesChannelService extends TransactionBaseService<SalesChannelService> {
|
||||
protected manager_: EntityManager
|
||||
protected transactionManager_: EntityManager | undefined
|
||||
|
||||
protected readonly salesChannelRepository_: typeof SalesChannelRepository
|
||||
protected readonly eventBusService_: EventBusService
|
||||
|
||||
constructor({
|
||||
salesChannelRepository,
|
||||
eventBusService,
|
||||
manager,
|
||||
}: InjectedDependencies) {
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
super(arguments[0])
|
||||
|
||||
this.manager_ = manager
|
||||
this.salesChannelRepository_ = salesChannelRepository
|
||||
this.eventBusService_ = eventBusService
|
||||
}
|
||||
|
||||
async retrieve(id: string): Promise<SalesChannel> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
async listAndCount(
|
||||
selector: QuerySelector<any> = {},
|
||||
config: FindConfig<any> = { relations: [], skip: 0, take: 10 }
|
||||
): Promise<[SalesChannel[], number]> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
async create(data: CreateSalesChannelInput): Promise<SalesChannel> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
data: UpdateSalesChannelInput
|
||||
): Promise<SalesChannel> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
}
|
||||
|
||||
export default SalesChannelService
|
||||
7
packages/medusa/src/types/sales-channels.ts
Normal file
7
packages/medusa/src/types/sales-channels.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export type CreateSalesChannelInput = {
|
||||
name: string
|
||||
description?: string
|
||||
is_disabled?: boolean
|
||||
}
|
||||
|
||||
export type UpdateSalesChannelInput = Partial<CreateSalesChannelInput>
|
||||
Reference in New Issue
Block a user