1 parent
0a16efa426
commit
be15240909
4 files changed
+20
-72
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/sales-channel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
refactor: migrate sales-channel to DML
|
||||||
File renamed without changes.
@@ -1,71 +1,11 @@
|
|||||||
import {
|
import { model } from "@medusajs/framework/utils"
|
||||||
DALUtils,
|
|
||||||
Searchable,
|
|
||||||
generateEntityId,
|
|
||||||
} from "@medusajs/framework/utils"
|
|
||||||
|
|
||||||
import { DAL } from "@medusajs/framework/types"
|
const SalesChannel = model.define("SalesChannel", {
|
||||||
import {
|
id: model.id({ prefix: "sc" }).primaryKey(),
|
||||||
BeforeCreate,
|
name: model.text().searchable(),
|
||||||
Entity,
|
description: model.text().searchable().nullable(),
|
||||||
Filter,
|
is_disabled: model.boolean().default(false),
|
||||||
Index,
|
metadata: model.json().nullable(),
|
||||||
OnInit,
|
})
|
||||||
OptionalProps,
|
|
||||||
PrimaryKey,
|
|
||||||
Property,
|
|
||||||
} from "@mikro-orm/core"
|
|
||||||
|
|
||||||
type SalesChannelOptionalProps = "is_disabled" | DAL.ModelDateColumns
|
export default SalesChannel
|
||||||
|
|
||||||
@Entity()
|
|
||||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
|
||||||
export default class SalesChannel {
|
|
||||||
[OptionalProps]?: SalesChannelOptionalProps
|
|
||||||
|
|
||||||
@PrimaryKey({ columnType: "text" })
|
|
||||||
id!: string
|
|
||||||
|
|
||||||
@Searchable()
|
|
||||||
@Property({ columnType: "text" })
|
|
||||||
name!: string
|
|
||||||
|
|
||||||
@Searchable()
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
|
||||||
description: string | null = null
|
|
||||||
|
|
||||||
@Property({ columnType: "boolean", default: false })
|
|
||||||
is_disabled: boolean = false
|
|
||||||
|
|
||||||
@Property({
|
|
||||||
onCreate: () => new Date(),
|
|
||||||
columnType: "timestamptz",
|
|
||||||
defaultRaw: "now()",
|
|
||||||
})
|
|
||||||
created_at: Date
|
|
||||||
|
|
||||||
@Property({ columnType: "jsonb", nullable: true })
|
|
||||||
metadata: Record<string, unknown> | null = null
|
|
||||||
|
|
||||||
@Property({
|
|
||||||
onCreate: () => new Date(),
|
|
||||||
onUpdate: () => new Date(),
|
|
||||||
columnType: "timestamptz",
|
|
||||||
defaultRaw: "now()",
|
|
||||||
})
|
|
||||||
updated_at: Date
|
|
||||||
|
|
||||||
@Index({ name: "IDX_sales_channel_deleted_at" })
|
|
||||||
@Property({ columnType: "timestamptz", nullable: true })
|
|
||||||
deleted_at: Date | null = null
|
|
||||||
|
|
||||||
@BeforeCreate()
|
|
||||||
onCreate() {
|
|
||||||
this.id = generateEntityId(this.id, "sc")
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnInit()
|
|
||||||
onInit() {
|
|
||||||
this.id = generateEntityId(this.id, "sc")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
CreateSalesChannelDTO,
|
CreateSalesChannelDTO,
|
||||||
DAL,
|
DAL,
|
||||||
FilterableSalesChannelProps,
|
FilterableSalesChannelProps,
|
||||||
|
InferEntityType,
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
ISalesChannelModuleService,
|
ISalesChannelModuleService,
|
||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
@@ -36,7 +37,9 @@ export default class SalesChannelModuleService
|
|||||||
implements ISalesChannelModuleService
|
implements ISalesChannelModuleService
|
||||||
{
|
{
|
||||||
protected baseRepository_: DAL.RepositoryService
|
protected baseRepository_: DAL.RepositoryService
|
||||||
protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<SalesChannel>
|
protected readonly salesChannelService_: ModulesSdkTypes.IMedusaInternalService<
|
||||||
|
InferEntityType<typeof SalesChannel>
|
||||||
|
>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{ baseRepository, salesChannelService }: InjectedDependencies,
|
{ baseRepository, salesChannelService }: InjectedDependencies,
|
||||||
@@ -83,7 +86,7 @@ export default class SalesChannelModuleService
|
|||||||
async createSalesChannels_(
|
async createSalesChannels_(
|
||||||
data: CreateSalesChannelDTO[],
|
data: CreateSalesChannelDTO[],
|
||||||
@MedusaContext() sharedContext: Context
|
@MedusaContext() sharedContext: Context
|
||||||
): Promise<SalesChannel[]> {
|
): Promise<InferEntityType<typeof SalesChannel>[]> {
|
||||||
return await this.salesChannelService_.create(data, sharedContext)
|
return await this.salesChannelService_.create(data, sharedContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +166,7 @@ export default class SalesChannelModuleService
|
|||||||
(channel): channel is CreateSalesChannelDTO => !channel.id
|
(channel): channel is CreateSalesChannelDTO => !channel.id
|
||||||
)
|
)
|
||||||
|
|
||||||
const operations: Promise<SalesChannel[]>[] = []
|
const operations: Promise<InferEntityType<typeof SalesChannel>[]>[] = []
|
||||||
|
|
||||||
if (forCreate.length) {
|
if (forCreate.length) {
|
||||||
operations.push(this.createSalesChannels_(forCreate, sharedContext))
|
operations.push(this.createSalesChannels_(forCreate, sharedContext))
|
||||||
|
|||||||
Reference in new issue
Block a user