refactor: migrate cart module to DML (#10385)

FIXES: FRMW-2815

This PR has no breaking changes
This commit is contained in:
Harminder Virk
2024-12-05 18:00:50 +05:30
committed by GitHub
parent 7013c37fda
commit 0a16efa426
16 changed files with 808 additions and 1275 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/cart": patch
"@medusajs/utils": patch
---
refactor: migrate cart module to DML

View File

@@ -4,3 +4,4 @@ export * from "./has-many"
export * from "./has-one"
export * from "./many-to-many"
export * from "./nullable"
export * from "./has-one-fk"

View File

@@ -1,18 +1,19 @@
import { CreateCartDTO } from "@medusajs/framework/types"
import { CreateCartDTO, InferEntityType } from "@medusajs/framework/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { Cart } from "../../../src/models"
import { defaultCartsData } from "./data"
import { toMikroORMEntity } from "@medusajs/framework/utils"
export * from "./data"
export async function createCarts(
manager: SqlEntityManager,
cartsData: CreateCartDTO[] = defaultCartsData
): Promise<Cart[]> {
const carts: Cart[] = []
): Promise<InferEntityType<typeof Cart>[]> {
const carts: InferEntityType<typeof Cart>[] = []
for (let cartData of cartsData) {
let cart = manager.create(Cart, cartData)
let cart = manager.create(toMikroORMEntity(Cart), cartData)
await manager.persistAndFlush(cart)
}

View File

@@ -161,13 +161,11 @@
"indexes": [
{
"keyName": "IDX_cart_address_deleted_at",
"columnNames": [
"deleted_at"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_address_deleted_at\" ON \"cart_address\" (deleted_at) WHERE deleted_at IS NOT NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_address_deleted_at\" ON \"cart_address\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "cart_address_pkey",
@@ -238,24 +236,6 @@
"nullable": false,
"mappedType": "text"
},
"shipping_address_id": {
"name": "shipping_address_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"billing_address_id": {
"name": "billing_address_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
@@ -275,6 +255,24 @@
"length": 6,
"mappedType": "datetime"
},
"shipping_address_id": {
"name": "shipping_address_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"billing_address_id": {
"name": "billing_address_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -312,20 +310,42 @@
"schema": "public",
"indexes": [
{
"keyName": "IDX_cart_region_id",
"columnNames": [
"region_id"
"shipping_address_id"
],
"composite": false,
"keyName": "cart_shipping_address_id_unique",
"primary": false,
"unique": true
},
{
"columnNames": [
"billing_address_id"
],
"composite": false,
"keyName": "cart_billing_address_id_unique",
"primary": false,
"unique": true
},
{
"keyName": "IDX_cart_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_deleted_at\" ON \"cart\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_region_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_region_id\" ON \"cart\" (region_id) WHERE deleted_at IS NULL AND region_id IS NOT NULL"
},
{
"keyName": "IDX_cart_customer_id",
"columnNames": [
"customer_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -333,9 +353,7 @@
},
{
"keyName": "IDX_cart_sales_channel_id",
"columnNames": [
"sales_channel_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -343,9 +361,7 @@
},
{
"keyName": "IDX_cart_curency_code",
"columnNames": [
"currency_code"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -353,9 +369,7 @@
},
{
"keyName": "IDX_cart_shipping_address_id",
"columnNames": [
"shipping_address_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -363,24 +377,12 @@
},
{
"keyName": "IDX_cart_billing_address_id",
"columnNames": [
"billing_address_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_billing_address_id\" ON \"cart\" (billing_address_id) WHERE deleted_at IS NULL AND billing_address_id IS NOT NULL"
},
{
"keyName": "IDX_cart_deleted_at",
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_deleted_at\" ON \"cart\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "cart_pkey",
"columnNames": [
@@ -432,15 +434,6 @@
"nullable": false,
"mappedType": "text"
},
"cart_id": {
"name": "cart_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"title": {
"name": "title",
"type": "text",
@@ -601,6 +594,7 @@
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "true",
"mappedType": "boolean"
},
"is_discountable": {
@@ -610,6 +604,7 @@
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "true",
"mappedType": "boolean"
},
"is_tax_inclusive": {
@@ -619,6 +614,7 @@
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "false",
"mappedType": "boolean"
},
"compare_at_unit_price": {
@@ -630,15 +626,6 @@
"nullable": true,
"mappedType": "decimal"
},
"raw_compare_at_unit_price": {
"name": "raw_compare_at_unit_price",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "json"
},
"unit_price": {
"name": "unit_price",
"type": "numeric",
@@ -648,15 +635,6 @@
"nullable": false,
"mappedType": "decimal"
},
"raw_unit_price": {
"name": "raw_unit_price",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
@@ -666,6 +644,33 @@
"nullable": true,
"mappedType": "json"
},
"cart_id": {
"name": "cart_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"raw_compare_at_unit_price": {
"name": "raw_compare_at_unit_price",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "json"
},
"raw_unit_price": {
"name": "raw_unit_price",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -702,11 +707,25 @@
"name": "cart_line_item",
"schema": "public",
"indexes": [
{
"keyName": "IDX_cart_line_item_cart_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_cart_id\" ON \"cart_line_item\" (cart_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_line_item_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_deleted_at\" ON \"cart_line_item\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_line_item_cart_id",
"columnNames": [
"cart_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -714,9 +733,7 @@
},
{
"keyName": "IDX_line_item_variant_id",
"columnNames": [
"variant_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -724,9 +741,7 @@
},
{
"keyName": "IDX_line_item_product_id",
"columnNames": [
"product_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -734,24 +749,12 @@
},
{
"keyName": "IDX_line_item_product_type_id",
"columnNames": [
"product_type_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_product_type_id\" ON \"cart_line_item\" (product_type_id) WHERE deleted_at IS NULL AND product_type_id IS NOT NULL"
},
{
"keyName": "IDX_cart_line_item_deleted_at",
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_deleted_at\" ON \"cart_line_item\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "cart_line_item_pkey",
"columnNames": [
@@ -774,6 +777,7 @@
"id"
],
"referencedTableName": "public.cart",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
@@ -816,17 +820,17 @@
"nullable": false,
"mappedType": "decimal"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"provider_id": {
"name": "provider_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
"nullable": true,
"mappedType": "text"
},
"provider_id": {
"name": "provider_id",
"promotion_id": {
"name": "promotion_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
@@ -843,6 +847,24 @@
"nullable": true,
"mappedType": "json"
},
"item_id": {
"name": "item_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -865,24 +887,6 @@
"default": "now()",
"mappedType": "datetime"
},
"item_id": {
"name": "item_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"promotion_id": {
"name": "promotion_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
@@ -898,34 +902,36 @@
"schema": "public",
"indexes": [
{
"keyName": "IDX_adjustment_item_id",
"columnNames": [
"item_id"
],
"keyName": "IDX_cart_line_item_adjustment_item_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_adjustment_item_id\" ON \"cart_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_adjustment_item_id\" ON \"cart_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_line_item_adjustment_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_adjustment_deleted_at\" ON \"cart_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_line_item_adjustment_promotion_id",
"columnNames": [
"promotion_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_adjustment_promotion_id\" ON \"cart_line_item_adjustment\" (promotion_id) WHERE deleted_at IS NULL AND promotion_id IS NOT NULL"
},
{
"keyName": "IDX_cart_line_item_adjustment_deleted_at",
"columnNames": [
"deleted_at"
],
"keyName": "IDX_adjustment_item_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_adjustment_deleted_at\" ON \"cart_line_item_adjustment\" (deleted_at) WHERE deleted_at IS NOT NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_adjustment_item_id\" ON \"cart_line_item_adjustment\" (item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "cart_line_item_adjustment_pkey",
@@ -955,6 +961,7 @@
"id"
],
"referencedTableName": "public.cart_line_item",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
@@ -990,12 +997,12 @@
},
"rate": {
"name": "rate",
"type": "numeric",
"type": "integer",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "decimal"
"mappedType": "integer"
},
"provider_id": {
"name": "provider_id",
@@ -1015,6 +1022,24 @@
"nullable": true,
"mappedType": "json"
},
"tax_rate_id": {
"name": "tax_rate_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"item_id": {
"name": "item_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -1037,24 +1062,6 @@
"default": "now()",
"mappedType": "datetime"
},
"item_id": {
"name": "item_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"tax_rate_id": {
"name": "tax_rate_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
@@ -1070,34 +1077,36 @@
"schema": "public",
"indexes": [
{
"keyName": "IDX_tax_line_item_id",
"columnNames": [
"item_id"
],
"keyName": "IDX_cart_line_item_tax_line_item_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_tax_line_item_id\" ON \"cart_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_tax_line_item_id\" ON \"cart_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_line_item_tax_line_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_tax_line_deleted_at\" ON \"cart_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_line_item_tax_line_tax_rate_id",
"columnNames": [
"tax_rate_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_line_item_tax_line_tax_rate_id\" ON \"cart_line_item_tax_line\" (tax_rate_id) WHERE deleted_at IS NULL AND tax_rate_id IS NOT NULL"
},
{
"keyName": "IDX_cart_line_item_tax_line_deleted_at",
"columnNames": [
"deleted_at"
],
"keyName": "IDX_tax_line_item_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_line_item_tax_line_deleted_at\" ON \"cart_line_item_tax_line\" (deleted_at) WHERE deleted_at IS NOT NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_tax_line_item_id\" ON \"cart_line_item_tax_line\" (item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "cart_line_item_tax_line_pkey",
@@ -1121,6 +1130,7 @@
"id"
],
"referencedTableName": "public.cart_line_item",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
@@ -1136,15 +1146,6 @@
"nullable": false,
"mappedType": "text"
},
"cart_id": {
"name": "cart_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"name": {
"name": "name",
"type": "text",
@@ -1172,15 +1173,6 @@
"nullable": false,
"mappedType": "decimal"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"is_tax_inclusive": {
"name": "is_tax_inclusive",
"type": "boolean",
@@ -1218,6 +1210,24 @@
"nullable": true,
"mappedType": "json"
},
"cart_id": {
"name": "cart_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -1254,11 +1264,25 @@
"name": "cart_shipping_method",
"schema": "public",
"indexes": [
{
"keyName": "IDX_cart_shipping_method_cart_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_cart_id\" ON \"cart_shipping_method\" (cart_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_shipping_method_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_deleted_at\" ON \"cart_shipping_method\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_shipping_method_cart_id",
"columnNames": [
"cart_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -1266,24 +1290,12 @@
},
{
"keyName": "IDX_shipping_method_option_id",
"columnNames": [
"shipping_option_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_method_option_id\" ON \"cart_shipping_method\" (shipping_option_id) WHERE deleted_at IS NULL AND shipping_option_id IS NOT NULL"
},
{
"keyName": "IDX_cart_shipping_method_deleted_at",
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_deleted_at\" ON \"cart_shipping_method\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "cart_shipping_method_pkey",
"columnNames": [
@@ -1312,6 +1324,7 @@
"id"
],
"referencedTableName": "public.cart",
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
@@ -1354,15 +1367,6 @@
"nullable": false,
"mappedType": "decimal"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"provider_id": {
"name": "provider_id",
"type": "text",
@@ -1381,6 +1385,33 @@
"nullable": true,
"mappedType": "json"
},
"promotion_id": {
"name": "promotion_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"shipping_method_id": {
"name": "shipping_method_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"raw_amount": {
"name": "raw_amount",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -1403,24 +1434,6 @@
"default": "now()",
"mappedType": "datetime"
},
"shipping_method_id": {
"name": "shipping_method_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"promotion_id": {
"name": "promotion_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
@@ -1436,34 +1449,36 @@
"schema": "public",
"indexes": [
{
"keyName": "IDX_adjustment_shipping_method_id",
"columnNames": [
"shipping_method_id"
],
"keyName": "IDX_cart_shipping_method_adjustment_shipping_method_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_adjustment_shipping_method_id\" ON \"cart_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_adjustment_shipping_method_id\" ON \"cart_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_shipping_method_adjustment_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_adjustment_deleted_at\" ON \"cart_shipping_method_adjustment\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_shipping_method_adjustment_promotion_id",
"columnNames": [
"promotion_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_method_adjustment_promotion_id\" ON \"cart_shipping_method_adjustment\" (promotion_id) WHERE deleted_at IS NULL AND promotion_id IS NOT NULL"
},
{
"keyName": "IDX_cart_shipping_method_adjustment_deleted_at",
"columnNames": [
"deleted_at"
],
"keyName": "IDX_adjustment_shipping_method_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_adjustment_deleted_at\" ON \"cart_shipping_method_adjustment\" (deleted_at) WHERE deleted_at IS NOT NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_adjustment_shipping_method_id\" ON \"cart_shipping_method_adjustment\" (shipping_method_id) WHERE deleted_at IS NULL"
},
{
"keyName": "cart_shipping_method_adjustment_pkey",
@@ -1522,12 +1537,12 @@
},
"rate": {
"name": "rate",
"type": "numeric",
"type": "integer",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "decimal"
"mappedType": "integer"
},
"provider_id": {
"name": "provider_id",
@@ -1538,6 +1553,15 @@
"nullable": true,
"mappedType": "text"
},
"tax_rate_id": {
"name": "tax_rate_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
@@ -1547,6 +1571,15 @@
"nullable": true,
"mappedType": "json"
},
"shipping_method_id": {
"name": "shipping_method_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
@@ -1569,24 +1602,6 @@
"default": "now()",
"mappedType": "datetime"
},
"shipping_method_id": {
"name": "shipping_method_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"tax_rate_id": {
"name": "tax_rate_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
@@ -1601,11 +1616,25 @@
"name": "cart_shipping_method_tax_line",
"schema": "public",
"indexes": [
{
"keyName": "IDX_cart_shipping_method_tax_line_shipping_method_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_tax_line_shipping_method_id\" ON \"cart_shipping_method_tax_line\" (shipping_method_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_cart_shipping_method_tax_line_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_tax_line_deleted_at\" ON \"cart_shipping_method_tax_line\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_tax_line_shipping_method_id",
"columnNames": [
"shipping_method_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
@@ -1613,24 +1642,12 @@
},
{
"keyName": "IDX_shipping_method_tax_line_tax_rate_id",
"columnNames": [
"tax_rate_id"
],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_method_tax_line_tax_rate_id\" ON \"cart_shipping_method_tax_line\" (tax_rate_id) WHERE deleted_at IS NULL AND tax_rate_id IS NOT NULL"
},
{
"keyName": "IDX_cart_shipping_method_tax_line_deleted_at",
"columnNames": [
"deleted_at"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_cart_shipping_method_tax_line_deleted_at\" ON \"cart_shipping_method_tax_line\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "cart_shipping_method_tax_line_pkey",
"columnNames": [

View File

@@ -0,0 +1,139 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20241205095237 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table if exists "cart_line_item" drop constraint if exists "cart_line_item_cart_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item_adjustment" drop constraint if exists "cart_line_item_adjustment_item_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" drop constraint if exists "cart_line_item_tax_line_item_id_foreign";'
)
this.addSql(
'alter table if exists "cart_shipping_method" drop constraint if exists "cart_shipping_method_cart_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "requires_shipping" type boolean using ("requires_shipping"::boolean);'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "requires_shipping" set default true;'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_discountable" type boolean using ("is_discountable"::boolean);'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_discountable" set default true;'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" set default false;'
)
this.addSql(
'alter table if exists "cart_line_item" add constraint "cart_line_item_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade on delete cascade;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_cart_id" ON "cart_line_item" (cart_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'alter table if exists "cart_line_item_adjustment" add constraint "cart_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade on delete cascade;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_adjustment_item_id" ON "cart_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" alter column "rate" type integer using ("rate"::integer);'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade on delete cascade;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_tax_line_item_id" ON "cart_line_item_tax_line" (item_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'alter table if exists "cart_shipping_method" add constraint "cart_shipping_method_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade on delete cascade;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_cart_id" ON "cart_shipping_method" (cart_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_adjustment_shipping_method_id" ON "cart_shipping_method_adjustment" (shipping_method_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'alter table if exists "cart_shipping_method_tax_line" alter column "rate" type integer using ("rate"::integer);'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_tax_line_shipping_method_id" ON "cart_shipping_method_tax_line" (shipping_method_id) WHERE deleted_at IS NULL;'
)
}
async down(): Promise<void> {
this.addSql(
'alter table if exists "cart_line_item" drop constraint if exists "cart_line_item_cart_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item_adjustment" drop constraint if exists "cart_line_item_adjustment_item_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" drop constraint if exists "cart_line_item_tax_line_item_id_foreign";'
)
this.addSql(
'alter table if exists "cart_shipping_method" drop constraint if exists "cart_shipping_method_cart_id_foreign";'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" drop default;'
)
this.addSql(
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);'
)
this.addSql('drop index if exists "IDX_cart_line_item_cart_id";')
this.addSql(
'alter table if exists "cart_line_item" add constraint "cart_line_item_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade;'
)
this.addSql('drop index if exists "IDX_cart_line_item_adjustment_item_id";')
this.addSql(
'alter table if exists "cart_line_item_adjustment" add constraint "cart_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" alter column "rate" type numeric using ("rate"::numeric);'
)
this.addSql('drop index if exists "IDX_cart_line_item_tax_line_item_id";')
this.addSql(
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;'
)
this.addSql('drop index if exists "IDX_cart_shipping_method_cart_id";')
this.addSql(
'alter table if exists "cart_shipping_method" add constraint "cart_shipping_method_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade;'
)
this.addSql(
'drop index if exists "IDX_cart_shipping_method_adjustment_shipping_method_id";'
)
this.addSql(
'alter table if exists "cart_shipping_method_tax_line" alter column "rate" type numeric using ("rate"::numeric);'
)
this.addSql(
'drop index if exists "IDX_cart_shipping_method_tax_line_shipping_method_id";'
)
}
}

View File

@@ -1,97 +1,22 @@
import { DAL } from "@medusajs/framework/types"
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
Filter,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
type OptionalAddressProps = DAL.SoftDeletableModelDateColumns
const PgIndex = createPsqlIndexStatementHelper({
tableName: "cart_address",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
@Entity({ tableName: "cart_address" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class Address {
[OptionalProps]: OptionalAddressProps
@PrimaryKey({ columnType: "text" })
id!: string
@Property({ columnType: "text", nullable: true })
customer_id: string | null = null
@Property({ columnType: "text", nullable: true })
company: string | null = null
@Property({ columnType: "text", nullable: true })
first_name: string | null = null
@Property({ columnType: "text", nullable: true })
last_name: string | null = null
@Property({ columnType: "text", nullable: true })
address_1: string | null = null
@Property({ columnType: "text", nullable: true })
address_2: string | null = null
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text", nullable: true })
country_code: string | null = null
@Property({ columnType: "text", nullable: true })
province: string | null = null
@Property({ columnType: "text", nullable: true })
postal_code: string | null = null
@Property({ columnType: "text", nullable: true })
phone: string | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PgIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "caaddr")
const Address = model.define(
{ tableName: "cart_address", name: "Address" },
{
id: model.id({ prefix: "caaddr" }).primaryKey(),
customer_id: model.text().nullable(),
company: model.text().nullable(),
first_name: model.text().nullable(),
last_name: model.text().nullable(),
address_1: model.text().nullable(),
address_2: model.text().nullable(),
city: model.text().nullable(),
country_code: model.text().nullable(),
province: model.text().nullable(),
postal_code: model.text().nullable(),
phone: model.text().nullable(),
metadata: model.json().nullable(),
}
)
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "caaddr")
}
}
export default Address

View File

@@ -1,49 +0,0 @@
import { DAL } from "@medusajs/framework/types"
import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/framework/utils"
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
type OptionalAdjustmentLineProps = DAL.SoftDeletableModelDateColumns
/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
export default abstract class AdjustmentLine {
[OptionalProps]: OptionalAdjustmentLineProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text", nullable: true })
description: string | null = null
@Property({ columnType: "text", nullable: true })
code: string | null = null
@MikroOrmBigNumberProperty()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
raw_amount: Record<string, unknown>
@Property({ columnType: "text", nullable: true })
provider_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
}

View File

@@ -1,181 +1,76 @@
import { DAL } from "@medusajs/framework/types"
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToOne,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import Address from "./address"
import LineItem from "./line-item"
import ShippingMethod from "./shipping-method"
type OptionalCartProps =
| "shipping_address"
| "billing_address"
| DAL.SoftDeletableModelDateColumns
const RegionIdIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_region_id",
tableName: "cart",
columns: "region_id",
where: "deleted_at IS NULL AND region_id IS NOT NULL",
}).MikroORMIndex
const CustomerIdIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_customer_id",
tableName: "cart",
columns: "customer_id",
where: "deleted_at IS NULL AND customer_id IS NOT NULL",
}).MikroORMIndex
const SalesChannelIdIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_sales_channel_id",
tableName: "cart",
columns: "sales_channel_id",
where: "deleted_at IS NULL AND sales_channel_id IS NOT NULL",
}).MikroORMIndex
const CurrencyCodeIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_curency_code",
tableName: "cart",
columns: "currency_code",
where: "deleted_at IS NULL",
}).MikroORMIndex
const ShippingAddressIdIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_shipping_address_id",
tableName: "cart",
columns: "shipping_address_id",
where: "deleted_at IS NULL AND shipping_address_id IS NOT NULL",
}).MikroORMIndex
const BillingAddressIdIndex = createPsqlIndexStatementHelper({
name: "IDX_cart_billing_address_id",
tableName: "cart",
columns: "billing_address_id",
where: "deleted_at IS NULL AND billing_address_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class Cart {
[OptionalProps]?: OptionalCartProps
@PrimaryKey({ columnType: "text" })
id: string
@RegionIdIndex()
@Property({ columnType: "text", nullable: true })
region_id: string | null = null
@CustomerIdIndex()
@Property({ columnType: "text", nullable: true })
customer_id: string | null = null
@SalesChannelIdIndex()
@Property({ columnType: "text", nullable: true })
sales_channel_id: string | null = null
@Property({ columnType: "text", nullable: true })
email: string | null = null
@CurrencyCodeIndex()
@Property({ columnType: "text" })
currency_code: string
@ShippingAddressIdIndex()
@ManyToOne({
entity: () => Address,
columnType: "text",
fieldName: "shipping_address_id",
mapToPk: true,
nullable: true,
const Cart = model
.define("Cart", {
id: model.id({ prefix: "cart" }).primaryKey(),
region_id: model.text().nullable(),
customer_id: model.text().nullable(),
sales_channel_id: model.text().nullable(),
email: model.text().nullable(),
currency_code: model.text(),
metadata: model.json().nullable(),
completed_at: model.dateTime().nullable(),
shipping_address: model
.hasOne(() => Address, {
mappedBy: undefined,
foreignKey: true,
})
.nullable(),
billing_address: model
.hasOne(() => Address, {
mappedBy: undefined,
foreignKey: true,
})
.nullable(),
items: model.hasMany(() => LineItem, {
mappedBy: "cart",
}),
shipping_methods: model.hasMany(() => ShippingMethod, {
mappedBy: "cart",
}),
})
shipping_address_id: string | null
@ManyToOne(() => Address, {
cascade: [Cascade.PERSIST],
nullable: true,
.cascades({
delete: [
"items",
"shipping_methods",
"shipping_address",
"billing_address",
],
})
shipping_address: Rel<Address> | null
.indexes([
{
name: "IDX_cart_region_id",
on: ["region_id"],
where: "deleted_at IS NULL AND region_id IS NOT NULL",
},
{
name: "IDX_cart_customer_id",
on: ["customer_id"],
where: "deleted_at IS NULL AND customer_id IS NOT NULL",
},
{
name: "IDX_cart_sales_channel_id",
on: ["sales_channel_id"],
where: "deleted_at IS NULL AND sales_channel_id IS NOT NULL",
},
{
name: "IDX_cart_curency_code",
on: ["currency_code"],
where: "deleted_at IS NULL",
},
{
name: "IDX_cart_shipping_address_id",
on: ["shipping_address_id"],
where: "deleted_at IS NULL AND shipping_address_id IS NOT NULL",
},
{
name: "IDX_cart_billing_address_id",
on: ["billing_address_id"],
where: "deleted_at IS NULL AND billing_address_id IS NOT NULL",
},
])
@BillingAddressIdIndex()
@ManyToOne({
entity: () => Address,
columnType: "text",
fieldName: "billing_address_id",
mapToPk: true,
nullable: true,
})
billing_address_id: string | null
@ManyToOne(() => Address, {
cascade: [Cascade.PERSIST],
nullable: true,
})
billing_address: Rel<Address> | null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@OneToMany(() => LineItem, (lineItem) => lineItem.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
items = new Collection<Rel<LineItem>>(this)
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
shipping_methods = new Collection<Rel<ShippingMethod>>(this)
@Property({ columnType: "timestamptz", nullable: true })
completed_at: Date | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "cart")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "cart")
}
}
export default Cart

View File

@@ -1,74 +1,34 @@
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Check,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
Rel,
} from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import { model } from "@medusajs/framework/utils"
import LineItem from "./line-item"
const LineItemIdIndex = createPsqlIndexStatementHelper({
name: "IDX_adjustment_item_id",
tableName: "cart_line_item_adjustment",
columns: "item_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const LineItemAdjustment = model
.define(
{ name: "LineItemAdjustment", tableName: "cart_line_item_adjustment" },
{
id: model.id({ prefix: "caliadj" }).primaryKey(),
description: model.text().nullable(),
code: model.text().nullable(),
amount: model.bigNumber(),
provider_id: model.text().nullable(),
promotion_id: model.text().nullable(),
metadata: model.json().nullable(),
item: model.belongsTo(() => LineItem, {
mappedBy: "adjustments",
}),
}
)
.indexes([
{
name: "IDX_line_item_adjustment_promotion_id",
on: ["promotion_id"],
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
},
{
name: "IDX_adjustment_item_id",
on: ["item_id"],
where: "deleted_at IS NULL",
},
])
.checks([(columns) => `${columns.amount} >= 0`])
const PromotionIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_adjustment_promotion_id",
tableName: "cart_line_item_adjustment",
columns: "promotion_id",
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_line_item_adjustment",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_line_item_adjustment" })
@Check<LineItemAdjustment>({
expression: (columns) => `${columns.amount} >= 0`,
})
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class LineItemAdjustment extends AdjustmentLine {
@ManyToOne({ entity: () => LineItem, persist: false })
item: Rel<LineItem>
@LineItemIdIndex()
@ManyToOne({
entity: () => LineItem,
columnType: "text",
fieldName: "item_id",
mapToPk: true,
})
item_id: string
@PromotionIdIndex()
@Property({ columnType: "text", nullable: true })
promotion_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "caliadj")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "caliadj")
}
}
export default LineItemAdjustment

View File

@@ -1,70 +1,36 @@
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import LineItem from "./line-item"
import TaxLine from "./tax-line"
const LineItemIdIndex = createPsqlIndexStatementHelper({
name: "IDX_tax_line_item_id",
tableName: "cart_line_item_tax_line",
columns: "item_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const LineItemTaxLine = model
.define(
{
name: "LineItemTaxLine",
tableName: "cart_line_item_tax_line",
},
{
id: model.id({ prefix: "calitxl" }).primaryKey(),
description: model.text().nullable(),
code: model.text(),
rate: model.number(),
provider_id: model.text().nullable(),
metadata: model.json().nullable(),
tax_rate_id: model.text().nullable(),
item: model.belongsTo(() => LineItem, {
mappedBy: "tax_lines",
}),
}
)
.indexes([
{
name: "IDX_line_item_tax_line_tax_rate_id",
on: ["tax_rate_id"],
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
},
{
name: "IDX_tax_line_item_id",
on: ["item_id"],
where: "deleted_at IS NULL",
},
])
const TaxRateIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_tax_line_tax_rate_id",
tableName: "cart_line_item_tax_line",
columns: "tax_rate_id",
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_line_item_tax_line",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_line_item_tax_line" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class LineItemTaxLine extends TaxLine {
@ManyToOne({ entity: () => LineItem, persist: false })
item: Rel<LineItem>
@LineItemIdIndex()
@ManyToOne({
entity: () => LineItem,
columnType: "text",
fieldName: "item_id",
mapToPk: true,
})
item_id: string
@TaxRateIdIndex()
@Property({ columnType: "text", nullable: true })
tax_rate_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "calitxl")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "calitxl")
}
}
export default LineItemTaxLine

View File

@@ -1,205 +1,71 @@
import { BigNumberRawValue, DAL } from "@medusajs/framework/types"
import {
BigNumber,
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
MikroOrmBigNumberProperty,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToOne,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import Cart from "./cart"
import LineItemAdjustment from "./line-item-adjustment"
import LineItemTaxLine from "./line-item-tax-line"
import LineItemAdjustment from "./line-item-adjustment"
type OptionalLineItemProps =
| "is_discoutable"
| "is_tax_inclusive"
| "compare_at_unit_price"
| "requires_shipping"
| "cart"
| DAL.SoftDeletableModelDateColumns
const CartIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_cart_id",
tableName: "cart_line_item",
columns: "cart_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const VariantIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_variant_id",
tableName: "cart_line_item",
columns: "variant_id",
where: "deleted_at IS NULL AND variant_id IS NOT NULL",
}).MikroORMIndex
const ProductIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_product_id",
tableName: "cart_line_item",
columns: "product_id",
where: "deleted_at IS NULL AND product_id IS NOT NULL",
}).MikroORMIndex
const ProductTypeIdIndex = createPsqlIndexStatementHelper({
name: "IDX_line_item_product_type_id",
tableName: "cart_line_item",
columns: "product_type_id",
where: "deleted_at IS NULL AND product_type_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_line_item",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_line_item" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class LineItem {
[OptionalProps]?: OptionalLineItemProps
@PrimaryKey({ columnType: "text" })
id: string
@CartIdIndex()
@ManyToOne({
entity: () => Cart,
columnType: "text",
fieldName: "cart_id",
mapToPk: true,
const LineItem = model
.define(
{ name: "LineItem", tableName: "cart_line_item" },
{
id: model.id({ prefix: "cali" }).primaryKey(),
title: model.text(),
subtitle: model.text().nullable(),
thumbnail: model.text().nullable(),
quantity: model.number(),
variant_id: model.text().nullable(),
product_id: model.text().nullable(),
product_title: model.text().nullable(),
product_description: model.text().nullable(),
product_subtitle: model.text().nullable(),
product_type: model.text().nullable(),
product_type_id: model.text().nullable(),
product_collection: model.text().nullable(),
product_handle: model.text().nullable(),
variant_sku: model.text().nullable(),
variant_barcode: model.text().nullable(),
variant_title: model.text().nullable(),
variant_option_values: model.json().nullable(),
requires_shipping: model.boolean().default(true),
is_discountable: model.boolean().default(true),
is_tax_inclusive: model.boolean().default(false),
compare_at_unit_price: model.bigNumber().nullable(),
unit_price: model.bigNumber(),
metadata: model.json().nullable(),
adjustments: model.hasMany(() => LineItemAdjustment, {
mappedBy: "item",
}),
tax_lines: model.hasMany(() => LineItemTaxLine, {
mappedBy: "item",
}),
cart: model.belongsTo(() => Cart, {
mappedBy: "items",
}),
}
)
.indexes([
{
name: "IDX_line_item_cart_id",
on: ["cart_id"],
where: "deleted_at IS NULL",
},
{
name: "IDX_line_item_variant_id",
on: ["variant_id"],
where: "deleted_at IS NULL AND variant_id IS NOT NULL",
},
{
name: "IDX_line_item_product_id",
on: ["product_id"],
where: "deleted_at IS NULL AND product_id IS NOT NULL",
},
{
name: "IDX_line_item_product_type_id",
on: ["product_type_id"],
where: "deleted_at IS NULL AND product_type_id IS NOT NULL",
},
])
.cascades({
delete: ["adjustments", "tax_lines"],
})
cart_id: string
@ManyToOne({ entity: () => Cart, persist: false })
cart: Rel<Cart>
@Property({ columnType: "text" })
title: string
@Property({ columnType: "text", nullable: true })
subtitle: string | null = null
@Property({ columnType: "text", nullable: true })
thumbnail: string | null = null
@Property({ columnType: "integer" })
quantity: number
@VariantIdIndex()
@Property({ columnType: "text", nullable: true })
variant_id: string | null = null
@ProductIdIndex()
@Property({ columnType: "text", nullable: true })
product_id: string | null = null
@Property({ columnType: "text", nullable: true })
product_title: string | null = null
@Property({ columnType: "text", nullable: true })
product_description: string | null = null
@Property({ columnType: "text", nullable: true })
product_subtitle: string | null = null
@Property({ columnType: "text", nullable: true })
product_type: string | null = null
@ProductTypeIdIndex()
@Property({ columnType: "text", nullable: true })
product_type_id: string | null = null
@Property({ columnType: "text", nullable: true })
product_collection: string | null = null
@Property({ columnType: "text", nullable: true })
product_handle: string | null = null
@Property({ columnType: "text", nullable: true })
variant_sku: string | null = null
@Property({ columnType: "text", nullable: true })
variant_barcode: string | null = null
@Property({ columnType: "text", nullable: true })
variant_title: string | null = null
@Property({ columnType: "jsonb", nullable: true })
variant_option_values: Record<string, unknown> | null = null
@Property({ columnType: "boolean" })
requires_shipping: boolean = true
@Property({ columnType: "boolean" })
is_discountable: boolean = true
@Property({ columnType: "boolean" })
is_tax_inclusive: boolean = false
@MikroOrmBigNumberProperty({ nullable: true })
compare_at_unit_price?: BigNumber | number | null = null
@Property({ columnType: "jsonb", nullable: true })
raw_compare_at_unit_price: BigNumberRawValue | null = null
@MikroOrmBigNumberProperty()
unit_price: BigNumber | number
@Property({ columnType: "jsonb" })
raw_unit_price: BigNumberRawValue
@OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.item, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
tax_lines = new Collection<Rel<LineItemTaxLine>>(this)
@OneToMany(() => LineItemAdjustment, (adjustment) => adjustment.item, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
adjustments = new Collection<Rel<LineItemAdjustment>>(this)
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "cali")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "cali")
}
}
export default LineItem

View File

@@ -1,70 +1,36 @@
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
Rel,
} from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import { model } from "@medusajs/framework/utils"
import ShippingMethod from "./shipping-method"
const ShippingMethodIdIndex = createPsqlIndexStatementHelper({
name: "IDX_adjustment_shipping_method_id",
tableName: "cart_shipping_method_adjustment",
columns: "shipping_method_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const ShippingMethodAdjustment = model
.define(
{
name: "ShippingMethodAdjustment",
tableName: "cart_shipping_method_adjustment",
},
{
id: model.id({ prefix: "casmadj" }).primaryKey(),
description: model.text().nullable(),
code: model.text().nullable(),
amount: model.bigNumber(),
provider_id: model.text().nullable(),
metadata: model.json().nullable(),
promotion_id: model.text().nullable(),
shipping_method: model.belongsTo(() => ShippingMethod, {
mappedBy: "adjustments",
}),
}
)
.indexes([
{
name: "IDX_shipping_method_adjustment_promotion_id",
on: ["promotion_id"],
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
},
{
name: "IDX_adjustment_shipping_method_id",
on: ["shipping_method_id"],
where: "deleted_at IS NULL",
},
])
const PromotionIdIndex = createPsqlIndexStatementHelper({
name: "IDX_shipping_method_adjustment_promotion_id",
tableName: "cart_shipping_method_adjustment",
columns: "promotion_id",
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_shipping_method_adjustment",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_shipping_method_adjustment" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class ShippingMethodAdjustment extends AdjustmentLine {
@ManyToOne({ entity: () => ShippingMethod, persist: false })
shipping_method: Rel<ShippingMethod>
@ShippingMethodIdIndex()
@ManyToOne({
entity: () => ShippingMethod,
columnType: "text",
fieldName: "shipping_method_id",
mapToPk: true,
})
shipping_method_id: string
@PromotionIdIndex()
@Property({ columnType: "text", nullable: true })
promotion_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casmadj")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casmadj")
}
}
export default ShippingMethodAdjustment

View File

@@ -1,70 +1,36 @@
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import ShippingMethod from "./shipping-method"
import TaxLine from "./tax-line"
const ShippingMethodIdIndex = createPsqlIndexStatementHelper({
name: "IDX_tax_line_shipping_method_id",
tableName: "cart_shipping_method_tax_line",
columns: "shipping_method_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const ShippingMethodTaxLine = model
.define(
{
name: "ShippingMethodTaxLine",
tableName: "cart_shipping_method_tax_line",
},
{
id: model.id({ prefix: "casmtxl" }).primaryKey(),
description: model.text().nullable(),
code: model.text(),
rate: model.number(),
provider_id: model.text().nullable(),
tax_rate_id: model.text().nullable(),
metadata: model.json().nullable(),
shipping_method: model.belongsTo(() => ShippingMethod, {
mappedBy: "tax_lines",
}),
}
)
.indexes([
{
name: "IDX_tax_line_shipping_method_id",
on: ["shipping_method_id"],
where: "deleted_at IS NULL",
},
{
name: "IDX_shipping_method_tax_line_tax_rate_id",
on: ["tax_rate_id"],
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
},
])
const TaxRateIdIndex = createPsqlIndexStatementHelper({
name: "IDX_shipping_method_tax_line_tax_rate_id",
tableName: "cart_shipping_method_tax_line",
columns: "tax_rate_id",
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_shipping_method_tax_line",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_shipping_method_tax_line" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class ShippingMethodTaxLine extends TaxLine {
@ManyToOne({ entity: () => ShippingMethod, persist: false })
shipping_method: Rel<ShippingMethod>
@ShippingMethodIdIndex()
@ManyToOne({
entity: () => ShippingMethod,
columnType: "text",
fieldName: "shipping_method_id",
mapToPk: true,
})
shipping_method_id: string
@TaxRateIdIndex()
@Property({ columnType: "text", nullable: true })
tax_rate_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casmtxl")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casmtxl")
}
}
export default ShippingMethodTaxLine

View File

@@ -1,145 +1,46 @@
import { BigNumberRawValue, DAL } from "@medusajs/framework/types"
import {
BigNumber,
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
MikroOrmBigNumberProperty,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Cascade,
Check,
Collection,
Entity,
Filter,
ManyToOne,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import Cart from "./cart"
import ShippingMethodAdjustment from "./shipping-method-adjustment"
import ShippingMethodTaxLine from "./shipping-method-tax-line"
type OptionalShippingMethodProps =
| "cart"
| "is_tax_inclusive"
| DAL.SoftDeletableModelDateColumns
const CartIdIndex = createPsqlIndexStatementHelper({
name: "IDX_shipping_method_cart_id",
tableName: "cart_shipping_method",
columns: "cart_id",
where: "deleted_at IS NULL",
}).MikroORMIndex
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
name: "IDX_shipping_method_option_id",
tableName: "cart_shipping_method",
columns: "shipping_option_id",
where: "deleted_at IS NULL AND shipping_option_id IS NOT NULL",
}).MikroORMIndex
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "cart_shipping_method",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex
@Entity({ tableName: "cart_shipping_method" })
@Check<ShippingMethod>({ expression: (columns) => `${columns.amount} >= 0` })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class ShippingMethod {
[OptionalProps]?: OptionalShippingMethodProps
@PrimaryKey({ columnType: "text" })
id: string
@CartIdIndex()
@ManyToOne({
entity: () => Cart,
columnType: "text",
fieldName: "cart_id",
mapToPk: true,
})
cart_id: string
@ManyToOne({ entity: () => Cart, persist: false })
cart: Rel<Cart>
@Property({ columnType: "text" })
name: string
@Property({ columnType: "jsonb", nullable: true })
description: string | null = null
@MikroOrmBigNumberProperty()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
raw_amount: BigNumberRawValue
@Property({ columnType: "boolean" })
is_tax_inclusive: boolean = false
@ShippingOptionIdIndex()
@Property({ columnType: "text", nullable: true })
shipping_option_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
data: Record<string, unknown> | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@OneToMany(
() => ShippingMethodTaxLine,
(taxLine) => taxLine.shipping_method,
const ShippingMethod = model
.define(
{
cascade: [Cascade.PERSIST, "soft-remove"] as any,
name: "ShippingMethod",
tableName: "cart_shipping_method",
},
{
id: model.id({ prefix: "casm" }).primaryKey(),
name: model.text(),
description: model.json().nullable(),
amount: model.bigNumber(),
is_tax_inclusive: model.boolean().default(false),
shipping_option_id: model.text().nullable(),
data: model.json().nullable(),
metadata: model.json().nullable(),
cart: model.belongsTo(() => Cart, {
mappedBy: "shipping_methods",
}),
tax_lines: model.hasMany(() => ShippingMethodTaxLine, {
mappedBy: "shipping_method",
}),
adjustments: model.hasMany(() => ShippingMethodAdjustment, {
mappedBy: "shipping_method",
}),
}
)
tax_lines = new Collection<Rel<ShippingMethodTaxLine>>(this)
@OneToMany(
() => ShippingMethodAdjustment,
(adjustment) => adjustment.shipping_method,
.indexes([
{
cascade: [Cascade.PERSIST, "soft-remove"] as any,
}
)
adjustments = new Collection<Rel<ShippingMethodAdjustment>>(this)
name: "IDX_shipping_method_cart_id",
on: ["cart_id"],
where: "deleted_at IS NULL",
},
{
name: "IDX_shipping_method_option_id",
on: ["shipping_option_id"],
where: "deleted_at IS NULL AND shipping_option_id IS NOT NULL",
},
])
.checks([(columns) => `${columns.amount} >= 0`])
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casm")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casm")
}
}
export default ShippingMethod

View File

@@ -1,45 +0,0 @@
import { DAL } from "@medusajs/framework/types"
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
type OptionalTaxLineProps = DAL.SoftDeletableModelDateColumns
/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
export default abstract class TaxLine {
[OptionalProps]?: OptionalTaxLineProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text", nullable: true })
description?: string | null
@Property({ columnType: "text" })
code: string
@Property({ columnType: "numeric", serializer: Number })
rate: number
@Property({ columnType: "text", nullable: true })
provider_id?: string | null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
}

View File

@@ -5,6 +5,7 @@ import {
DAL,
FindConfig,
ICartModuleService,
InferEntityType,
InternalModuleDeclaration,
ModulesSdkTypes,
} from "@medusajs/framework/types"
@@ -76,14 +77,30 @@ export default class CartModuleService
implements ICartModuleService
{
protected baseRepository_: DAL.RepositoryService
protected cartService_: ModulesSdkTypes.IMedusaInternalService<Cart>
protected addressService_: ModulesSdkTypes.IMedusaInternalService<Address>
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<LineItem>
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodAdjustment>
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethod>
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<LineItemAdjustment>
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<LineItemTaxLine>
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodTaxLine>
protected cartService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof Cart>
>
protected addressService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof Address>
>
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof LineItem>
>
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof ShippingMethodAdjustment>
>
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof ShippingMethod>
>
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof LineItemAdjustment>
>
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof LineItemTaxLine>
>
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<
InferEntityType<typeof ShippingMethodTaxLine>
>
constructor(
{
@@ -274,7 +291,7 @@ export default class CartModuleService
@MedusaContext() sharedContext: Context = {}
) {
const lineItemsToCreate: CreateLineItemDTO[] = []
const createdCarts: Cart[] = []
const createdCarts: InferEntityType<typeof Cart>[] = []
for (const { items, ...cart } of data) {
const [created] = await this.cartService_.create([cart], sharedContext)
@@ -397,7 +414,7 @@ export default class CartModuleService
data?: CartTypes.CreateLineItemDTO[] | CartTypes.CreateLineItemDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.CartLineItemDTO[]> {
let items: LineItem[] = []
let items: InferEntityType<typeof LineItem>[] = []
if (isString(cartIdOrData)) {
items = await this.addLineItems_(
cartIdOrData,
@@ -422,7 +439,7 @@ export default class CartModuleService
cartId: string,
items: CartTypes.CreateLineItemDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<LineItem[]> {
): Promise<InferEntityType<typeof LineItem>[]> {
const cart = await this.retrieveCart(
cartId,
{ select: ["id"] },
@@ -443,7 +460,7 @@ export default class CartModuleService
protected async addLineItemsBulk_(
data: CreateLineItemDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<LineItem[]> {
): Promise<InferEntityType<typeof LineItem>[]> {
return await this.lineItemService_.create(data, sharedContext)
}
@@ -471,7 +488,7 @@ export default class CartModuleService
data?: CartTypes.UpdateLineItemDTO | Partial<CartTypes.UpdateLineItemDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.CartLineItemDTO[] | CartTypes.CartLineItemDTO> {
let items: LineItem[] = []
let items: InferEntityType<typeof LineItem>[] = []
if (isString(lineItemIdOrDataOrSelector)) {
const item = await this.updateLineItem_(
lineItemIdOrDataOrSelector,
@@ -511,7 +528,7 @@ export default class CartModuleService
lineItemId: string,
data: Partial<CartTypes.UpdateLineItemDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<LineItem> {
): Promise<InferEntityType<typeof LineItem>> {
const [item] = await this.lineItemService_.update(
[{ id: lineItemId, ...data }],
sharedContext
@@ -524,7 +541,7 @@ export default class CartModuleService
protected async updateLineItemsWithSelector_(
updates: CartTypes.UpdateLineItemWithSelectorDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<LineItem[]> {
): Promise<InferEntityType<typeof LineItem>[]> {
let toUpdate: UpdateLineItemDTO[] = []
for (const { selector, data } of updates) {
const items = await this.listLineItems({ ...selector }, {}, sharedContext)
@@ -639,7 +656,7 @@ export default class CartModuleService
): Promise<
CartTypes.CartShippingMethodDTO[] | CartTypes.CartShippingMethodDTO
> {
let methods: ShippingMethod[]
let methods: InferEntityType<typeof ShippingMethod>[]
if (isString(cartIdOrData)) {
methods = await this.addShippingMethods_(
cartIdOrData,
@@ -664,7 +681,7 @@ export default class CartModuleService
cartId: string,
data: CartTypes.CreateShippingMethodForSingleCartDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<ShippingMethod[]> {
): Promise<InferEntityType<typeof ShippingMethod>[]> {
const cart = await this.retrieveCart(
cartId,
{ select: ["id"] },
@@ -685,7 +702,7 @@ export default class CartModuleService
protected async addShippingMethodsBulk_(
data: CartTypes.CreateShippingMethodDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<ShippingMethod[]> {
): Promise<InferEntityType<typeof ShippingMethod>[]> {
return await this.shippingMethodService_.create(
data as unknown as CreateShippingMethodDTO[],
sharedContext
@@ -713,7 +730,7 @@ export default class CartModuleService
adjustments?: CartTypes.CreateLineItemAdjustmentDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemAdjustmentDTO[]> {
let addedAdjustments: LineItemAdjustment[] = []
let addedAdjustments: InferEntityType<typeof LineItemAdjustment>[] = []
if (isString(cartIdOrData)) {
const cart = await this.retrieveCart(
cartIdOrData,
@@ -888,7 +905,8 @@ export default class CartModuleService
| CartTypes.ShippingMethodAdjustmentDTO[]
| CartTypes.ShippingMethodAdjustmentDTO
> {
let addedAdjustments: ShippingMethodAdjustment[] = []
let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] =
[]
if (isString(cartIdOrData)) {
const cart = await this.retrieveCart(
cartIdOrData,
@@ -961,7 +979,7 @@ export default class CartModuleService
| CartTypes.CreateLineItemTaxLineDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO> {
let addedTaxLines: LineItemTaxLine[]
let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[]
if (isString(cartIdOrData)) {
// existence check
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)
@@ -1077,7 +1095,7 @@ export default class CartModuleService
): Promise<
CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO
> {
let addedTaxLines: ShippingMethodTaxLine[]
let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[]
if (isString(cartIdOrData)) {
// existence check
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)