chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
8
packages/modules/pricing/src/models/index.ts
Normal file
8
packages/modules/pricing/src/models/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export { default as Price } from "./price"
|
||||
export { default as PriceList } from "./price-list"
|
||||
export { default as PriceListRule } from "./price-list-rule"
|
||||
export { default as PriceListRuleValue } from "./price-list-rule-value"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
export { default as PriceSet } from "./price-set"
|
||||
export { default as PriceSetRuleType } from "./price-set-rule-type"
|
||||
export { default as RuleType } from "./rule-type"
|
||||
87
packages/modules/pricing/src/models/price-list-rule-value.ts
Normal file
87
packages/modules/pricing/src/models/price-list-rule-value.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceListRule from "./price-list-rule"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list_rule_value"
|
||||
const PriceListRuleValueDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListPriceListRuleIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_rule_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRuleValue {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceListPriceListRuleIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceListRule, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_list_rule_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_rule_id: string
|
||||
|
||||
@ManyToOne(() => PriceListRule, { persist: false })
|
||||
price_list_rule: PriceListRule
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListRuleValueDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "plrv")
|
||||
this.price_list_rule_id ??= this.price_list_rule?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "plrv")
|
||||
this.price_list_rule_id ??= this.price_list_rule?.id
|
||||
}
|
||||
}
|
||||
114
packages/modules/pricing/src/models/price-list-rule.ts
Normal file
114
packages/modules/pricing/src/models/price-list-rule.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceList from "./price-list"
|
||||
import PriceListRuleValue from "./price-list-rule-value"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list_rule"
|
||||
const PriceListRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
const PriceListRulePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRule {
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceListRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@ManyToOne(() => RuleType, { persist: false })
|
||||
rule_type: RuleType
|
||||
|
||||
@OneToMany(() => PriceListRuleValue, (plrv) => plrv.price_list_rule, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rule_values = new Collection<PriceListRuleValue>(this)
|
||||
|
||||
@PriceListRulePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_id: string
|
||||
|
||||
@ManyToOne(() => PriceList, { persist: false })
|
||||
price_list: PriceList
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "plrule")
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "plrule")
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
}
|
||||
}
|
||||
123
packages/modules/pricing/src/models/price-list.ts
Normal file
123
packages/modules/pricing/src/models/price-list.ts
Normal file
@@ -0,0 +1,123 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
Searchable,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceListRule from "./price-list-rule"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields =
|
||||
| "starts_at"
|
||||
| "ends_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list"
|
||||
const PriceListDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
export const PriceListIdPrefix = "plist"
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceList {
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
title: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
description: string
|
||||
|
||||
@Enum({ items: () => PriceListStatus, default: PriceListStatus.DRAFT })
|
||||
status: PriceListStatus
|
||||
|
||||
@Enum({ items: () => PriceListType, default: PriceListType.SALE })
|
||||
type: PriceListType
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
starts_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
ends_at: Date | null = null
|
||||
|
||||
@OneToMany(() => Price, (price) => price.price_list, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceListRule, (pr) => pr.price_list, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rules = new Collection<PriceListRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceListRule,
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number = 0
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, PriceListIdPrefix)
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, PriceListIdPrefix)
|
||||
}
|
||||
}
|
||||
132
packages/modules/pricing/src/models/price-rule.ts
Normal file
132
packages/modules/pricing/src/models/price-rule.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceSet from "./price-set"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_rule"
|
||||
const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: ["price_id", "rule_type_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceRule {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceRulePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@ManyToOne(() => PriceSet, { persist: false })
|
||||
price_set: PriceSet
|
||||
|
||||
@PriceRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@ManyToOne(() => RuleType, { persist: false })
|
||||
rule_type: RuleType
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
priority: number = 0
|
||||
|
||||
@PriceRulePriceIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => Price, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_id: string
|
||||
|
||||
@ManyToOne(() => Price, { persist: false })
|
||||
price: Price
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
}
|
||||
89
packages/modules/pricing/src/models/price-set-rule-type.ts
Normal file
89
packages/modules/pricing/src/models/price-set-rule-type.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceSet from "./price-set"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
const tableName = "price_set_rule_type"
|
||||
const PriceSetRuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypeRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetRuleType {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceSetRuleTypePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@PriceSetRuleTypeRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceSetRuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psrt")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "psrt")
|
||||
}
|
||||
}
|
||||
83
packages/modules/pricing/src/models/price-set.ts
Normal file
83
packages/modules/pricing/src/models/price-set.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSetRuleType from "./price-set-rule-type"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
const tableName = "price_set"
|
||||
const PriceSetDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
export const PriceSetIdPrefix = "pset"
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSet {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@OneToMany(() => Price, (price) => price.price_set, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceSetRuleType,
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceSetDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, PriceSetIdPrefix)
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, PriceSetIdPrefix)
|
||||
}
|
||||
}
|
||||
147
packages/modules/pricing/src/models/price.ts
Normal file
147
packages/modules/pricing/src/models/price.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
MikroOrmBigNumberProperty,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceList from "./price-list"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price"
|
||||
const PriceDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PricePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PricePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Price {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
title: string | null = null
|
||||
|
||||
@PriceCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
amount: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_amount: Record<string, unknown>
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
min_quantity: number | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
max_quantity: number | null = null
|
||||
|
||||
@PricePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@ManyToOne(() => PriceSet, { persist: false })
|
||||
price_set?: PriceSet
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number = 0
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceRule,
|
||||
mappedBy: (pr) => pr.price,
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@PricePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
fieldName: "price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_id: string | null = null
|
||||
|
||||
@ManyToOne(() => PriceList, { persist: false, nullable: true })
|
||||
price_list: PriceList | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
}
|
||||
85
packages/modules/pricing/src/models/rule-type.ts
Normal file
85
packages/modules/pricing/src/models/rule-type.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = "default_priority"
|
||||
|
||||
const tableName = "rule_type"
|
||||
const RuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const RuleTypeRuleAttributeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_attribute",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class RuleType {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@RuleTypeRuleAttributeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
rule_attribute: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
default_priority: number
|
||||
|
||||
@ManyToMany(() => PriceSet, (priceSet) => priceSet.rule_types)
|
||||
price_sets = new Collection<PriceSet>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@RuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "rul-typ")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "rul-typ")
|
||||
}
|
||||
}
|
||||
|
||||
export default RuleType
|
||||
Reference in New Issue
Block a user