chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
4
packages/modules/tax/src/models/index.ts
Normal file
4
packages/modules/tax/src/models/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export { default as TaxRate } from "./tax-rate"
|
||||
export { default as TaxRegion } from "./tax-region"
|
||||
export { default as TaxRateRule } from "./tax-rate-rule"
|
||||
export { default as TaxProvider } from "./tax-provider"
|
||||
16
packages/modules/tax/src/models/tax-provider.ts
Normal file
16
packages/modules/tax/src/models/tax-provider.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Entity, OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
|
||||
const TABLE_NAME = "tax_provider"
|
||||
@Entity({ tableName: TABLE_NAME })
|
||||
export default class TaxProvider {
|
||||
[OptionalProps]?: "is_enabled"
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({
|
||||
default: true,
|
||||
columnType: "boolean",
|
||||
})
|
||||
is_enabled: boolean = true
|
||||
}
|
||||
116
packages/modules/tax/src/models/tax-rate-rule.ts
Normal file
116
packages/modules/tax/src/models/tax-rate-rule.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
Cascade,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Filter,
|
||||
OptionalProps,
|
||||
BeforeCreate,
|
||||
OnInit,
|
||||
} from "@mikro-orm/core"
|
||||
import TaxRate from "./tax-rate"
|
||||
|
||||
const TABLE_NAME = "tax_rate_rule"
|
||||
|
||||
type OptionalRuleProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const taxRateIdIndexName = "IDX_tax_rate_rule_tax_rate_id"
|
||||
const taxRateIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: taxRateIdIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: "tax_rate_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const referenceIdIndexName = "IDX_tax_rate_rule_reference_id"
|
||||
const referenceIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: referenceIdIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: "reference_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
export const uniqueRateReferenceIndexName =
|
||||
"IDX_tax_rate_rule_unique_rate_reference"
|
||||
const uniqueRateReferenceIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: uniqueRateReferenceIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: ["tax_rate_id", "reference_id"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: TABLE_NAME })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
@uniqueRateReferenceIndexStatement.MikroORMIndex()
|
||||
export default class TaxRateRule {
|
||||
[OptionalProps]?: OptionalRuleProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => TaxRate, {
|
||||
type: "text",
|
||||
fieldName: "tax_rate_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@taxRateIdIndexStatement.MikroORMIndex()
|
||||
tax_rate_id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@referenceIdIndexStatement.MikroORMIndex()
|
||||
reference_id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
reference: string
|
||||
|
||||
@ManyToOne(() => TaxRate, { persist: false })
|
||||
tax_rate: TaxRate
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | 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: "text", nullable: true })
|
||||
created_by: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: TABLE_NAME,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "txrule")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "txrule")
|
||||
}
|
||||
}
|
||||
126
packages/modules/tax/src/models/tax-rate.ts
Normal file
126
packages/modules/tax/src/models/tax-rate.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
Searchable,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import TaxRateRule from "./tax-rate-rule"
|
||||
import TaxRegion from "./tax-region"
|
||||
|
||||
type OptionalTaxRateProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const TABLE_NAME = "tax_rate"
|
||||
|
||||
export const singleDefaultRegionIndexName = "IDX_single_default_region"
|
||||
const singleDefaultRegionIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: singleDefaultRegionIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: "tax_region_id",
|
||||
unique: true,
|
||||
where: "is_default = true AND deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const taxRegionIdIndexName = "IDX_tax_rate_tax_region_id"
|
||||
const taxRegionIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: taxRegionIdIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: "tax_region_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@singleDefaultRegionIndexStatement.MikroORMIndex()
|
||||
@Entity({ tableName: TABLE_NAME })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class TaxRate {
|
||||
[OptionalProps]?: OptionalTaxRateProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "real", nullable: true })
|
||||
rate: number | null = null
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
code: string | null = null
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "bool", default: false })
|
||||
is_default = false
|
||||
|
||||
@Property({ columnType: "bool", default: false })
|
||||
is_combinable = false
|
||||
|
||||
@ManyToOne(() => TaxRegion, {
|
||||
columnType: "text",
|
||||
fieldName: "tax_region_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@taxRegionIdIndexStatement.MikroORMIndex()
|
||||
tax_region_id: string
|
||||
|
||||
@ManyToOne({ entity: () => TaxRegion, persist: false })
|
||||
tax_region: TaxRegion
|
||||
|
||||
@OneToMany(() => TaxRateRule, (rule) => rule.tax_rate, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
rules = new Collection<TaxRateRule>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | 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: "text", nullable: true })
|
||||
created_by: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: TABLE_NAME,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "txr")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "txr")
|
||||
}
|
||||
}
|
||||
138
packages/modules/tax/src/models/tax-region.ts
Normal file
138
packages/modules/tax/src/models/tax-region.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
Searchable,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Check,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import TaxProvider from "./tax-provider"
|
||||
import TaxRate from "./tax-rate"
|
||||
|
||||
type OptionalTaxRegionProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const TABLE_NAME = "tax_region"
|
||||
|
||||
export const countryCodeProvinceIndexName =
|
||||
"IDX_tax_region_unique_country_province"
|
||||
const countryCodeProvinceIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: countryCodeProvinceIndexName,
|
||||
tableName: TABLE_NAME,
|
||||
columns: ["country_code", "province_code"],
|
||||
unique: true,
|
||||
})
|
||||
|
||||
export const taxRegionProviderTopLevelCheckName =
|
||||
"CK_tax_region_provider_top_level"
|
||||
export const taxRegionCountryTopLevelCheckName =
|
||||
"CK_tax_region_country_top_level"
|
||||
|
||||
@Check({
|
||||
name: taxRegionProviderTopLevelCheckName,
|
||||
expression: `parent_id IS NULL OR provider_id IS NULL`,
|
||||
})
|
||||
@Check({
|
||||
name: taxRegionCountryTopLevelCheckName,
|
||||
expression: `parent_id IS NULL OR province_code IS NOT NULL`,
|
||||
})
|
||||
@countryCodeProvinceIndexStatement.MikroORMIndex()
|
||||
@Entity({ tableName: TABLE_NAME })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class TaxRegion {
|
||||
[OptionalProps]?: OptionalTaxRegionProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => TaxProvider, {
|
||||
fieldName: "provider_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
})
|
||||
provider_id: string | null = null
|
||||
|
||||
@ManyToOne(() => TaxProvider, { persist: false })
|
||||
provider: TaxProvider
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
country_code: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province_code: string | null = null
|
||||
|
||||
@ManyToOne(() => TaxRegion, {
|
||||
index: "IDX_tax_region_parent_id",
|
||||
fieldName: "parent_id",
|
||||
onDelete: "cascade",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
})
|
||||
parent_id: string | null = null
|
||||
|
||||
@ManyToOne(() => TaxRegion, { persist: false })
|
||||
parent: TaxRegion
|
||||
|
||||
@OneToMany(() => TaxRate, (label) => label.tax_region, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
tax_rates = new Collection<TaxRate>(this)
|
||||
|
||||
@OneToMany(() => TaxRegion, (label) => label.parent, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
children = new Collection<TaxRegion>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | 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: "text", nullable: true })
|
||||
created_by: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: TABLE_NAME,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "txreg")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "txreg")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user