feat(pricing,utils,types): add operator field to price rule (#10315)
what: - adds an operator field to price rule with specific operator fields RESOLVES CMRC-746
This commit is contained in:
1 parent
2838100efc
commit
3b1a63eca7
8 files changed
+91
-6
No files matched your search
@@ -133,3 +133,8 @@ export interface FilterablePriceRuleProps
|
|||||||
*/
|
*/
|
||||||
price_set_id?: string[]
|
price_set_id?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The possible operators to use in a price rule.
|
||||||
|
*/
|
||||||
|
export type PricingRuleOperatorValues = "gt" | "lt" | "eq" | "lte" | "gte"
|
||||||
@@ -6,14 +6,15 @@ export * as DMLUtils from "./dml"
|
|||||||
export * as EventBusUtils from "./event-bus"
|
export * as EventBusUtils from "./event-bus"
|
||||||
export * as FeatureFlagUtils from "./feature-flags"
|
export * as FeatureFlagUtils from "./feature-flags"
|
||||||
export * as FulfillmentUtils from "./fulfillment"
|
export * as FulfillmentUtils from "./fulfillment"
|
||||||
|
export * as GraphQLUtils from "./graphql"
|
||||||
export * as InventoryUtils from "./inventory"
|
export * as InventoryUtils from "./inventory"
|
||||||
export * as LinkUtils from "./link"
|
export * as LinkUtils from "./link"
|
||||||
export * as ModulesSdkUtils from "./modules-sdk"
|
export * as ModulesSdkUtils from "./modules-sdk"
|
||||||
export * as OrchestrationUtils from "./orchestration"
|
export * as OrchestrationUtils from "./orchestration"
|
||||||
export * as OrderUtils from "./order"
|
export * as OrderUtils from "./order"
|
||||||
|
export * as PricingUtils from "./pricing"
|
||||||
export * as ProductUtils from "./product"
|
export * as ProductUtils from "./product"
|
||||||
export * as PromotionUtils from "./promotion"
|
export * as PromotionUtils from "./promotion"
|
||||||
export * as SearchUtils from "./search"
|
export * as SearchUtils from "./search"
|
||||||
export * as ShippingProfileUtils from "./shipping"
|
export * as ShippingProfileUtils from "./shipping"
|
||||||
export * as UserUtils from "./user"
|
export * as UserUtils from "./user"
|
||||||
export * as GraphQLUtils from "./graphql"
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export enum PricingRuleOperator {
|
||||||
|
GTE = "gte",
|
||||||
|
LTE = "lte",
|
||||||
|
GT = "gt",
|
||||||
|
LT = "lt",
|
||||||
|
EQ = "eq",
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from "./builders"
|
export * from "./builders"
|
||||||
export * from "./price-list"
|
export * from "./enums"
|
||||||
export * from "./events"
|
export * from "./events"
|
||||||
|
export * from "./price-list"
|
||||||
@@ -628,6 +628,17 @@
|
|||||||
"nullable": false,
|
"nullable": false,
|
||||||
"mappedType": "text"
|
"mappedType": "text"
|
||||||
},
|
},
|
||||||
|
"operator": {
|
||||||
|
"name": "operator",
|
||||||
|
"type": "text",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": false,
|
||||||
|
"default": "'eq'",
|
||||||
|
"enumItems": ["gte", "lte", "gt", "lt", "eq"],
|
||||||
|
"mappedType": "enum"
|
||||||
|
},
|
||||||
"value": {
|
"value": {
|
||||||
"name": "value",
|
"name": "value",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -693,12 +704,19 @@
|
|||||||
"schema": "public",
|
"schema": "public",
|
||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"keyName": "IDX_price_rule_price_id_attribute_unique",
|
"columnNames": ["operator"],
|
||||||
|
"composite": false,
|
||||||
|
"keyName": "IDX_price_rule_operator",
|
||||||
|
"primary": false,
|
||||||
|
"unique": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"keyName": "IDX_price_rule_price_id_attribute_operator_unique",
|
||||||
"columnNames": ["price_id"],
|
"columnNames": ["price_id"],
|
||||||
"composite": false,
|
"composite": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"unique": false,
|
"unique": false,
|
||||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_id_attribute_unique\" ON \"price_rule\" (price_id, attribute) WHERE deleted_at IS NULL"
|
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_id_attribute_operator_unique\" ON \"price_rule\" (price_id, attribute, operator) WHERE deleted_at IS NULL"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyName": "IDX_price_rule_deleted_at",
|
"keyName": "IDX_price_rule_deleted_at",
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Migration } from "@mikro-orm/migrations"
|
||||||
|
|
||||||
|
export class Migration20241127114534 extends Migration {
|
||||||
|
async up(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
`alter table if exists "price_rule" add column if not exists "operator" text check ("operator" in ('gte', 'lte', 'gt', 'lt', 'eq'));`
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
`update "price_rule" set "operator" = 'eq' where "operator" is null;`
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
`alter table "price_rule" alter column "operator" set not null, alter column "operator" set default 'eq';`
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_price_rule_operator" on "price_rule" ("operator");'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
this.addSql('drop index if exists "IDX_price_rule_operator";')
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "price_rule" drop column if exists "operator";'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Migration } from "@mikro-orm/migrations"
|
||||||
|
|
||||||
|
export class Migration20241127223829 extends Migration {
|
||||||
|
async up(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
'drop index if exists "IDX_price_rule_price_id_attribute_unique";'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_attribute_operator_unique" ON "price_rule" (price_id, attribute, operator) WHERE deleted_at IS NULL;'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
'drop index if exists "IDX_price_rule_price_id_attribute_operator_unique";'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_attribute_unique" ON "price_rule" (price_id, attribute) WHERE deleted_at IS NULL;'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import { DAL } from "@medusajs/framework/types"
|
import { DAL, PricingRuleOperatorValues } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
createPsqlIndexStatementHelper,
|
createPsqlIndexStatementHelper,
|
||||||
DALUtils,
|
DALUtils,
|
||||||
generateEntityId,
|
generateEntityId,
|
||||||
|
PricingRuleOperator,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Entity,
|
Entity,
|
||||||
|
Enum,
|
||||||
Filter,
|
Filter,
|
||||||
|
Index,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OnInit,
|
OnInit,
|
||||||
OptionalProps,
|
OptionalProps,
|
||||||
@@ -28,7 +31,7 @@ const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
|||||||
|
|
||||||
const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
|
const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: tableName,
|
tableName: tableName,
|
||||||
columns: ["price_id", "attribute"],
|
columns: ["price_id", "attribute", "operator"],
|
||||||
where: "deleted_at IS NULL",
|
where: "deleted_at IS NULL",
|
||||||
unique: true,
|
unique: true,
|
||||||
})
|
})
|
||||||
@@ -44,6 +47,10 @@ export default class PriceRule {
|
|||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
attribute: string
|
attribute: string
|
||||||
|
|
||||||
|
@Index({ name: "IDX_price_rule_operator" })
|
||||||
|
@Enum({ items: () => PricingRuleOperator, default: PricingRuleOperator.EQ })
|
||||||
|
operator: PricingRuleOperatorValues = PricingRuleOperator.EQ
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
value: string
|
value: string
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user