chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
44
packages/modules/region/src/models/country.ts
Normal file
44
packages/modules/region/src/models/country.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Entity, ManyToOne, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
|
||||
import { createPsqlIndexStatementHelper } from "@medusajs/utils"
|
||||
import Region from "./region"
|
||||
|
||||
// We don't need a partial index on deleted_at here since we don't support soft deletes on countries
|
||||
const regionIdIsoIndexName = "IDX_region_country_region_id_iso_2_unique"
|
||||
const RegionIdIsoIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: regionIdIsoIndexName,
|
||||
tableName: "region_country",
|
||||
columns: ["region_id", "iso_2"],
|
||||
unique: true,
|
||||
})
|
||||
|
||||
RegionIdIsoIndexStatement.MikroORMIndex()
|
||||
@Entity({ tableName: "region_country" })
|
||||
export default class Country {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
@Property({ columnType: "text" })
|
||||
iso_2: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
iso_3: string
|
||||
|
||||
@Property({ columnType: "int" })
|
||||
num_code: number
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
display_name: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
region_id?: string | null = null
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Region,
|
||||
fieldName: "region_id",
|
||||
nullable: true,
|
||||
onDelete: "set null",
|
||||
})
|
||||
region?: Region | null
|
||||
}
|
||||
2
packages/modules/region/src/models/index.ts
Normal file
2
packages/modules/region/src/models/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as Country } from "./country"
|
||||
export { default as Region } from "./region"
|
||||
72
packages/modules/region/src/models/region.ts
Normal file
72
packages/modules/region/src/models/region.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { DALUtils, Searchable, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Country from "./country"
|
||||
|
||||
type RegionOptionalProps = "countries" | DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity({ tableName: "region" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Region {
|
||||
[OptionalProps]?: RegionOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@Property({ columnType: "boolean" })
|
||||
automatic_taxes = true
|
||||
|
||||
@OneToMany(() => Country, (country) => country.region)
|
||||
countries = new Collection<Country>(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
|
||||
|
||||
@Index({ name: "IDX_region_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "reg")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "reg")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user