feat(core-flows,medusa,types,utils): rename psma to prices (#6796)
What: Renames pricesetmoneyamount to prices Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
fbc369705d
commit
9073d7aba3
@@ -1,13 +1,13 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import { PriceList, PriceSet, PriceSetMoneyAmount } from "@models"
|
||||
import { Price, PriceList, PriceSet } from "@models"
|
||||
import schema from "./schema"
|
||||
|
||||
export const LinkableKeys = {
|
||||
price_set_id: PriceSet.name,
|
||||
price_list_id: PriceList.name,
|
||||
price_set_money_amount_id: PriceSetMoneyAmount.name,
|
||||
price_id: Price.name,
|
||||
}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
|
||||
@@ -1,125 +1,7 @@
|
||||
{
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"namespaces": ["public"],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"currency_code": {
|
||||
"name": "currency_code",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"amount": {
|
||||
"name": "amount",
|
||||
"type": "numeric",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"min_quantity": {
|
||||
"name": "min_quantity",
|
||||
"type": "numeric",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"max_quantity": {
|
||||
"name": "max_quantity",
|
||||
"type": "numeric",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
}
|
||||
},
|
||||
"name": "money_amount",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_money_amount_currency_code",
|
||||
"columnNames": [
|
||||
"currency_code"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_money_amount_currency_code\" ON \"money_amount\" (currency_code) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_money_amount_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_money_amount_deleted_at\" ON \"money_amount\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "money_amount_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
@@ -157,10 +39,7 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'draft'",
|
||||
"enumItems": [
|
||||
"active",
|
||||
"draft"
|
||||
],
|
||||
"enumItems": ["active", "draft"],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"type": {
|
||||
@@ -171,10 +50,7 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'sale'",
|
||||
"enumItems": [
|
||||
"sale",
|
||||
"override"
|
||||
],
|
||||
"enumItems": ["sale", "override"],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"starts_at": {
|
||||
@@ -245,9 +121,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_list_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -255,9 +129,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_list_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -315,9 +187,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_set_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -325,9 +195,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_set_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -453,54 +321,44 @@
|
||||
"mappedType": "datetime"
|
||||
}
|
||||
},
|
||||
"name": "price_set_money_amount",
|
||||
"name": "price",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_set_money_amount_currency_code",
|
||||
"columnNames": [
|
||||
"currency_code"
|
||||
],
|
||||
"keyName": "IDX_price_currency_code",
|
||||
"columnNames": ["currency_code"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_currency_code\" ON \"price_set_money_amount\" (currency_code) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_currency_code\" ON \"price\" (currency_code) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_set_money_amount_price_set_id",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"keyName": "IDX_price_price_set_id",
|
||||
"columnNames": ["price_set_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_price_set_id\" ON \"price_set_money_amount\" (price_set_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_price_set_id\" ON \"price\" (price_set_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_set_money_amount_price_list_id",
|
||||
"columnNames": [
|
||||
"price_list_id"
|
||||
],
|
||||
"keyName": "IDX_price_price_list_id",
|
||||
"columnNames": ["price_list_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_price_list_id\" ON \"price_set_money_amount\" (price_list_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_price_list_id\" ON \"price\" (price_list_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_set_money_amount_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"keyName": "IDX_price_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_deleted_at\" ON \"price_set_money_amount\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_deleted_at\" ON \"price\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "price_set_money_amount_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"keyName": "price_pkey",
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -508,28 +366,20 @@
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"price_set_money_amount_price_set_id_foreign": {
|
||||
"constraintName": "price_set_money_amount_price_set_id_foreign",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"localTableName": "public.price_set_money_amount",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"price_price_set_id_foreign": {
|
||||
"constraintName": "price_price_set_id_foreign",
|
||||
"columnNames": ["price_set_id"],
|
||||
"localTableName": "public.price",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_set",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"price_set_money_amount_price_list_id_foreign": {
|
||||
"constraintName": "price_set_money_amount_price_list_id_foreign",
|
||||
"columnNames": [
|
||||
"price_list_id"
|
||||
],
|
||||
"localTableName": "public.price_set_money_amount",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"price_price_list_id_foreign": {
|
||||
"constraintName": "price_price_list_id_foreign",
|
||||
"columnNames": ["price_list_id"],
|
||||
"localTableName": "public.price",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_list",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -613,9 +463,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_rule_type_rule_attribute",
|
||||
"columnNames": [
|
||||
"rule_attribute"
|
||||
],
|
||||
"columnNames": ["rule_attribute"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -623,9 +471,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_rule_type_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -633,9 +479,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "rule_type_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -711,9 +555,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_set_rule_type_price_set_id",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"columnNames": ["price_set_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -721,9 +563,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_set_rule_type_rule_type_id",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -731,9 +571,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_set_rule_type_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -741,9 +579,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_set_rule_type_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -753,26 +589,18 @@
|
||||
"foreignKeys": {
|
||||
"price_set_rule_type_price_set_id_foreign": {
|
||||
"constraintName": "price_set_rule_type_price_set_id_foreign",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"columnNames": ["price_set_id"],
|
||||
"localTableName": "public.price_set_rule_type",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_set",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"price_set_rule_type_rule_type_id_foreign": {
|
||||
"constraintName": "price_set_rule_type_rule_type_id_foreign",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"localTableName": "public.price_set_rule_type",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.rule_type",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -827,8 +655,8 @@
|
||||
"default": "0",
|
||||
"mappedType": "integer"
|
||||
},
|
||||
"price_set_money_amount_id": {
|
||||
"name": "price_set_money_amount_id",
|
||||
"price_id": {
|
||||
"name": "price_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
@@ -874,9 +702,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_rule_price_set_id",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"columnNames": ["price_set_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -884,29 +710,23 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_rule_rule_type_id",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_rule_rule_type_id\" ON \"price_rule\" (rule_type_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_rule_price_set_money_amount_id_unique",
|
||||
"columnNames": [
|
||||
"price_set_money_amount_id"
|
||||
],
|
||||
"keyName": "IDX_price_rule_price_id_rule_type_id_unique",
|
||||
"columnNames": ["price_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_set_money_amount_id_unique\" ON \"price_rule\" (price_set_money_amount_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_id_rule_type_id_unique\" ON \"price_rule\" (price_id, rule_type_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_rule_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -914,9 +734,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_rule_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -926,39 +744,27 @@
|
||||
"foreignKeys": {
|
||||
"price_rule_price_set_id_foreign": {
|
||||
"constraintName": "price_rule_price_set_id_foreign",
|
||||
"columnNames": [
|
||||
"price_set_id"
|
||||
],
|
||||
"columnNames": ["price_set_id"],
|
||||
"localTableName": "public.price_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_set",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"price_rule_rule_type_id_foreign": {
|
||||
"constraintName": "price_rule_rule_type_id_foreign",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"localTableName": "public.price_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.rule_type",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"price_rule_price_set_money_amount_id_foreign": {
|
||||
"constraintName": "price_rule_price_set_money_amount_id_foreign",
|
||||
"columnNames": [
|
||||
"price_set_money_amount_id"
|
||||
],
|
||||
"price_rule_price_id_foreign": {
|
||||
"constraintName": "price_rule_price_id_foreign",
|
||||
"columnNames": ["price_id"],
|
||||
"localTableName": "public.price_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.price_set_money_amount",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
@@ -1031,9 +837,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_list_rule_rule_type_id_unique",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1041,9 +845,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_list_rule_price_list_id",
|
||||
"columnNames": [
|
||||
"price_list_id"
|
||||
],
|
||||
"columnNames": ["price_list_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1051,9 +853,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_list_rule_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1061,9 +861,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_list_rule_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1073,25 +871,17 @@
|
||||
"foreignKeys": {
|
||||
"price_list_rule_rule_type_id_foreign": {
|
||||
"constraintName": "price_list_rule_rule_type_id_foreign",
|
||||
"columnNames": [
|
||||
"rule_type_id"
|
||||
],
|
||||
"columnNames": ["rule_type_id"],
|
||||
"localTableName": "public.price_list_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.rule_type",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"price_list_rule_price_list_id_foreign": {
|
||||
"constraintName": "price_list_rule_price_list_id_foreign",
|
||||
"columnNames": [
|
||||
"price_list_id"
|
||||
],
|
||||
"columnNames": ["price_list_id"],
|
||||
"localTableName": "public.price_list_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_list",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -1165,9 +955,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_price_list_rule_value_price_list_rule_id",
|
||||
"columnNames": [
|
||||
"price_list_rule_id"
|
||||
],
|
||||
"columnNames": ["price_list_rule_id"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1175,9 +963,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_price_list_rule_value_deleted_at",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
@@ -1185,9 +971,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "price_list_rule_value_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -1197,13 +981,9 @@
|
||||
"foreignKeys": {
|
||||
"price_list_rule_value_price_list_rule_id_foreign": {
|
||||
"constraintName": "price_list_rule_value_price_list_rule_id_foreign",
|
||||
"columnNames": [
|
||||
"price_list_rule_id"
|
||||
],
|
||||
"columnNames": ["price_list_rule_id"],
|
||||
"localTableName": "public.price_list_rule_value",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.price_list_rule",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
|
||||
@@ -11,11 +11,11 @@ export class Migration20230929122253 extends Migration {
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_set_money_amount" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_money_amount_pkey" primary key ("id"));'
|
||||
'create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_set_money_amount" add constraint "price_set_money_amount_money_amount_id_unique" unique ("money_amount_id");'
|
||||
'alter table "price" add constraint "price_money_amount_id_unique" unique ("money_amount_id");'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
@@ -27,14 +27,14 @@ export class Migration20230929122253 extends Migration {
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_rule" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "value" text not null, "priority" integer not null default 0, "price_set_money_amount_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_rule_pkey" primary key ("id"));'
|
||||
'create table "price_rule" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "value" text not null, "priority" integer not null default 0, "price_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_rule_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
|
||||
'alter table "price" add constraint "price_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_set_money_amount" add constraint "price_set_money_amount_money_amount_id_foreign" foreign key ("money_amount_id") references "money_amount" ("id") on update cascade on delete cascade;'
|
||||
'alter table "price" add constraint "price_money_amount_id_foreign" foreign key ("money_amount_id") references "money_amount" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
@@ -51,7 +51,7 @@ export class Migration20230929122253 extends Migration {
|
||||
'alter table "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_rule" add constraint "price_rule_price_set_money_amount_id_foreign" foreign key ("price_set_money_amount_id") references "price_set_money_amount" ("id") on update cascade on delete cascade;'
|
||||
'alter table "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
@@ -69,9 +69,7 @@ export class Migration20230929122253 extends Migration {
|
||||
'alter table "price_list_rule" add constraint "price_list_rule_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_set_money_amount" add column "price_list_id" text null;'
|
||||
)
|
||||
this.addSql('alter table "price" add column "price_list_id" text null;')
|
||||
|
||||
this.addSql('alter table "price_rule" drop column "price_list_id";')
|
||||
|
||||
@@ -112,16 +110,16 @@ export class Migration20230929122253 extends Migration {
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_deleted_at" ON "price_set" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_price_set_id" ON "price_set_money_amount" (price_set_id) WHERE deleted_at IS NULL;'
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_price_set_id" ON "price" (price_set_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_money_amount_id" ON "price_set_money_amount" (money_amount_id) WHERE deleted_at IS NULL;'
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_money_amount_id" ON "price" (money_amount_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_price_list_id" ON "price_set_money_amount" (price_list_id) WHERE deleted_at IS NULL;'
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_price_list_id" ON "price" (price_list_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_deleted_at" ON "price_set_money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_deleted_at" ON "price" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_rule_type_rule_attribute" ON "rule_type" (rule_attribute) WHERE deleted_at IS NOT NULL;'
|
||||
@@ -146,7 +144,7 @@ export class Migration20230929122253 extends Migration {
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_rule_type_id" ON "price_rule" (rule_type_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_set_money_amount_id_unique" ON "price_rule" (price_set_money_amount_id) WHERE deleted_at IS NOT NULL;'
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_deleted_at" ON "price_rule" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
@@ -172,7 +170,7 @@ export class Migration20230929122253 extends Migration {
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
|
||||
'alter table if exists "price" add constraint "price_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
@@ -208,27 +206,25 @@ export class Migration20230929122253 extends Migration {
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_money_amount" drop constraint if exists "price_set_money_amount_money_amount_id_foreign";'
|
||||
'alter table if exists "price" drop constraint if exists "price_money_amount_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_money_amount" add column if not exists "amount" numeric not null, add column "min_quantity" numeric null, add column "max_quantity" numeric null;'
|
||||
'alter table if exists "price" add column if not exists "amount" numeric not null, add column "min_quantity" numeric null, add column "max_quantity" numeric null;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_money_amount" drop constraint if exists "price_set_money_amount_money_amount_id_unique";'
|
||||
'alter table if exists "price" drop constraint if exists "price_money_amount_id_unique";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_money_amount_id";')
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" rename column "money_amount_id" to "currency_code";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'drop index if exists "IDX_price_set_money_amount_money_amount_id";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_money_amount" rename column "money_amount_id" to "currency_code";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_currency_code" ON "price_set_money_amount" (currency_code) WHERE deleted_at IS NULL;'
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_currency_code" ON "price" (currency_code) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20240322094407 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop table if exists "money_amount" cascade;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('create table if not exists "money_amount" ("id" text not null, "currency_code" text not null, "amount" numeric not null, "min_quantity" numeric null, "max_quantity" numeric null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "money_amount_pkey" primary key ("id"));');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_money_amount_currency_code" ON "money_amount" (currency_code) WHERE deleted_at IS NULL;');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_money_amount_deleted_at" ON "money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240322113359 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_price_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_price_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240322120125 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_rule_type_id_unique" ON "price_rule" (price_id, rule_type_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'drop index if exists "IDX_price_rule_price_id_rule_type_id_unique";'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
export { default as Price } from "./price"
|
||||
export { default as PriceList } from "./price-list"
|
||||
export { default as PriceListRule } from "./price-list-rule"
|
||||
export { default as PriceListRuleValue } from "./price-list-rule-value"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
export { default as PriceSet } from "./price-set"
|
||||
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
|
||||
export { default as PriceSetRuleType } from "./price-set-rule-type"
|
||||
export { default as RuleType } from "./rule-type"
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceListRule from "./price-list-rule"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields =
|
||||
@@ -68,10 +68,10 @@ export default class PriceList {
|
||||
})
|
||||
ends_at: Date | null = null
|
||||
|
||||
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_list, {
|
||||
@OneToMany(() => Price, (price) => price.price_list, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceListRule, (pr) => pr.price_list, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
@@ -14,8 +14,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceSet from "./price-set"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
@@ -39,9 +39,9 @@ const PriceRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceSetMoneyAmountIdIndex = createPsqlIndexStatementHelper({
|
||||
const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_money_amount_id",
|
||||
columns: ["price_id", "rule_type_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
@@ -83,17 +83,17 @@ export default class PriceRule {
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
priority: number = 0
|
||||
|
||||
@PriceRulePriceSetMoneyAmountIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSetMoneyAmount, {
|
||||
@PriceRulePriceIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => Price, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_money_amount_id",
|
||||
fieldName: "price_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_money_amount_id: string
|
||||
price_id: string
|
||||
|
||||
@ManyToOne(() => PriceSetMoneyAmount, { persist: false })
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
@ManyToOne(() => Price, { persist: false })
|
||||
price: Price
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
@@ -117,10 +117,16 @@ export default class PriceRule {
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,22 @@ export default class PriceSetRuleType {
|
||||
id!: string
|
||||
|
||||
@PriceSetRuleTypePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
|
||||
price_set: PriceSet
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@PriceSetRuleTypeRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, { onDelete: "cascade" })
|
||||
rule_type: RuleType
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
|
||||
@@ -15,8 +15,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import PriceSetRuleType from "./price-set-rule-type"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
@@ -33,13 +33,13 @@ export default class PriceSet {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_set, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
@OneToMany(() => Price, (price) => price.price_set, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
|
||||
+20
-22
@@ -1,7 +1,7 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
@@ -23,32 +23,26 @@ import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_set_money_amount"
|
||||
const PriceSetMoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
const tableName = "price"
|
||||
const PriceDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountPriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
const PricePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountMoneyAmountIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "money_amount_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountPriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
const PricePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
const PriceCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
@@ -56,7 +50,7 @@ const PriceSetMoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetMoneyAmount {
|
||||
export default class Price {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
@@ -65,7 +59,7 @@ export default class PriceSetMoneyAmount {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
title: string | null = null
|
||||
|
||||
@PriceSetMoneyAmountCurrencyCodeIndex.MikroORMIndex()
|
||||
@PriceCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@@ -78,7 +72,7 @@ export default class PriceSetMoneyAmount {
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
max_quantity: number | null = null
|
||||
|
||||
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
|
||||
@PricePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
@@ -95,12 +89,12 @@ export default class PriceSetMoneyAmount {
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceRule,
|
||||
mappedBy: (pr) => pr.price_set_money_amount,
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
mappedBy: (pr) => pr.price,
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@PriceSetMoneyAmountPriceListIdIndex.MikroORMIndex()
|
||||
@PricePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
@@ -128,17 +122,21 @@ export default class PriceSetMoneyAmount {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceSetMoneyAmountDeletedAtIndex.MikroORMIndex()
|
||||
@PriceDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psma")
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "psma")
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
}
|
||||
@@ -57,27 +57,27 @@ export class PricingRepository
|
||||
const date = new Date().toISOString()
|
||||
// Gets all the price set money amounts where rules match for each of the contexts
|
||||
// that the price set is configured for
|
||||
const psmaSubQueryKnex = knex({
|
||||
psma: "price_set_money_amount",
|
||||
const priceSubQueryKnex = knex({
|
||||
price: "price",
|
||||
})
|
||||
.select({
|
||||
id: "psma1.id",
|
||||
amount: "psma1.amount",
|
||||
min_quantity: "psma1.min_quantity",
|
||||
max_quantity: "psma1.max_quantity",
|
||||
currency_code: "psma1.currency_code",
|
||||
price_set_id: "psma1.price_set_id",
|
||||
rules_count: "psma1.rules_count",
|
||||
price_list_id: "psma1.price_list_id",
|
||||
id: "price1.id",
|
||||
amount: "price1.amount",
|
||||
min_quantity: "price1.min_quantity",
|
||||
max_quantity: "price1.max_quantity",
|
||||
currency_code: "price1.currency_code",
|
||||
price_set_id: "price1.price_set_id",
|
||||
rules_count: "price1.rules_count",
|
||||
price_list_id: "price1.price_list_id",
|
||||
pl_rules_count: "pl.rules_count",
|
||||
pl_type: "pl.type",
|
||||
has_price_list: knex.raw(
|
||||
"case when psma1.price_list_id IS NULL then False else True end"
|
||||
"case when price1.price_list_id IS NULL then False else True end"
|
||||
),
|
||||
})
|
||||
.leftJoin("price_set_money_amount as psma1", "psma1.id", "psma1.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_set_money_amount_id", "psma1.id")
|
||||
.leftJoin("price_list as pl", "pl.id", "psma1.price_list_id")
|
||||
.leftJoin("price as price1", "price1.id", "price1.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_id", "price1.id")
|
||||
.leftJoin("price_list as pl", "pl.id", "price1.price_list_id")
|
||||
.leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
|
||||
.leftJoin(
|
||||
"price_list_rule_value as plrv",
|
||||
@@ -90,31 +90,31 @@ export class PricingRepository
|
||||
{ column: "rules_count", order: "desc" },
|
||||
{ column: "pl.rules_count", order: "desc" },
|
||||
])
|
||||
.groupBy("psma1.id", "pl.id")
|
||||
.groupBy("price1.id", "pl.id")
|
||||
.having(
|
||||
knex.raw(
|
||||
"count(DISTINCT rt.rule_attribute) = psma1.rules_count AND psma1.price_list_id IS NULL"
|
||||
"count(DISTINCT rt.rule_attribute) = price1.rules_count AND price1.price_list_id IS NULL"
|
||||
)
|
||||
)
|
||||
.orHaving(
|
||||
knex.raw(
|
||||
"count(DISTINCT plrt.rule_attribute) = pl.rules_count AND psma1.price_list_id IS NOT NULL"
|
||||
"count(DISTINCT plrt.rule_attribute) = pl.rules_count AND price1.price_list_id IS NOT NULL"
|
||||
)
|
||||
)
|
||||
|
||||
psmaSubQueryKnex.orWhere((q) => {
|
||||
priceSubQueryKnex.orWhere((q) => {
|
||||
for (const [key, value] of Object.entries(context)) {
|
||||
q.orWhere({
|
||||
"rt.rule_attribute": key,
|
||||
"pr.value": value,
|
||||
})
|
||||
}
|
||||
q.orWhere("psma1.rules_count", "=", 0)
|
||||
q.whereNull("psma1.price_list_id")
|
||||
q.orWhere("price1.rules_count", "=", 0)
|
||||
q.whereNull("price1.price_list_id")
|
||||
})
|
||||
|
||||
psmaSubQueryKnex.orWhere((q) => {
|
||||
q.whereNotNull("psma1.price_list_id")
|
||||
priceSubQueryKnex.orWhere((q) => {
|
||||
q.whereNotNull("price1.price_list_id")
|
||||
.andWhere(function () {
|
||||
this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date)
|
||||
})
|
||||
@@ -141,9 +141,9 @@ export class PricingRepository
|
||||
"pr.value": value,
|
||||
})
|
||||
}
|
||||
this.andWhere("psma1.rules_count", ">", 0)
|
||||
this.andWhere("price1.rules_count", ">", 0)
|
||||
})
|
||||
this.orWhere("psma1.rules_count", "=", 0)
|
||||
this.orWhere("price1.rules_count", "=", 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -152,38 +152,38 @@ export class PricingRepository
|
||||
ps: "price_set",
|
||||
})
|
||||
.select({
|
||||
id: "psma.id",
|
||||
id: "price.id",
|
||||
price_set_id: "ps.id",
|
||||
amount: "psma.amount",
|
||||
min_quantity: "psma.min_quantity",
|
||||
max_quantity: "psma.max_quantity",
|
||||
currency_code: "psma.currency_code",
|
||||
amount: "price.amount",
|
||||
min_quantity: "price.min_quantity",
|
||||
max_quantity: "price.max_quantity",
|
||||
currency_code: "price.currency_code",
|
||||
default_priority: "rt.default_priority",
|
||||
rules_count: "psma.rules_count",
|
||||
pl_rules_count: "psma.pl_rules_count",
|
||||
price_list_type: "psma.pl_type",
|
||||
price_list_id: "psma.price_list_id",
|
||||
rules_count: "price.rules_count",
|
||||
pl_rules_count: "price.pl_rules_count",
|
||||
price_list_type: "price.pl_type",
|
||||
price_list_id: "price.price_list_id",
|
||||
})
|
||||
.join(psmaSubQueryKnex.as("psma"), "psma.price_set_id", "ps.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_set_money_amount_id", "psma.id")
|
||||
.join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_id", "price.id")
|
||||
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
||||
.whereIn("ps.id", pricingFilters.id)
|
||||
.andWhere("psma.currency_code", "=", currencyCode)
|
||||
.andWhere("price.currency_code", "=", currencyCode)
|
||||
|
||||
.orderBy([
|
||||
{ column: "psma.has_price_list", order: "asc" },
|
||||
{ column: "price.has_price_list", order: "asc" },
|
||||
{ column: "amount", order: "asc" },
|
||||
{ column: "rules_count", order: "desc" },
|
||||
{ column: "default_priority", order: "desc" },
|
||||
])
|
||||
|
||||
if (quantity) {
|
||||
priceSetQueryKnex.where("psma.min_quantity", "<=", quantity)
|
||||
priceSetQueryKnex.andWhere("psma.max_quantity", ">=", quantity)
|
||||
priceSetQueryKnex.where("price.min_quantity", "<=", quantity)
|
||||
priceSetQueryKnex.andWhere("price.max_quantity", ">=", quantity)
|
||||
} else {
|
||||
priceSetQueryKnex.andWhere(function () {
|
||||
this.andWhere("psma.min_quantity", "<=", "1").orWhereNull(
|
||||
"psma.min_quantity"
|
||||
this.andWhere("price.min_quantity", "<=", "1").orWhereNull(
|
||||
"price.min_quantity"
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ export async function run({
|
||||
|
||||
logger.info(`Loading seed data from ${path}...`)
|
||||
|
||||
const { priceSetsData, priceSetMoneyAmountsData } = await import(
|
||||
const { priceSetsData, pricesData } = await import(
|
||||
resolve(process.cwd(), path)
|
||||
).catch((e) => {
|
||||
logger?.error(
|
||||
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and priceSetMoneyAmountsData.${EOL}${e}`
|
||||
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and pricesData.${EOL}${e}`
|
||||
)
|
||||
throw e
|
||||
})
|
||||
@@ -44,10 +44,10 @@ export async function run({
|
||||
const manager = orm.em.fork()
|
||||
|
||||
try {
|
||||
logger.info("Inserting price_set & price_set_money_amount")
|
||||
logger.info("Inserting price_sets & prices")
|
||||
|
||||
await createPriceSets(manager as any, priceSetsData)
|
||||
await createPriceSetMoneyAmounts(manager as any, priceSetMoneyAmountsData)
|
||||
await createPriceSets(manager, priceSetsData)
|
||||
await createPrices(manager, pricesData)
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${EOL}${e}`
|
||||
@@ -70,18 +70,15 @@ async function createPriceSets(
|
||||
return priceSets
|
||||
}
|
||||
|
||||
async function createPriceSetMoneyAmounts(
|
||||
async function createPrices(
|
||||
manager: SqlEntityManager<PostgreSqlDriver>,
|
||||
data: RequiredEntityData<PricingModels.PriceSetMoneyAmount>[]
|
||||
data: RequiredEntityData<PricingModels.Price>[]
|
||||
) {
|
||||
const priceSetMoneyAmounts = data.map((priceSetMoneyAmountData) => {
|
||||
return manager.create(
|
||||
PricingModels.PriceSetMoneyAmount,
|
||||
priceSetMoneyAmountData
|
||||
)
|
||||
const prices = data.map((priceData) => {
|
||||
return manager.create(PricingModels.Price, priceData)
|
||||
})
|
||||
|
||||
await manager.persistAndFlush(priceSetMoneyAmounts)
|
||||
await manager.persistAndFlush(prices)
|
||||
|
||||
return priceSetMoneyAmounts
|
||||
return prices
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
AddPricesDTO,
|
||||
Context,
|
||||
CreatePriceListRuleDTO,
|
||||
CreatePricesDTO,
|
||||
DAL,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
@@ -14,33 +15,33 @@ import {
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
deduplicate,
|
||||
generateEntityId,
|
||||
groupBy,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
PriceListType,
|
||||
arrayDifference,
|
||||
deduplicate,
|
||||
groupBy,
|
||||
removeNullish,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
Price,
|
||||
PriceList,
|
||||
PriceListRule,
|
||||
PriceListRuleValue,
|
||||
PriceRule,
|
||||
PriceSet,
|
||||
PriceSetMoneyAmount,
|
||||
PriceSetRuleType,
|
||||
RuleType,
|
||||
} from "@models"
|
||||
|
||||
import { PriceListService, RuleTypeService } from "@services"
|
||||
import { ServiceTypes } from "@types"
|
||||
import { validatePriceListDates } from "@utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import {PriceListService, RuleTypeService} from "@services"
|
||||
import {validatePriceListDates} from "@utils"
|
||||
import {entityNameToLinkableKeysMap, joinerConfig} from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -49,7 +50,7 @@ type InjectedDependencies = {
|
||||
ruleTypeService: RuleTypeService<any>
|
||||
priceRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceSetRuleTypeService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceSetMoneyAmountService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceListService: PriceListService<any>
|
||||
priceListRuleService: ModulesSdkTypes.InternalModuleService<any>
|
||||
priceListRuleValueService: ModulesSdkTypes.InternalModuleService<any>
|
||||
@@ -60,7 +61,7 @@ const generateMethodForModels = [
|
||||
PriceListRule,
|
||||
PriceListRuleValue,
|
||||
PriceRule,
|
||||
PriceSetMoneyAmount,
|
||||
Price,
|
||||
PriceSetRuleType,
|
||||
RuleType,
|
||||
]
|
||||
@@ -70,7 +71,7 @@ export default class PricingModuleService<
|
||||
TRuleType extends RuleType = RuleType,
|
||||
TPriceRule extends PriceRule = PriceRule,
|
||||
TPriceSetRuleType extends PriceSetRuleType = PriceSetRuleType,
|
||||
TPriceSetMoneyAmount extends PriceSetMoneyAmount = PriceSetMoneyAmount,
|
||||
TPrice extends Price = Price,
|
||||
TPriceList extends PriceList = PriceList,
|
||||
TPriceListRule extends PriceListRule = PriceListRule,
|
||||
TPriceListRuleValue extends PriceListRuleValue = PriceListRuleValue
|
||||
@@ -79,7 +80,7 @@ export default class PricingModuleService<
|
||||
InjectedDependencies,
|
||||
PricingTypes.PriceSetDTO,
|
||||
{
|
||||
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
|
||||
Price: { dto: PricingTypes.PriceDTO }
|
||||
PriceRule: {
|
||||
dto: PricingTypes.PriceRuleDTO
|
||||
create: PricingTypes.CreatePriceRuleDTO
|
||||
@@ -102,7 +103,7 @@ export default class PricingModuleService<
|
||||
protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService<TPriceSet>
|
||||
protected readonly priceRuleService_: ModulesSdkTypes.InternalModuleService<TPriceRule>
|
||||
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.InternalModuleService<TPriceSetRuleType>
|
||||
protected readonly priceSetMoneyAmountService_: ModulesSdkTypes.InternalModuleService<TPriceSetMoneyAmount>
|
||||
protected readonly priceService_: ModulesSdkTypes.InternalModuleService<TPrice>
|
||||
protected readonly priceListService_: PriceListService<TPriceList>
|
||||
protected readonly priceListRuleService_: ModulesSdkTypes.InternalModuleService<TPriceListRule>
|
||||
protected readonly priceListRuleValueService_: ModulesSdkTypes.InternalModuleService<TPriceListRuleValue>
|
||||
@@ -115,7 +116,7 @@ export default class PricingModuleService<
|
||||
priceSetService,
|
||||
priceRuleService,
|
||||
priceSetRuleTypeService,
|
||||
priceSetMoneyAmountService,
|
||||
priceService,
|
||||
priceListService,
|
||||
priceListRuleService,
|
||||
priceListRuleValueService,
|
||||
@@ -132,7 +133,7 @@ export default class PricingModuleService<
|
||||
this.ruleTypeService_ = ruleTypeService
|
||||
this.priceRuleService_ = priceRuleService
|
||||
this.priceSetRuleTypeService_ = priceSetRuleTypeService
|
||||
this.priceSetMoneyAmountService_ = priceSetMoneyAmountService
|
||||
this.priceService_ = priceService
|
||||
this.priceListService_ = priceListService
|
||||
this.priceListRuleService_ = priceListRuleService
|
||||
this.priceListRuleValueService_ = priceListRuleValueService
|
||||
@@ -228,20 +229,20 @@ export default class PricingModuleService<
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PriceSetDTO | PriceSetDTO[]> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const priceSets = await this.create_(input, sharedContext)
|
||||
|
||||
const dbPriceSets = await this.list(
|
||||
{ id: priceSets.filter((p) => !!p).map((p) => p!.id) },
|
||||
{
|
||||
relations: ["rule_types", "price_set_money_amounts", "price_rules"],
|
||||
},
|
||||
{ id: priceSets.map((p) => p.id) },
|
||||
{ relations: ["rule_types", "prices", "price_rules"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return (Array.isArray(data) ? dbPriceSets : dbPriceSets[0]) as unknown as
|
||||
| PriceSetDTO
|
||||
| PriceSetDTO[]
|
||||
// Ensure the output to be in the same order as the input
|
||||
const results = priceSets.map((priceSet) => {
|
||||
return dbPriceSets.find((p) => p.id === priceSet.id)!
|
||||
})
|
||||
|
||||
return Array.isArray(data) ? results : results[0]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@@ -249,14 +250,14 @@ export default class PricingModuleService<
|
||||
data: PricingTypes.CreatePriceSetDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const ruleAttributes = data
|
||||
.map((d) => d.rules?.map((r) => r.rule_attribute) ?? [])
|
||||
.flat()
|
||||
|
||||
const ruleTypes = await this.ruleTypeService_.list(
|
||||
{
|
||||
rule_attribute: ruleAttributes,
|
||||
},
|
||||
{ rule_attribute: ruleAttributes },
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
@@ -293,77 +294,82 @@ export default class PricingModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
const ruleSetRuleTypeToCreateMap: Map<string, TPriceSetRuleType> = new Map()
|
||||
|
||||
const toCreate = input.map((inputData) => {
|
||||
const id = generateEntityId(
|
||||
(inputData as unknown as TPriceSet).id,
|
||||
"pset"
|
||||
)
|
||||
|
||||
const { prices, rules = [], ...rest } = inputData
|
||||
|
||||
let pricesData: CreatePricesDTO[] = []
|
||||
|
||||
rules.forEach((rule) => {
|
||||
const priceSetRuleType = {
|
||||
rule_type_id: ruleTypeMap.get(rule.rule_attribute).id,
|
||||
price_set_id: id,
|
||||
} as TPriceSetRuleType
|
||||
|
||||
ruleSetRuleTypeToCreateMap.set(
|
||||
JSON.stringify(priceSetRuleType),
|
||||
priceSetRuleType
|
||||
)
|
||||
})
|
||||
|
||||
if (inputData.prices) {
|
||||
pricesData = inputData.prices.map((price) => {
|
||||
let { rules: priceRules = {}, ...rest } = price
|
||||
const cleanRules = priceRules ? removeNullish(priceRules) : {}
|
||||
const numberOfRules = Object.keys(cleanRules).length
|
||||
|
||||
const rulesDataMap = new Map()
|
||||
|
||||
Object.entries(priceRules).map(([attribute, value]) => {
|
||||
const rule = {
|
||||
price_set_id: id,
|
||||
rule_type_id: ruleTypeMap.get(attribute).id,
|
||||
value,
|
||||
}
|
||||
rulesDataMap.set(JSON.stringify(rule), rule)
|
||||
|
||||
const priceSetRuleType = {
|
||||
rule_type_id: ruleTypeMap.get(attribute).id,
|
||||
price_set_id: id,
|
||||
} as TPriceSetRuleType
|
||||
|
||||
ruleSetRuleTypeToCreateMap.set(
|
||||
JSON.stringify(priceSetRuleType),
|
||||
priceSetRuleType
|
||||
)
|
||||
})
|
||||
|
||||
return {
|
||||
...rest,
|
||||
title: "test", // TODO: accept title
|
||||
rules_count: numberOfRules,
|
||||
price_rules: Array.from(rulesDataMap.values()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
id,
|
||||
prices: pricesData,
|
||||
}
|
||||
})
|
||||
|
||||
// Bulk create price sets
|
||||
const priceSetData = data.map(({ rules, prices, ...rest }) => rest)
|
||||
const createdPriceSets = await this.priceSetService_.create(
|
||||
priceSetData,
|
||||
toCreate,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
// Price set rule types
|
||||
const ruleTypeData = data.flatMap(
|
||||
(item, index) =>
|
||||
item.rules?.map((rule) => ({
|
||||
rule_type: ruleTypeMap.get(rule.rule_attribute),
|
||||
price_set: createdPriceSets[index],
|
||||
})) || []
|
||||
)
|
||||
|
||||
if (ruleTypeData.length > 0) {
|
||||
if (ruleSetRuleTypeToCreateMap.size) {
|
||||
await this.priceSetRuleTypeService_.create(
|
||||
ruleTypeData as unknown as PricingTypes.CreatePriceSetRuleTypeDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
const priceSetMoneyAmountData: unknown[] = []
|
||||
const priceRulesData: unknown[] = []
|
||||
|
||||
for (const [index, item] of data.entries()) {
|
||||
for (const price of item.prices || []) {
|
||||
const cleanRules = price.rules ? removeNullish(price.rules) : {}
|
||||
const numberOfRules = Object.entries(cleanRules).length
|
||||
|
||||
const priceSetMoneyAmount = {
|
||||
...price,
|
||||
price_set_id: createdPriceSets[index].id,
|
||||
title: "test", // TODO: accept title
|
||||
rules_count: numberOfRules,
|
||||
}
|
||||
priceSetMoneyAmountData.push(priceSetMoneyAmount)
|
||||
|
||||
for (const [k, v] of Object.entries(cleanRules)) {
|
||||
priceRulesData.push({
|
||||
price_set_money_amount_id: null, // Updated later
|
||||
rule_type_id: ruleTypeMap.get(k).id,
|
||||
price_set_id: createdPriceSets[index].id,
|
||||
value: v,
|
||||
price_list_id: "test",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bulk create price set money amounts
|
||||
const createdPriceSetMoneyAmounts =
|
||||
await this.priceSetMoneyAmountService_.create(
|
||||
priceSetMoneyAmountData as PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
// Update price set money amount references
|
||||
for (let i = 0, j = 0; i < priceSetMoneyAmountData.length; i++) {
|
||||
const rulesCount = (priceSetMoneyAmountData[i] as any).rules_count
|
||||
for (let k = 0; k < rulesCount; k++, j++) {
|
||||
;(priceRulesData[j] as any).price_set_money_amount_id =
|
||||
createdPriceSetMoneyAmounts[i].id
|
||||
}
|
||||
}
|
||||
|
||||
// Price rules
|
||||
if (priceRulesData.length > 0) {
|
||||
await this.priceRuleService_.create(
|
||||
priceRulesData as ServiceTypes.CreatePriceRuleDTO[],
|
||||
Array.from(ruleSetRuleTypeToCreateMap.values()),
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -392,9 +398,7 @@ export default class PricingModuleService<
|
||||
|
||||
return await this.list(
|
||||
{ id: priceSets.map(({ id }) => id) },
|
||||
{
|
||||
relations: ["rule_types"],
|
||||
}
|
||||
{ relations: ["rule_types"] }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -417,7 +421,6 @@ export default class PricingModuleService<
|
||||
)
|
||||
|
||||
const priceSetMap = new Map(priceSets.map((p) => [p.id, p]))
|
||||
|
||||
const invalidPriceSetInputs = inputs.filter(
|
||||
(d) => !priceSetMap.has(d.priceSetId)
|
||||
)
|
||||
@@ -434,7 +437,7 @@ export default class PricingModuleService<
|
||||
const ruleTypes = await this.ruleTypeService_.list(
|
||||
{
|
||||
rule_attribute: inputs
|
||||
.map((d) => d.rules.map((r) => r.attribute))
|
||||
.map((data) => data.rules.map((r) => r.attribute))
|
||||
.flat(),
|
||||
},
|
||||
{ take: null },
|
||||
@@ -461,23 +464,21 @@ export default class PricingModuleService<
|
||||
|
||||
const priceSetRuleTypesCreate: PricingTypes.CreatePriceSetRuleTypeDTO[] = []
|
||||
|
||||
inputs.forEach((d) => {
|
||||
const priceSet = priceSetMap.get(d.priceSetId)
|
||||
|
||||
for (const r of d.rules) {
|
||||
if (priceSetRuleTypeMap.get(d.priceSetId)!.has(r.attribute)) {
|
||||
inputs.forEach((data) => {
|
||||
for (const rule of data.rules) {
|
||||
if (priceSetRuleTypeMap.get(data.priceSetId)!.has(rule.attribute)) {
|
||||
continue
|
||||
}
|
||||
|
||||
priceSetRuleTypesCreate.push({
|
||||
rule_type: ruleTypeMap.get(r.attribute) as RuleTypeDTO,
|
||||
price_set: priceSet as unknown as PriceSetDTO,
|
||||
rule_type_id: ruleTypeMap.get(rule.attribute)!.id,
|
||||
price_set_id: priceSetMap.get(data.priceSetId)!.id,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
await this.priceSetRuleTypeService_.create(
|
||||
priceSetRuleTypesCreate as unknown as PricingTypes.CreatePriceSetRuleTypeDTO[],
|
||||
priceSetRuleTypesCreate,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -503,11 +504,11 @@ export default class PricingModuleService<
|
||||
|
||||
await this.addPrices_(input, sharedContext)
|
||||
|
||||
return (await this.list(
|
||||
return await this.list(
|
||||
{ id: input.map((d) => d.priceSetId) },
|
||||
{ relations: ["price_set_money_amounts"] },
|
||||
{ relations: ["prices"] },
|
||||
sharedContext
|
||||
)) as unknown as PricingTypes.PriceSetDTO[] | PricingTypes.PriceSetDTO
|
||||
)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@@ -558,7 +559,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
})
|
||||
|
||||
const priceSetMoneyAmountsBulkData: unknown[] = input.flatMap(
|
||||
const pricesToCreate: PricingTypes.CreatePriceDTO[] = input.flatMap(
|
||||
({ priceSetId, prices }) =>
|
||||
prices.map((price) => {
|
||||
const numberOfRules = Object.entries(price?.rules ?? {}).length
|
||||
@@ -572,21 +573,21 @@ export default class PricingModuleService<
|
||||
})
|
||||
)
|
||||
|
||||
const createdPriceSetMoneyAmounts =
|
||||
await this.priceSetMoneyAmountService_.create(
|
||||
priceSetMoneyAmountsBulkData as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
const createdPrices = await this.priceService_.create(
|
||||
pricesToCreate,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
// Price rules
|
||||
let rulesCursor = 0
|
||||
const priceRulesBulkData = input.flatMap(({ priceSetId, prices }) =>
|
||||
prices.flatMap((ma) => {
|
||||
const rules = ma.rules ?? {}
|
||||
const priceSetMoneyAmount = createdPriceSetMoneyAmounts[rulesCursor]
|
||||
const price = createdPrices[rulesCursor]
|
||||
rulesCursor++
|
||||
|
||||
return Object.entries(rules).map(([k, v]) => ({
|
||||
price_set_money_amount_id: priceSetMoneyAmount.id,
|
||||
price_id: price.id,
|
||||
rule_type_id: ruleTypeMap.get(priceSetId)!.get(k)!.id,
|
||||
price_set_id: priceSetId,
|
||||
value: v,
|
||||
@@ -605,14 +606,12 @@ export default class PricingModuleService<
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
const priceSets = await this.priceSetService_.list(
|
||||
{
|
||||
id: data.map((d) => d.id),
|
||||
},
|
||||
{ id: data.map((d) => d.id) },
|
||||
{},
|
||||
sharedContext
|
||||
)
|
||||
const priceSetIds = priceSets.map((ps) => ps.id)
|
||||
|
||||
const priceSetIds = priceSets.map((ps) => ps.id)
|
||||
const ruleTypes = await this.ruleTypeService_.list(
|
||||
{
|
||||
rule_attribute: data.map((d) => d.rules || []).flat(),
|
||||
@@ -620,26 +619,17 @@ export default class PricingModuleService<
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
const ruleTypeIds = ruleTypes.map((rt) => rt.id)
|
||||
|
||||
const ruleTypeIds = ruleTypes.map((rt) => rt.id)
|
||||
const priceSetRuleTypes = await this.priceSetRuleTypeService_.list(
|
||||
{
|
||||
price_set_id: priceSetIds,
|
||||
rule_type_id: ruleTypeIds,
|
||||
},
|
||||
{ price_set_id: priceSetIds, rule_type_id: ruleTypeIds },
|
||||
{ take: null },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const priceRules = await this.priceRuleService_.list(
|
||||
{
|
||||
price_set_id: priceSetIds,
|
||||
rule_type_id: ruleTypeIds,
|
||||
},
|
||||
{
|
||||
select: ["price_set_money_amount"],
|
||||
take: null,
|
||||
},
|
||||
{ price_set_id: priceSetIds, rule_type_id: ruleTypeIds },
|
||||
{ select: ["price"], take: null },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -648,8 +638,8 @@ export default class PricingModuleService<
|
||||
sharedContext
|
||||
)
|
||||
|
||||
await this.priceSetMoneyAmountService_.delete(
|
||||
priceRules.map((pr) => pr.price_set_money_amount.id),
|
||||
await this.priceService_.delete(
|
||||
priceRules.map((pr) => pr.price.id),
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -663,9 +653,7 @@ export default class PricingModuleService<
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.PriceSetDTO[]>(
|
||||
priceSets,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
{ populate: true }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -678,9 +666,7 @@ export default class PricingModuleService<
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
priceLists,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
{ populate: true }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -759,7 +745,7 @@ export default class PricingModuleService<
|
||||
)
|
||||
|
||||
// Create the values for the rule
|
||||
for (const ruleValue of ruleValues as string[]) {
|
||||
for (const ruleValue of ruleValues) {
|
||||
await this.priceListRuleValueService_.create(
|
||||
[{ price_list_rule_id: priceListRule.id, value: ruleValue }],
|
||||
sharedContext
|
||||
@@ -767,26 +753,23 @@ export default class PricingModuleService<
|
||||
}
|
||||
}
|
||||
|
||||
for (const price of prices) {
|
||||
for (const priceData of prices) {
|
||||
const {
|
||||
price_set_id: priceSetId,
|
||||
rules: priceRules = {},
|
||||
...psmaData
|
||||
} = price
|
||||
...rest
|
||||
} = priceData
|
||||
|
||||
const [priceSetMoneyAmount] =
|
||||
await this.priceSetMoneyAmountService_.create(
|
||||
[
|
||||
{
|
||||
price_set_id: priceSetId,
|
||||
price_list_id: priceList.id,
|
||||
title: "test",
|
||||
rules_count: Object.keys(priceRules).length,
|
||||
...psmaData,
|
||||
},
|
||||
],
|
||||
sharedContext
|
||||
)
|
||||
const createdPrice = await this.priceService_.create(
|
||||
{
|
||||
price_set_id: priceSetId,
|
||||
price_list_id: priceList.id,
|
||||
title: "test",
|
||||
rules_count: Object.keys(priceRules).length,
|
||||
...rest,
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
await this.priceRuleService_.create(
|
||||
Object.entries(priceRules).map(([ruleAttribute, ruleValue]) => {
|
||||
@@ -794,7 +777,7 @@ export default class PricingModuleService<
|
||||
price_set_id: priceSetId,
|
||||
rule_type_id: ruleTypeMap.get(ruleAttribute)!?.id,
|
||||
value: ruleValue,
|
||||
price_set_money_amount_id: priceSetMoneyAmount.id,
|
||||
price_id: createdPrice.id,
|
||||
}
|
||||
}),
|
||||
sharedContext
|
||||
@@ -814,9 +797,7 @@ export default class PricingModuleService<
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
priceLists,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
{ populate: true }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -913,7 +894,7 @@ export default class PricingModuleService<
|
||||
sharedContext
|
||||
)
|
||||
|
||||
for (const ruleValue of ruleValues as string[]) {
|
||||
for (const ruleValue of ruleValues) {
|
||||
await this.priceListRuleValueService_.create(
|
||||
[{ price_list_rule_id: priceListRule.id, value: ruleValue }],
|
||||
sharedContext
|
||||
@@ -979,7 +960,7 @@ export default class PricingModuleService<
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const ruleTypeAttributes: string[] = []
|
||||
const priceListIds: string[] = []
|
||||
const psmaIds: string[] = []
|
||||
const priceIds: string[] = []
|
||||
const priceSetIds = data
|
||||
.map((d) => d.prices.map((price) => price.price_set_id))
|
||||
.flat()
|
||||
@@ -988,22 +969,19 @@ export default class PricingModuleService<
|
||||
priceListIds.push(priceListData.price_list_id)
|
||||
|
||||
for (const price of priceListData.prices) {
|
||||
psmaIds.push(price.id)
|
||||
priceIds.push(price.id)
|
||||
ruleTypeAttributes.push(...Object.keys(price.rules || {}))
|
||||
}
|
||||
}
|
||||
|
||||
const psmas = await this.listPriceSetMoneyAmounts(
|
||||
{ id: psmaIds },
|
||||
{
|
||||
take: null,
|
||||
relations: ["price_rules"],
|
||||
},
|
||||
const prices = await this.listPrices(
|
||||
{ id: priceIds },
|
||||
{ take: null, relations: ["price_rules"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const psmaMap: Map<string, PricingTypes.PriceSetMoneyAmountDTO> = new Map(
|
||||
psmas.map((psma) => [psma.id, psma])
|
||||
const priceMap: Map<string, PricingTypes.PriceDTO> = new Map(
|
||||
prices.map((price) => [price.id, price])
|
||||
)
|
||||
|
||||
const ruleTypes = await this.listRuleTypes(
|
||||
@@ -1032,6 +1010,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
acc.set(curr.id, priceSetRuleAttributeSet)
|
||||
|
||||
return acc
|
||||
},
|
||||
new Map()
|
||||
@@ -1080,40 +1059,41 @@ export default class PricingModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
const moneyAmountsToUpdate: PricingTypes.UpdateMoneyAmountDTO[] = []
|
||||
const priceRulesToDelete: string[] = []
|
||||
const priceRuleIdsToDelete: string[] = []
|
||||
const priceRulesToCreate: PricingTypes.CreatePriceRuleDTO[] = []
|
||||
const psmaToUpdate: ServiceTypes.UpdatePriceSetMoneyAmountDTO[] = []
|
||||
const pricesToUpdate: (PricingTypes.UpdatePriceDTO & {
|
||||
rules_count: number
|
||||
})[] = []
|
||||
|
||||
for (const price of prices) {
|
||||
const { rules, price_set_id, ...priceData } = price
|
||||
const priceSetMoneyAmount = psmaMap.get(price.id)!
|
||||
const priceRules = priceSetMoneyAmount.price_rules!
|
||||
for (const priceData of prices) {
|
||||
const { rules, price_set_id, ...rest } = priceData
|
||||
const price = priceMap.get(rest.id)!
|
||||
const priceRules = price.price_rules!
|
||||
|
||||
if (typeof rules === "undefined") {
|
||||
continue
|
||||
}
|
||||
|
||||
psmaToUpdate.push({
|
||||
...priceData,
|
||||
pricesToUpdate.push({
|
||||
...rest,
|
||||
rules_count: Object.keys(rules).length,
|
||||
})
|
||||
|
||||
priceRulesToDelete.push(...priceRules.map((pr) => pr.id))
|
||||
priceRuleIdsToDelete.push(...priceRules.map((pr) => pr.id))
|
||||
priceRulesToCreate.push(
|
||||
...Object.entries(rules).map(([ruleAttribute, ruleValue]) => ({
|
||||
price_set_id: price.price_set_id,
|
||||
price_set_id,
|
||||
rule_type_id: ruleTypeMap.get(ruleAttribute)!.id,
|
||||
value: ruleValue,
|
||||
price_set_money_amount_id: priceSetMoneyAmount.id,
|
||||
price_id: price.id,
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.priceRuleService_.delete(priceRulesToDelete),
|
||||
this.priceRuleService_.delete(priceRuleIdsToDelete),
|
||||
this.priceRuleService_.create(priceRulesToCreate),
|
||||
this.priceSetMoneyAmountService_.update(psmaToUpdate),
|
||||
this.priceService_.update(pricesToUpdate),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -1133,7 +1113,7 @@ export default class PricingModuleService<
|
||||
ids: string[],
|
||||
sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetMoneyAmountService_.delete(ids, sharedContext)
|
||||
await this.priceService_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
@@ -1237,15 +1217,15 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
prices.map(async (price) => {
|
||||
const priceRules = price.rules || {}
|
||||
prices.map(async (priceData) => {
|
||||
const priceRules = priceData.rules || {}
|
||||
const noOfRules = Object.keys(priceRules).length
|
||||
|
||||
const [psma] = await this.priceSetMoneyAmountService_.create(
|
||||
const [price] = await this.priceService_.create(
|
||||
[
|
||||
{
|
||||
...price,
|
||||
price_set_id: price.price_set_id,
|
||||
...priceData,
|
||||
price_set_id: priceData.price_set_id,
|
||||
title: "test",
|
||||
price_list_id: priceList.id,
|
||||
rules_count: noOfRules,
|
||||
@@ -1257,16 +1237,16 @@ export default class PricingModuleService<
|
||||
await this.priceRuleService_.create(
|
||||
Object.entries(priceRules).map(([ruleAttribute, ruleValue]) => {
|
||||
return {
|
||||
price_set_id: price.price_set_id,
|
||||
price_set_id: priceData.price_set_id,
|
||||
rule_type_id: ruleTypeMap.get(ruleAttribute)!?.id,
|
||||
value: ruleValue,
|
||||
price_set_money_amount_id: psma.id,
|
||||
price_id: price.id,
|
||||
}
|
||||
}),
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return psma
|
||||
return price
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -1291,27 +1271,19 @@ export default class PricingModuleService<
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const priceLists = await this.priceListService_.list(
|
||||
{ id: data.map((d) => d.price_list_id) },
|
||||
{
|
||||
relations: ["price_list_rules", "price_list_rules.rule_type"],
|
||||
},
|
||||
{ relations: ["price_list_rules", "price_list_rules.rule_type"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const priceListMap = new Map(priceLists.map((p) => [p.id, p]))
|
||||
const ruleTypes = await this.listRuleTypes(
|
||||
{
|
||||
rule_attribute: data.map((d) => Object.keys(d.rules)).flat(),
|
||||
},
|
||||
{
|
||||
take: null,
|
||||
}
|
||||
{ rule_attribute: data.map((d) => Object.keys(d.rules)).flat() },
|
||||
{ take: null }
|
||||
)
|
||||
|
||||
const ruleTypeMap = new Map(ruleTypes.map((rt) => [rt.rule_attribute, rt]))
|
||||
|
||||
const ruleIdsToUpdate: string[] = []
|
||||
const rulesToCreate: CreatePriceListRuleDTO[] = []
|
||||
|
||||
const priceRuleValues = new Map<string, Map<string, string[]>>()
|
||||
|
||||
for (const { price_list_id: priceListId, rules } of data) {
|
||||
@@ -1325,9 +1297,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
const priceListRulesMap: Map<string, PriceListRule> = new Map(
|
||||
priceList.price_list_rules
|
||||
.getItems()
|
||||
.map((p) => [p.rule_type.rule_attribute, p])
|
||||
priceList.price_list_rules.map((p) => [p.rule_type.rule_attribute, p])
|
||||
)
|
||||
|
||||
const priceListRuleValues = new Map<string, string[]>()
|
||||
@@ -1365,9 +1335,7 @@ export default class PricingModuleService<
|
||||
const [createdRules, priceListValuesToDelete] = await Promise.all([
|
||||
this.priceListRuleService_.create(rulesToCreate),
|
||||
this.priceListRuleValueService_.list(
|
||||
{
|
||||
price_list_rule_id: ruleIdsToUpdate,
|
||||
},
|
||||
{ price_list_rule_id: ruleIdsToUpdate },
|
||||
{ take: null }
|
||||
),
|
||||
])
|
||||
@@ -1382,6 +1350,7 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
const values = ruleValues.get(rule_type_id)
|
||||
|
||||
if (!values) {
|
||||
continue
|
||||
}
|
||||
@@ -1400,16 +1369,14 @@ export default class PricingModuleService<
|
||||
sharedContext
|
||||
),
|
||||
this.priceListRuleValueService_.create(
|
||||
priceListRuleValuesToCreate as ServiceTypes.CreatePriceListRuleValueDTO[],
|
||||
priceListRuleValuesToCreate,
|
||||
sharedContext
|
||||
),
|
||||
])
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
priceLists,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
{ populate: true }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1430,15 +1397,13 @@ export default class PricingModuleService<
|
||||
): Promise<PricingTypes.PriceListDTO[]> {
|
||||
const priceLists = await this.priceListService_.list(
|
||||
{ id: data.map((d) => d.price_list_id) },
|
||||
{
|
||||
relations: ["price_list_rules", "price_list_rules.rule_type"],
|
||||
},
|
||||
{ relations: ["price_list_rules", "price_list_rules.rule_type"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const priceListMap = new Map(priceLists.map((p) => [p.id, p]))
|
||||
|
||||
const idsToDelete: string[] = []
|
||||
|
||||
for (const { price_list_id: priceListId, rules } of data) {
|
||||
const priceList = priceListMap.get(priceListId)
|
||||
|
||||
@@ -1450,14 +1415,13 @@ export default class PricingModuleService<
|
||||
}
|
||||
|
||||
const priceListRulesMap: Map<string, PriceListRule> = new Map(
|
||||
priceList.price_list_rules
|
||||
.getItems()
|
||||
.map((p) => [p.rule_type.rule_attribute, p])
|
||||
priceList.price_list_rules.map((p) => [p.rule_type.rule_attribute, p])
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
rules.map(async (rule_attribute) => {
|
||||
const rule = priceListRulesMap.get(rule_attribute)
|
||||
|
||||
if (rule) {
|
||||
idsToDelete.push(rule.id)
|
||||
}
|
||||
@@ -1469,9 +1433,7 @@ export default class PricingModuleService<
|
||||
|
||||
return await this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
priceLists,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
{ populate: true }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { Context, DAL, PricingTypes } from "@medusajs/types"
|
||||
import {
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
validateRuleAttributes,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
@@ -26,17 +25,17 @@ export default class RuleTypeService<
|
||||
}
|
||||
|
||||
create(
|
||||
data: ServiceTypes.CreateRuleTypeDTO,
|
||||
data: PricingTypes.CreateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
create(
|
||||
data: ServiceTypes.CreateRuleTypeDTO[],
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreateRuleTypeDTO | ServiceTypes.CreateRuleTypeDTO[],
|
||||
data: PricingTypes.CreateRuleTypeDTO | PricingTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
@@ -46,12 +45,12 @@ export default class RuleTypeService<
|
||||
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: ServiceTypes.UpdateRuleTypeDTO[],
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: ServiceTypes.UpdateRuleTypeDTO,
|
||||
data: PricingTypes.UpdateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
|
||||
@@ -59,7 +58,7 @@ export default class RuleTypeService<
|
||||
// TODO: add support for selector? and then rm ts ignore
|
||||
// @ts-ignore
|
||||
async update(
|
||||
data: ServiceTypes.UpdateRuleTypeDTO | ServiceTypes.UpdateRuleTypeDTO[],
|
||||
data: PricingTypes.UpdateRuleTypeDTO | PricingTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
|
||||
@@ -4,5 +4,4 @@ export type InitializeModuleInjectableDependencies = {
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export * as RepositoryTypes from "./repositories"
|
||||
export * as ServiceTypes from "./services"
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export * from "./price-list"
|
||||
export * from "./price-list-rule"
|
||||
export * from "./price-list-rule-value"
|
||||
export * from "./price-rule"
|
||||
export * from "./price-set"
|
||||
export * from "./price-set-money-amount"
|
||||
export * from "./price-set-rule-type"
|
||||
export * from "./rule-type"
|
||||
@@ -1,12 +0,0 @@
|
||||
import { PriceListRule } from "@models"
|
||||
|
||||
export interface CreatePriceListRuleValueDTO {
|
||||
price_list_rule_id?: string
|
||||
price_list_rule: PriceListRule | string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { PriceListDTO, RuleTypeDTO } from "../services"
|
||||
|
||||
export interface CreatePriceListRuleDTO {
|
||||
rule_type_id?: string
|
||||
rule_type?: string | RuleTypeDTO
|
||||
price_list_id?: string
|
||||
price_list?: string | PriceListDTO
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleDTO {
|
||||
id: string
|
||||
price_list_id?: string
|
||||
rule_type_id?: string
|
||||
price_list?: string
|
||||
rule_type?: string
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models"
|
||||
|
||||
export interface CreatePriceRuleDTO {
|
||||
id?: string
|
||||
price_set_id?: string
|
||||
price_set?: PriceSet | string
|
||||
rule_type_id?: string
|
||||
rule_type?: RuleType | string
|
||||
value: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_set_money_amount?: PriceSetMoneyAmount | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceRuleDTO {
|
||||
id: string
|
||||
price_set_id?: string
|
||||
rule_type_id?: string
|
||||
value?: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_list_id?: string
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { MoneyAmountDTO, PriceListDTO, PriceSetDTO } from "../services"
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
money_amount?: MoneyAmountDTO
|
||||
}
|
||||
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO | string
|
||||
price_list?: PriceListDTO | string
|
||||
money_amount?: MoneyAmountDTO | string
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { PriceSetDTO, RuleTypeDTO } from "../services"
|
||||
|
||||
export interface CreatePriceSetRuleTypeDTO {
|
||||
price_set: PriceSetDTO | string
|
||||
rule_type: RuleTypeDTO | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set?: string
|
||||
rule_type?: string
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export interface CreatePriceSetDTO {}
|
||||
|
||||
export interface UpdatePriceSetDTO {
|
||||
id: string
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
export interface CreateRuleTypeDTO {
|
||||
id?: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface UpdateRuleTypeDTO {
|
||||
id: string
|
||||
name?: string
|
||||
rule_attribute?: string
|
||||
default_priority?: number
|
||||
}
|
||||
@@ -1,10 +1 @@
|
||||
export * from "./money-amount"
|
||||
export * from "./price-list"
|
||||
export * from "./price-list-rule"
|
||||
export * from "./price-list-rule-value"
|
||||
export * from "./price-rule"
|
||||
export * from "./price-set"
|
||||
export * from "./price-set-money-amount"
|
||||
export * from "./price-set-rule-type"
|
||||
export * from "./pricing"
|
||||
export * from "./rule-type"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { BaseFilterable, PriceSetMoneyAmountDTO } from "@medusajs/types"
|
||||
|
||||
export interface CreateMoneyAmountDTO {
|
||||
id?: string
|
||||
currency_code: string
|
||||
amount: number
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
}
|
||||
|
||||
export interface UpdateMoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
}
|
||||
|
||||
export interface MoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string | null
|
||||
amount?: number | null
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
price_set_money_amount?: PriceSetMoneyAmountDTO
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
export interface FilterableMoneyAmountProps
|
||||
extends BaseFilterable<FilterableMoneyAmountProps> {
|
||||
id?: string[]
|
||||
currency_code?: string | string[]
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { BaseFilterable } from "@medusajs/types"
|
||||
import { PriceListRule } from "@models"
|
||||
|
||||
export interface CreatePriceListRuleValueDTO {
|
||||
price_list_rule_id?: string
|
||||
price_list_rule: PriceListRule | string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface PriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
price_list_rule: PriceListRule
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleValueProps
|
||||
extends BaseFilterable<FilterablePriceListRuleValueProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
price_list_rule_id?: string[]
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
PriceListDTO,
|
||||
PriceListRuleValueDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceListRuleDTO {
|
||||
rule_type_id?: string
|
||||
rule_type?: string | RuleTypeDTO
|
||||
price_list_id?: string
|
||||
price_list?: string | PriceListDTO
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleDTO {
|
||||
id: string
|
||||
price_list_id?: string
|
||||
rule_type_id?: string
|
||||
price_list?: string
|
||||
rule_type?: string
|
||||
}
|
||||
|
||||
export interface PriceListRuleDTO {
|
||||
id: string
|
||||
value: string
|
||||
rule_type: RuleTypeDTO
|
||||
price_list: PriceListDTO
|
||||
price_list_rule_values?: PriceListRuleValueDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleProps
|
||||
extends BaseFilterable<FilterablePriceListRuleProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
rule_type?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
@@ -1,10 +1,3 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
MoneyAmountDTO,
|
||||
PriceListRuleDTO,
|
||||
PriceSetMoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
@@ -25,26 +18,3 @@ export interface UpdatePriceListDTO {
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
export interface PriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string | null
|
||||
status?: PriceListStatus
|
||||
ends_at?: string | null
|
||||
number_rules?: number
|
||||
price_set_money_amounts?: PriceSetMoneyAmountDTO[]
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
rule_types?: RuleTypeDTO[]
|
||||
rules?: PriceListRuleDTO[]
|
||||
price_list_rules?: PriceListRuleDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListProps
|
||||
extends BaseFilterable<FilterablePriceListProps> {
|
||||
id?: string[]
|
||||
starts_at?: string[]
|
||||
ends_at?: string[]
|
||||
status?: PriceListStatus[]
|
||||
number_rules?: number[]
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import { BaseFilterable, PriceSetDTO, RuleTypeDTO } from "@medusajs/types"
|
||||
import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models"
|
||||
|
||||
export interface CreatePriceRuleDTO {
|
||||
id?: string
|
||||
price_set_id?: string
|
||||
price_set?: PriceSet | string
|
||||
rule_type_id?: string
|
||||
rule_type?: RuleType | string
|
||||
value: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_set_money_amount?: PriceSetMoneyAmount | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceRuleDTO {
|
||||
id: string
|
||||
price_set_id?: string
|
||||
rule_type_id?: string
|
||||
value?: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_list_id?: string
|
||||
}
|
||||
|
||||
export interface PriceRuleDTO {
|
||||
id: string
|
||||
price_set_id: string
|
||||
price_set: PriceSetDTO
|
||||
rule_type_id: string
|
||||
rule_type: RuleTypeDTO
|
||||
value: string
|
||||
priority: number
|
||||
price_set_money_amount_id: string
|
||||
price_list_id: string
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
export interface FilterablePriceRuleProps
|
||||
extends BaseFilterable<FilterablePriceRuleProps> {
|
||||
id?: string[]
|
||||
name?: string[]
|
||||
price_set_id?: string[]
|
||||
rule_type_id?: string[]
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
MoneyAmountDTO,
|
||||
PriceListDTO,
|
||||
PriceRuleDTO,
|
||||
PriceSetDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
money_amount?: MoneyAmountDTO
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO | string
|
||||
price_list?: PriceListDTO | string
|
||||
money_amount?: MoneyAmountDTO | string
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetMoneyAmountProps
|
||||
extends BaseFilterable<FilterablePriceSetMoneyAmountProps> {
|
||||
id?: string[]
|
||||
price_set_id?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
|
||||
export interface PriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
price_list?: PriceListDTO
|
||||
price_set_id?: string
|
||||
price_rules?: PriceRuleDTO[]
|
||||
money_amount?: MoneyAmountDTO
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { BaseFilterable, PriceSetDTO, RuleTypeDTO } from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceSetRuleTypeDTO {
|
||||
price_set: PriceSetDTO | string
|
||||
rule_type: RuleTypeDTO | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set?: string
|
||||
rule_type?: string
|
||||
}
|
||||
|
||||
export interface PriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set: PriceSetDTO
|
||||
rule_type: RuleTypeDTO
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetRuleTypeProps
|
||||
extends BaseFilterable<FilterablePriceSetRuleTypeProps> {
|
||||
id?: string[]
|
||||
rule_type_id?: string[]
|
||||
price_set_id?: string[]
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
FilterableMoneyAmountProps,
|
||||
MoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceSetDTO {}
|
||||
|
||||
export interface UpdatePriceSetDTO {
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface PriceSetDTO {
|
||||
id: string
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
rule_types?: RuleTypeDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetProps
|
||||
extends BaseFilterable<FilterablePriceSetProps> {
|
||||
id?: string[]
|
||||
money_amounts?: FilterableMoneyAmountProps
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { Context } from "@medusajs/types"
|
||||
|
||||
export interface PricingRepositoryService {
|
||||
calculatePrices(
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext,
|
||||
context: Context
|
||||
): Promise<CalculatedPriceSetDTO[]>
|
||||
}
|
||||
|
||||
export interface PricingFilters {
|
||||
id: string[]
|
||||
}
|
||||
|
||||
export interface PricingContext {
|
||||
context?: Record<string, string | number>
|
||||
}
|
||||
|
||||
export interface CalculatedPriceSetDTO {
|
||||
id: string
|
||||
price_set_id: string
|
||||
amount: string | null
|
||||
currency_code: string | null
|
||||
min_quantity: string | null
|
||||
max_quantity: string | null
|
||||
price_list_type: string | null
|
||||
price_list_id: string | null
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { BaseFilterable } from "@medusajs/types"
|
||||
|
||||
export interface CreateRuleTypeDTO {
|
||||
id?: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface UpdateRuleTypeDTO {
|
||||
id: string
|
||||
name?: string
|
||||
rule_attribute?: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface RuleTypeDTO {
|
||||
id: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority: number
|
||||
/**
|
||||
* The creation date of the rule type.
|
||||
*/
|
||||
created_at?: Date | string
|
||||
|
||||
/**
|
||||
* The update date of the rule type.
|
||||
*/
|
||||
updated_at?: Date | string
|
||||
}
|
||||
|
||||
export interface FilterableRuleTypeProps
|
||||
extends BaseFilterable<FilterableRuleTypeProps> {
|
||||
id?: string[]
|
||||
name?: string[]
|
||||
rule_attribute?: string[]
|
||||
}
|
||||
Reference in New Issue
Block a user