feat(fulfillment): Shipping options, rules CRUD + rules based context filtering (#6455)
**What**
- Update shipping options with its rules and type
- create/update rules independently
- context based validation fundation
- 🔴 list shipping options with context rules fitlering will come in a separate pr to keep this one smaller
FIXES CORE-1743
FIXES CORE-1764
This commit is contained in:
@@ -74,7 +74,11 @@ export default class GeoZone {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@ManyToOne(() => ServiceZone, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "service_zone_id",
|
||||
})
|
||||
@ServiceZoneIdIndex.MikroORMIndex()
|
||||
service_zone_id: string
|
||||
|
||||
|
||||
@@ -61,7 +61,11 @@ export default class ServiceZone {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@ManyToOne(() => FulfillmentSet, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "fulfillment_set_id",
|
||||
})
|
||||
@FulfillmentSetIdIndex.MikroORMIndex()
|
||||
fulfillment_set_id: string
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import ShippingOption from "./shipping-option"
|
||||
import { RuleOperator } from "@utils"
|
||||
|
||||
type ShippingOptionRuleOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@@ -42,17 +44,26 @@ export default class ShippingOptionRule {
|
||||
@Property({ columnType: "text" })
|
||||
attribute: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
operator: string
|
||||
@Enum({
|
||||
items: () => Object.values(RuleOperator),
|
||||
columnType: "text",
|
||||
})
|
||||
operator: Lowercase<keyof typeof RuleOperator>
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
value: { value: string | string[] } | null = null
|
||||
value: string | string[] | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@ManyToOne(() => ShippingOption, {
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "shipping_option_id",
|
||||
})
|
||||
@ShippingOptionIdIndex.MikroORMIndex()
|
||||
shipping_option_id: string
|
||||
|
||||
@ManyToOne(() => ShippingOption, { persist: false })
|
||||
@ManyToOne(() => ShippingOption, {
|
||||
persist: false,
|
||||
})
|
||||
shipping_option: ShippingOption
|
||||
|
||||
@Property({
|
||||
|
||||
@@ -48,12 +48,8 @@ export default class ShippingOptionType {
|
||||
@Property({ columnType: "text" })
|
||||
code: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@ShippingOptionIdIndex.MikroORMIndex()
|
||||
shipping_option_id: string
|
||||
|
||||
@OneToOne(() => ShippingOption, (so) => so.type, {
|
||||
persist: false,
|
||||
type: "text",
|
||||
})
|
||||
shipping_option: ShippingOption
|
||||
|
||||
@@ -79,12 +75,10 @@ export default class ShippingOptionType {
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
this.shipping_option_id ??= this.shipping_option?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "sotype")
|
||||
this.shipping_option_id ??= this.shipping_option?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export default class ShippingOption {
|
||||
})
|
||||
price_type: ShippingOptionPriceType
|
||||
|
||||
@ManyToOne(() => ShippingProfile, {
|
||||
@ManyToOne(() => ServiceZone, {
|
||||
type: "text",
|
||||
fieldName: "service_zone_id",
|
||||
mapToPk: true,
|
||||
@@ -129,6 +129,7 @@ export default class ShippingOption {
|
||||
@OneToOne(() => ShippingOptionType, (so) => so.shipping_option, {
|
||||
owner: true,
|
||||
cascade: [Cascade.PERSIST, Cascade.REMOVE, "soft-remove"] as any,
|
||||
orphanRemoval: true,
|
||||
fieldName: "shipping_option_type_id",
|
||||
})
|
||||
type: ShippingOptionType
|
||||
|
||||
Reference in New Issue
Block a user