chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
125
packages/modules/promotion/src/models/application-method.ts
Normal file
125
packages/modules/promotion/src/models/application-method.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import {
|
||||
ApplicationMethodAllocationValues,
|
||||
ApplicationMethodTargetTypeValues,
|
||||
ApplicationMethodTypeValues,
|
||||
BigNumberRawValue,
|
||||
DAL,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
PromotionUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Promotion from "./promotion"
|
||||
import PromotionRule from "./promotion-rule"
|
||||
|
||||
type OptionalFields =
|
||||
| "value"
|
||||
| "max_quantity"
|
||||
| "apply_to_quantity"
|
||||
| "buy_rules_min_quantity"
|
||||
| "allocation"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "promotion_application_method" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ApplicationMethod {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@MikroOrmBigNumberProperty({ nullable: true })
|
||||
value: BigNumber | number | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_value: BigNumberRawValue | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true, serializer: Number })
|
||||
max_quantity?: number | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true, serializer: Number })
|
||||
apply_to_quantity?: number | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true, serializer: Number })
|
||||
buy_rules_min_quantity?: number | null = null
|
||||
|
||||
@Index({ name: "IDX_application_method_type" })
|
||||
@Enum(() => PromotionUtils.ApplicationMethodType)
|
||||
type: ApplicationMethodTypeValues
|
||||
|
||||
@Index({ name: "IDX_application_method_target_type" })
|
||||
@Enum(() => PromotionUtils.ApplicationMethodTargetType)
|
||||
target_type: ApplicationMethodTargetTypeValues
|
||||
|
||||
@Index({ name: "IDX_application_method_allocation" })
|
||||
@Enum({
|
||||
items: () => PromotionUtils.ApplicationMethodAllocation,
|
||||
nullable: true,
|
||||
})
|
||||
allocation?: ApplicationMethodAllocationValues
|
||||
|
||||
@OneToOne({
|
||||
entity: () => Promotion,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
promotion: Promotion
|
||||
|
||||
@ManyToMany(() => PromotionRule, "method_target_rules", {
|
||||
owner: true,
|
||||
pivotTable: "application_method_target_rules",
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
target_rules = new Collection<PromotionRule>(this)
|
||||
|
||||
@ManyToMany(() => PromotionRule, "method_buy_rules", {
|
||||
owner: true,
|
||||
pivotTable: "application_method_buy_rules",
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
buy_rules = new Collection<PromotionRule>(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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "proappmet")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "proappmet")
|
||||
}
|
||||
}
|
||||
89
packages/modules/promotion/src/models/campaign-budget.ts
Normal file
89
packages/modules/promotion/src/models/campaign-budget.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
BigNumberRawValue,
|
||||
CampaignBudgetTypeValues,
|
||||
DAL,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
PromotionUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
OnInit,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Campaign from "./campaign"
|
||||
|
||||
type OptionalFields =
|
||||
| "description"
|
||||
| "limit"
|
||||
| "used"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "promotion_campaign_budget" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class CampaignBudget {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Index({ name: "IDX_campaign_budget_type" })
|
||||
@Enum(() => PromotionUtils.CampaignBudgetType)
|
||||
type: CampaignBudgetTypeValues
|
||||
|
||||
@OneToOne({
|
||||
entity: () => Campaign,
|
||||
})
|
||||
campaign: Campaign | null = null
|
||||
|
||||
@MikroOrmBigNumberProperty({ nullable: true })
|
||||
limit: BigNumber | number | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_limit: BigNumberRawValue | null = null
|
||||
|
||||
@MikroOrmBigNumberProperty({ nullable: true })
|
||||
used: BigNumber | number | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_used: BigNumberRawValue | 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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "probudg")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "probudg")
|
||||
}
|
||||
}
|
||||
105
packages/modules/promotion/src/models/campaign.ts
Normal file
105
packages/modules/promotion/src/models/campaign.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Unique,
|
||||
} from "@mikro-orm/core"
|
||||
import CampaignBudget from "./campaign-budget"
|
||||
import Promotion from "./promotion"
|
||||
|
||||
type OptionalRelations = "budget"
|
||||
type OptionalFields =
|
||||
| "description"
|
||||
| "currency"
|
||||
| "starts_at"
|
||||
| "ends_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "promotion_campaign" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Campaign {
|
||||
[OptionalProps]?: OptionalFields | OptionalRelations
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
currency: string | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Unique({
|
||||
name: "IDX_campaign_identifier_unique",
|
||||
properties: ["campaign_identifier"],
|
||||
})
|
||||
campaign_identifier: string
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
starts_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
ends_at: Date | null = null
|
||||
|
||||
@OneToOne({
|
||||
entity: () => CampaignBudget,
|
||||
mappedBy: (cb) => cb.campaign,
|
||||
cascade: ["soft-remove"] as any,
|
||||
nullable: true,
|
||||
})
|
||||
budget: CampaignBudget | null = null
|
||||
|
||||
@OneToMany(() => Promotion, (promotion) => promotion.campaign, {
|
||||
orphanRemoval: true,
|
||||
})
|
||||
promotions = new Collection<Promotion>(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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "procamp")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "procamp")
|
||||
}
|
||||
}
|
||||
6
packages/modules/promotion/src/models/index.ts
Normal file
6
packages/modules/promotion/src/models/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { default as ApplicationMethod } from "./application-method"
|
||||
export { default as Campaign } from "./campaign"
|
||||
export { default as CampaignBudget } from "./campaign-budget"
|
||||
export { default as Promotion } from "./promotion"
|
||||
export { default as PromotionRule } from "./promotion-rule"
|
||||
export { default as PromotionRuleValue } from "./promotion-rule-value"
|
||||
@@ -0,0 +1,56 @@
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PromotionRule from "./promotion-rule"
|
||||
|
||||
@Entity({ tableName: "promotion_rule_value" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PromotionRuleValue {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => PromotionRule, {
|
||||
onDelete: "cascade",
|
||||
fieldName: "promotion_rule_id",
|
||||
index: "IDX_promotion_rule_promotion_rule_value_id",
|
||||
})
|
||||
promotion_rule: PromotionRule
|
||||
|
||||
@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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "prorulval")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "prorulval")
|
||||
}
|
||||
}
|
||||
91
packages/modules/promotion/src/models/promotion-rule.ts
Normal file
91
packages/modules/promotion/src/models/promotion-rule.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { DAL, PromotionRuleOperatorValues } from "@medusajs/types"
|
||||
import { DALUtils, PromotionUtils, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import ApplicationMethod from "./application-method"
|
||||
import Promotion from "./promotion"
|
||||
import PromotionRuleValue from "./promotion-rule-value"
|
||||
|
||||
type OptionalFields = "description" | DAL.SoftDeletableEntityDateColumns
|
||||
type OptionalRelations = "values" | "promotions"
|
||||
|
||||
@Entity({ tableName: "promotion_rule" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PromotionRule {
|
||||
[OptionalProps]?: OptionalFields | OptionalRelations
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@Index({ name: "IDX_promotion_rule_attribute" })
|
||||
@Property({ columnType: "text" })
|
||||
attribute: string
|
||||
|
||||
@Index({ name: "IDX_promotion_rule_operator" })
|
||||
@Enum(() => PromotionUtils.PromotionRuleOperator)
|
||||
operator: PromotionRuleOperatorValues
|
||||
|
||||
@OneToMany(() => PromotionRuleValue, (prv) => prv.promotion_rule, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
})
|
||||
values = new Collection<PromotionRuleValue>(this)
|
||||
|
||||
@ManyToMany(() => Promotion, (promotion) => promotion.rules)
|
||||
promotions = new Collection<Promotion>(this)
|
||||
|
||||
@ManyToMany(
|
||||
() => ApplicationMethod,
|
||||
(applicationMethod) => applicationMethod.target_rules
|
||||
)
|
||||
method_target_rules = new Collection<ApplicationMethod>(this)
|
||||
|
||||
@ManyToMany(
|
||||
() => ApplicationMethod,
|
||||
(applicationMethod) => applicationMethod.buy_rules
|
||||
)
|
||||
method_buy_rules = new Collection<ApplicationMethod>(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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "prorul")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "prorul")
|
||||
}
|
||||
}
|
||||
104
packages/modules/promotion/src/models/promotion.ts
Normal file
104
packages/modules/promotion/src/models/promotion.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { DAL, PromotionTypeValues } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
PromotionUtils,
|
||||
Searchable,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Unique,
|
||||
} from "@mikro-orm/core"
|
||||
import ApplicationMethod from "./application-method"
|
||||
import Campaign from "./campaign"
|
||||
import PromotionRule from "./promotion-rule"
|
||||
|
||||
type OptionalFields = "is_automatic" | DAL.SoftDeletableEntityDateColumns
|
||||
type OptionalRelations = "application_method" | "campaign"
|
||||
|
||||
@Entity({ tableName: "promotion" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Promotion {
|
||||
[OptionalProps]?: OptionalFields | OptionalRelations
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
@Index({ name: "IDX_promotion_code" })
|
||||
@Unique({
|
||||
name: "IDX_promotion_code_unique",
|
||||
properties: ["code"],
|
||||
})
|
||||
code: string
|
||||
|
||||
@Searchable()
|
||||
@ManyToOne(() => Campaign, {
|
||||
fieldName: "campaign_id",
|
||||
nullable: true,
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
campaign: Campaign | null = null
|
||||
|
||||
@Property({ columnType: "boolean", default: false })
|
||||
is_automatic: boolean = false
|
||||
|
||||
@Index({ name: "IDX_promotion_type" })
|
||||
@Enum(() => PromotionUtils.PromotionType)
|
||||
type: PromotionTypeValues
|
||||
|
||||
@OneToOne({
|
||||
entity: () => ApplicationMethod,
|
||||
mappedBy: (am) => am.promotion,
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
application_method: ApplicationMethod
|
||||
|
||||
@ManyToMany(() => PromotionRule, "promotions", {
|
||||
owner: true,
|
||||
pivotTable: "promotion_promotion_rule",
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
rules = new Collection<PromotionRule>(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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "promo")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "promo")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user