feat: Add boilerplate for the file module (#6956)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import {
|
||||
moduleDefinition,
|
||||
revertMigration,
|
||||
runMigrations,
|
||||
} from "./module-definition"
|
||||
|
||||
export default moduleDefinition
|
||||
export { revertMigration, runMigrations }
|
||||
|
||||
export * from "./services"
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
|
||||
export const LinkableKeys = {}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.FILE,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: [
|
||||
{
|
||||
name: ["file", "files"],
|
||||
args: {
|
||||
entity: "File",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { FileModuleService } from "@services"
|
||||
export const runMigrations = () => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
export const revertMigration = () => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const service = FileModuleService
|
||||
const loaders = [] as any
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
runMigrations,
|
||||
revertMigration,
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
describe("File service", function () {
|
||||
it("noop", async function () {})
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
Context,
|
||||
CreateFileDTO,
|
||||
FileDTO,
|
||||
ModuleJoinerConfig,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
|
||||
export default class FileModuleService {
|
||||
constructor() {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
super(...arguments)
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
create(data: CreateFileDTO[], sharedContext?: Context): Promise<FileDTO[]>
|
||||
create(data: CreateFileDTO, sharedContext?: Context): Promise<FileDTO>
|
||||
|
||||
async create(
|
||||
data: CreateFileDTO[] | CreateFileDTO
|
||||
): Promise<FileDTO[] | FileDTO> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
const files = []
|
||||
return Array.isArray(data) ? files : files[0]
|
||||
}
|
||||
|
||||
async delete(ids: string[], sharedContext?: Context): Promise<void>
|
||||
async delete(id: string, sharedContext?: Context): Promise<void>
|
||||
async delete(ids: string[] | string): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
async retrieve(id: string): Promise<FileDTO>
|
||||
async retrieve(id: string): Promise<FileDTO> {
|
||||
return {} as FileDTO
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default as FileModuleService } from "./file-module-service"
|
||||
Reference in New Issue
Block a user