feat(fulfillment): Initialize models work (#6328)
**What** Initialize work on the fulfillment module entities. This pr finally also include the indexes as i was working on some utilities i though it would make sense to test them directly. Also this pr add a new utility to generate proper index for our entity properties. It also include a new monkey patch for the migration generator to handle most of if exists/not exists cases. The monkey patch is a workaround the fact that the transpilation does work well with the ECMA used by mikro orm and therefore we end up with some constructor issue when mikro orm try to instanciate the custom generator class extension. **Comment** - The rule part will likely evolved when we reach the point of rule filtering based data, so no need for details review I believe FIXES CORE-1714 FIXES CORE-1715 FIXES CORE-1718 FIXES CORE-1722 FIXES CORE-1723 Current schema diagram 
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import * as entities from "./src/models"
|
||||
import { TSMigrationGenerator } from "@medusajs/utils"
|
||||
|
||||
module.exports = {
|
||||
entities: Object.values(entities),
|
||||
schema: "public",
|
||||
clientUrl: "postgres://postgres@localhost/medusa-fulfillment",
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: TSMigrationGenerator,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Index,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
type OptionalAddressProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const fulfillmentIdIndexName = "IDX_fulfillment_address_fulfillment_id"
|
||||
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentIdIndexName,
|
||||
tableName: "fulfillment_address",
|
||||
columns: "fulfillment_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const fulfillmentDeletedAtIndexName = "IDX_fulfillment_address_deleted_at"
|
||||
const fulfillmentDeletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentDeletedAtIndexName,
|
||||
tableName: "fulfillment_address",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "fulfillment_address" })
|
||||
export default class Address {
|
||||
[OptionalProps]: OptionalAddressProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@Index({
|
||||
name: fulfillmentIdIndexName,
|
||||
expression: fulfillmentIdIndexStatement,
|
||||
})
|
||||
fulfillment_id: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
company: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
first_name: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
last_name: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
address_1: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
address_2: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
country_code: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
postal_code: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
phone: string | null = null
|
||||
|
||||
@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: "timestamptz", nullable: true })
|
||||
@Index({
|
||||
name: fulfillmentDeletedAtIndexName,
|
||||
expression: fulfillmentDeletedAtIndexStatement,
|
||||
})
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fuladdr")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fuladdr")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import Fulfillment from "./fulfillment"
|
||||
|
||||
type FulfillmentItemOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const fulfillmentIdIndexName = "IDX_fulfillment_item_fulfillment_id"
|
||||
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentIdIndexName,
|
||||
tableName: "fulfillment_item",
|
||||
columns: "fulfillment_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const lineItemIndexName = "IDX_fulfillment_item_line_item_id"
|
||||
const lineItemIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentIdIndexName,
|
||||
tableName: "fulfillment_item",
|
||||
columns: "line_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const inventoryItemIndexName = "IDX_fulfillment_item_inventory_item_id"
|
||||
const inventoryItemIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentIdIndexName,
|
||||
tableName: "fulfillment_item",
|
||||
columns: "inventory_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const fulfillmentItemDeletedAtIndexName = "IDX_fulfillment_item_deleted_at"
|
||||
const fulfillmentItemDeletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentItemDeletedAtIndexName,
|
||||
tableName: "fulfillment_item",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentItem {
|
||||
[OptionalProps]?: FulfillmentItemOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
title: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
sku: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
barcode: string
|
||||
|
||||
@Property({ columnType: "numeric", serializer: Number })
|
||||
quantity: number // TODO: probably allow big numbers here
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@Index({
|
||||
name: lineItemIndexName,
|
||||
expression: lineItemIdIndexStatement,
|
||||
})
|
||||
line_item_id: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@Index({
|
||||
name: inventoryItemIndexName,
|
||||
expression: inventoryItemIdIndexStatement,
|
||||
})
|
||||
inventory_item_id: string | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: fulfillmentIdIndexName,
|
||||
expression: fulfillmentIdIndexStatement,
|
||||
})
|
||||
fulfillment_id: string
|
||||
|
||||
@ManyToOne(() => Fulfillment)
|
||||
fulfillment: Fulfillment
|
||||
|
||||
@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: fulfillmentItemDeletedAtIndexName,
|
||||
expression: fulfillmentItemDeletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fulit")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fulit")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import Fulfillment from "./fulfillment"
|
||||
|
||||
type FulfillmentLabelOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const fulfillmentIdIndexName = "IDX_fulfillment_label_fulfillment_id"
|
||||
const fulfillmentIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentIdIndexName,
|
||||
tableName: "fulfillment_label",
|
||||
columns: "fulfillment_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const providerIdIndexName = "IDX_fulfillment_label_provider_id"
|
||||
const providerIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: providerIdIndexName,
|
||||
tableName: "fulfillment_label",
|
||||
columns: "provider_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const deletedAtIndexName = "IDX_fulfillment_label_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "fulfillment_label",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentLabel {
|
||||
[OptionalProps]?: FulfillmentLabelOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
tracking_number: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
tracking_url: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
label_url: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: fulfillmentIdIndexName,
|
||||
expression: fulfillmentIdIndexStatement,
|
||||
})
|
||||
provider_id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: providerIdIndexName,
|
||||
expression: providerIdIndexStatement,
|
||||
})
|
||||
fulfillment_id: string
|
||||
|
||||
@ManyToOne(() => Fulfillment)
|
||||
fulfillment: Fulfillment
|
||||
|
||||
@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 })
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "fulla")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fulla")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import ServiceProvider from "./service-provider"
|
||||
import Address from "./address"
|
||||
import FulfillmentItem from "./fulfillment-item"
|
||||
import FulfillmentLabel from "./fulfillment-label"
|
||||
|
||||
type FulfillmentOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const fulfillmentDeletedAtIndexName = "IDX_fulfillment_deleted_at"
|
||||
const fulfillmentDeletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentDeletedAtIndexName,
|
||||
tableName: "fulfillment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const fulfillmentProviderIdIndexName = "IDX_fulfillment_provider_id"
|
||||
const fulfillmentProviderIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentProviderIdIndexName,
|
||||
tableName: "fulfillment",
|
||||
columns: "provider_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const fulfillmentLocationIdIndexName = "IDX_fulfillment_location_id"
|
||||
const fulfillmentLocationIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: fulfillmentLocationIdIndexName,
|
||||
tableName: "fulfillment",
|
||||
columns: "location_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const fulfillmentShippingOptionIdIndexName =
|
||||
"IDX_fulfillment_shipping_option_id"
|
||||
const fulfillmentShippingOptionIdIndexStatement =
|
||||
createPsqlIndexStatementHelper({
|
||||
name: fulfillmentShippingOptionIdIndexName,
|
||||
tableName: "fulfillment",
|
||||
columns: "shipping_option_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Fulfillment {
|
||||
[OptionalProps]?: FulfillmentOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: fulfillmentLocationIdIndexName,
|
||||
expression: fulfillmentLocationIdIndexStatement,
|
||||
})
|
||||
location_id: string
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
packed_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
shipped_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
delivered_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
canceled_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
data: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: fulfillmentProviderIdIndexName,
|
||||
expression: fulfillmentProviderIdIndexStatement,
|
||||
})
|
||||
provider_id: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@Index({
|
||||
name: fulfillmentShippingOptionIdIndexName,
|
||||
expression: fulfillmentShippingOptionIdIndexStatement,
|
||||
})
|
||||
shipping_option_id: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => ShippingOption, { nullable: true })
|
||||
shipping_option: ShippingOption | null
|
||||
|
||||
@ManyToOne(() => ServiceProvider)
|
||||
provider: ServiceProvider
|
||||
|
||||
@ManyToOne(() => Address)
|
||||
delivery_address: Address
|
||||
|
||||
@ManyToOne(() => FulfillmentItem)
|
||||
items: FulfillmentItem
|
||||
|
||||
@OneToMany(() => FulfillmentLabel, (label) => label.fulfillment)
|
||||
labels = new Collection<FulfillmentLabel>(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
|
||||
|
||||
@Index({
|
||||
name: fulfillmentDeletedAtIndexName,
|
||||
expression: fulfillmentDeletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ful")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ful")
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,34 @@
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ServiceZone from "./service-zone"
|
||||
|
||||
type FulfillmentSetOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_fulfillment_set_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "fulfillment_set",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class FulfillmentSet {
|
||||
@@ -25,6 +40,20 @@ export default class FulfillmentSet {
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
type: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToMany(() => ServiceZone, "fulfillment_sets", {
|
||||
owner: true,
|
||||
pivotTable: "fulfillment_set_service_zones",
|
||||
joinColumn: "fulfillment_set_id",
|
||||
inverseJoinColumn: "service_zone_id",
|
||||
})
|
||||
service_zones = new Collection<ServiceZone>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
@@ -40,8 +69,11 @@ export default class FulfillmentSet {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_fulfillment_set_deleted_at" })
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
GeoZoneType,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ServiceZone from "./service-zone"
|
||||
|
||||
type GeoZoneOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_geo_zone_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "geo_zone",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const countryCodeIndexName = "IDX_geo_zone_country_code"
|
||||
const countryCodeIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: countryCodeIndexName,
|
||||
tableName: "geo_zone",
|
||||
columns: "country_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const provinceCodeIndexName = "IDX_geo_zone_province_code"
|
||||
const provinceCodeIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: provinceCodeIndexName,
|
||||
tableName: "geo_zone",
|
||||
columns: "province_code",
|
||||
where: "deleted_at IS NULL AND province_code IS NOT NULL",
|
||||
})
|
||||
|
||||
const cityIndexName = "IDX_geo_zone_city"
|
||||
const cityIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: cityIndexName,
|
||||
tableName: "geo_zone",
|
||||
columns: "city",
|
||||
where: "deleted_at IS NULL AND city IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class GeoZone {
|
||||
[OptionalProps]?: GeoZoneOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Enum({ items: () => GeoZoneType, default: GeoZoneType.COUNTRY })
|
||||
type: GeoZoneType
|
||||
|
||||
@Index({
|
||||
name: countryCodeIndexName,
|
||||
expression: countryCodeIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "text" })
|
||||
country_code: string
|
||||
|
||||
@Index({
|
||||
name: provinceCodeIndexName,
|
||||
expression: provinceCodeIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province_code: string | null = null
|
||||
|
||||
@Index({
|
||||
name: cityIndexName,
|
||||
expression: cityIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null = null
|
||||
|
||||
// TODO: Do we have an example or idea of what would be stored in this field? like lat/long for example?
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
postal_expression: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToMany(() => ServiceZone, (serviceZone) => serviceZone.geo_zones)
|
||||
service_zones = new Collection<ServiceZone>(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
|
||||
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, " fgz")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "fgz")
|
||||
}
|
||||
}
|
||||
@@ -1 +1,12 @@
|
||||
export { default as FulfillmentSet } from "./fullfilment-set"
|
||||
export { default as Fulfillment } from "./fulfillment"
|
||||
export { default as Address } from "./address"
|
||||
export { default as GeoZone } from "./geo-zone"
|
||||
export { default as ServiceZone } from "./service-zone"
|
||||
export { default as FulfillmentItem } from "./fulfillment-item"
|
||||
export { default as FulfillmentLabel } from "./fulfillment-label"
|
||||
export { default as ServiceProvider } from "./service-provider"
|
||||
export { default as ShippingOption } from "./shipping-option"
|
||||
export { default as ShippingOptionType } from "./shipping-option-type"
|
||||
export { default as ShippingOptionRule } from "./shipping-option-rule"
|
||||
export { default as ShippingProfile } from "./shipping-profile"
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ShippingOption from "./shipping-option"
|
||||
|
||||
type ServiceProviderOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_service_provider_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "service_provider",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ServiceProvider {
|
||||
[OptionalProps]?: ServiceProviderOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingOption,
|
||||
(shippingOption) => shippingOption.service_provider
|
||||
)
|
||||
shipping_options = new Collection<ShippingOption>(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
|
||||
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "serpro")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "serpro")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import FulfillmentSet from "./fullfilment-set"
|
||||
import GeoZone from "./geo-zone"
|
||||
import ShippingOption from "./shipping-option"
|
||||
|
||||
type ServiceZoneOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_service_zone_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "service_zone",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ServiceZone {
|
||||
[OptionalProps]?: ServiceZoneOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToMany(
|
||||
() => FulfillmentSet,
|
||||
(fulfillmentSet) => fulfillmentSet.service_zones
|
||||
)
|
||||
fulfillment_sets = new Collection<FulfillmentSet>(this)
|
||||
|
||||
@ManyToMany(() => GeoZone, "service_zones", {
|
||||
owner: true,
|
||||
pivotTable: "service_zone_geo_zones",
|
||||
joinColumn: "service_zone_id",
|
||||
inverseJoinColumn: "geo_zone_id",
|
||||
})
|
||||
geo_zones = new Collection<GeoZone>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingOption,
|
||||
(shippingOption) => shippingOption.service_zone
|
||||
)
|
||||
shipping_options = new Collection<ShippingOption>(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
|
||||
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "serzo")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "serzo")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ShippingOption from "./shipping-option"
|
||||
|
||||
type ShippingOptionRuleOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
// TODO: need some test to see if we continue with this kind of structure or we change it
|
||||
// More adjustments can appear as I move forward
|
||||
|
||||
const deletedAtIndexName = "IDX_shipping_option_rule_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "shipping_option_rule",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOptionRule {
|
||||
[OptionalProps]?: ShippingOptionRuleOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
attribute: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
operator: string
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
value: { value: string | string[] } | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
shipping_option_id: string
|
||||
|
||||
@ManyToOne(() => ShippingOption)
|
||||
shipping_option: ShippingOption
|
||||
|
||||
@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: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sorul")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sorul")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ShippingOption from "./shipping-option"
|
||||
|
||||
type ShippingOptionTypeOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_shipping_option_type_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "shipping_option_type",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOptionType {
|
||||
[OptionalProps]?: ShippingOptionTypeOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
label: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@OneToOne(() => ShippingOption, (so) => so.shipping_option_type)
|
||||
shipping_option: ShippingOption
|
||||
|
||||
@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: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
ShippingOptionPriceType,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ServiceZone from "./service-zone"
|
||||
import ShippingProfile from "./shipping-profile"
|
||||
import ServiceProvider from "./service-provider"
|
||||
import ShippingOptionType from "./shipping-option-type"
|
||||
import ShippingOptionRule from "./shipping-option-rule"
|
||||
import Fulfillment from "./fulfillment"
|
||||
|
||||
type ShippingOptionOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_shipping_option_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "shipping_option",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const serviceZoneIdIndexName = "IDX_shipping_option_service_zone_id"
|
||||
const serviceZoneIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: serviceZoneIdIndexName,
|
||||
tableName: "shipping_option",
|
||||
columns: "service_zone_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const shippingProfileIdIndexName = "IDX_shipping_option_shipping_profile_id"
|
||||
const shippingProfileIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: shippingProfileIdIndexName,
|
||||
tableName: "shipping_option",
|
||||
columns: "shipping_profile_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const serviceProviderIdIndexName = "IDX_shipping_option_service_provider_id"
|
||||
const serviceProviderIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: serviceProviderIdIndexName,
|
||||
tableName: "shipping_option",
|
||||
columns: "service_provider_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const shippingOptionTypeIdIndexName =
|
||||
"IDX_shipping_option_shipping_option_type_id"
|
||||
const shippingOptionTypeIdIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: shippingOptionTypeIdIndexName,
|
||||
tableName: "shipping_option",
|
||||
columns: "shipping_option_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingOption {
|
||||
[OptionalProps]?: ShippingOptionOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Enum({
|
||||
items: () => ShippingOptionPriceType,
|
||||
default: ShippingOptionPriceType.CALCULATED,
|
||||
})
|
||||
price_type: ShippingOptionPriceType
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: serviceZoneIdIndexName,
|
||||
expression: serviceZoneIdIndexStatement,
|
||||
})
|
||||
service_zone_id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: shippingProfileIdIndexName,
|
||||
expression: shippingProfileIdIndexStatement,
|
||||
})
|
||||
shipping_profile_id: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@Index({
|
||||
name: serviceProviderIdIndexName,
|
||||
expression: serviceProviderIdIndexStatement,
|
||||
})
|
||||
service_provider_id: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@Index({
|
||||
name: shippingOptionTypeIdIndexName,
|
||||
expression: shippingOptionTypeIdIndexStatement,
|
||||
})
|
||||
shipping_option_type_id: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
data: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@ManyToOne(() => ServiceZone)
|
||||
service_zone: ServiceZone
|
||||
|
||||
@ManyToOne(() => ShippingProfile)
|
||||
shipping_profile: ShippingProfile
|
||||
|
||||
@ManyToOne(() => ServiceProvider)
|
||||
service_provider: ServiceProvider
|
||||
|
||||
@OneToOne(() => ShippingOptionType, (so) => so.shipping_option, {
|
||||
owner: true,
|
||||
})
|
||||
shipping_option_type: ShippingOptionType
|
||||
|
||||
@OneToMany(() => ShippingOptionRule, (sor) => sor.shipping_option)
|
||||
rules = new Collection<ShippingOptionRule>(this)
|
||||
|
||||
@OneToMany(() => Fulfillment, (fulfillment) => fulfillment.shipping_option)
|
||||
fulfillments = new Collection<Fulfillment>(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
|
||||
|
||||
@Index({
|
||||
name: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "so")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "so")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import ShippingOption from "./shipping-option"
|
||||
|
||||
type ShippingProfileOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const deletedAtIndexName = "IDX_shipping_profile_deleted_at"
|
||||
const deletedAtIndexStatement = createPsqlIndexStatementHelper({
|
||||
name: deletedAtIndexName,
|
||||
tableName: "shipping_profile",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingProfile {
|
||||
[OptionalProps]?: ShippingProfileOptionalProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingOption,
|
||||
(shippingOption) => shippingOption.shipping_profile
|
||||
)
|
||||
shipping_options = new Collection<ShippingOption>(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: deletedAtIndexName,
|
||||
expression: deletedAtIndexStatement,
|
||||
})
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sp")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sp")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user