fix(medusa): Order edit confirmation conflict line items update (#5867)
* fix(medusa): Order edit confirmation conflict line items update * naming * Create serious-flowers-provide.md * another proposal * fixes
This commit is contained in:
1 parent
1c6c759aa8
commit
2826605b01
16 files changed
+111
-51
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Order edit confirmation conflict line items update
|
||||||
@@ -97,8 +97,20 @@ export function buildQuery<TWhereKeys extends object, TEntity = unknown>(
|
|||||||
*/
|
*/
|
||||||
function buildWhere<TWhereKeys extends object, TEntity>(
|
function buildWhere<TWhereKeys extends object, TEntity>(
|
||||||
constraints: TWhereKeys
|
constraints: TWhereKeys
|
||||||
): FindOptionsWhere<TEntity> {
|
): FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] {
|
||||||
const where: FindOptionsWhere<TEntity> = {}
|
let where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] = {}
|
||||||
|
|
||||||
|
if (Array.isArray(constraints)) {
|
||||||
|
where = []
|
||||||
|
constraints.forEach((constraint) => {
|
||||||
|
;(where as FindOptionsWhere<TEntity>[]).push(
|
||||||
|
buildWhere(constraint) as FindOptionsWhere<TEntity>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return where
|
||||||
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(constraints)) {
|
for (const [key, value] of Object.entries(constraints)) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
} from "../types/common"
|
} from "../types/common"
|
||||||
import { CreateCustomerInput, UpdateCustomerInput } from "../types/customers"
|
import { CreateCustomerInput, UpdateCustomerInput } from "../types/customers"
|
||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, setMetadata } from "../utils"
|
||||||
|
import { selectorConstraintsToString } from "@medusajs/utils"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -194,9 +195,8 @@ class CustomerService extends TransactionBaseService {
|
|||||||
const customer = await customerRepo.findOne(query)
|
const customer = await customerRepo.findOne(query)
|
||||||
|
|
||||||
if (!customer) {
|
if (!customer) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map((key, value) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Customer with ${selectorConstraints} was not found`
|
`Customer with ${selectorConstraints} was not found`
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import { buildQuery, setMetadata } from "../utils"
|
import { buildQuery, setMetadata } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
import RegionService from "./region"
|
import RegionService from "./region"
|
||||||
|
import {selectorConstraintsToString} from "@medusajs/utils";
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -193,9 +194,7 @@ class GiftCardService extends TransactionBaseService {
|
|||||||
const giftCard = await giftCardRepo.findOne(query)
|
const giftCard = await giftCardRepo.findOne(query)
|
||||||
|
|
||||||
if (!giftCard) {
|
if (!giftCard) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
import { MedusaError } from "medusa-core-utils"
|
import {MedusaError} from "medusa-core-utils"
|
||||||
import { EntityManager, In } from "typeorm"
|
import {EntityManager, In} from "typeorm"
|
||||||
import { DeepPartial } from "typeorm/common/DeepPartial"
|
import {DeepPartial} from "typeorm/common/DeepPartial"
|
||||||
|
|
||||||
import { FlagRouter, MedusaV2Flag } from "@medusajs/utils"
|
import {
|
||||||
import { TransactionBaseService } from "../interfaces"
|
FlagRouter,
|
||||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
MedusaV2Flag,
|
||||||
|
selectorConstraintsToString
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {TransactionBaseService} from "../interfaces"
|
||||||
|
import TaxInclusivePricingFeatureFlag
|
||||||
|
from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||||
import {
|
import {
|
||||||
LineItem,
|
LineItem,
|
||||||
LineItemAdjustment,
|
LineItemAdjustment,
|
||||||
LineItemTaxLine,
|
LineItemTaxLine,
|
||||||
ProductVariant,
|
ProductVariant,
|
||||||
} from "../models"
|
} from "../models"
|
||||||
import { CartRepository } from "../repositories/cart"
|
import {CartRepository} from "../repositories/cart"
|
||||||
import { LineItemRepository } from "../repositories/line-item"
|
import {LineItemRepository} from "../repositories/line-item"
|
||||||
import { LineItemTaxLineRepository } from "../repositories/line-item-tax-line"
|
import {LineItemTaxLineRepository} from "../repositories/line-item-tax-line"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import {FindConfig, Selector} from "../types/common"
|
||||||
import { GenerateInputData, GenerateLineItemContext } from "../types/line-item"
|
import {GenerateInputData, GenerateLineItemContext} from "../types/line-item"
|
||||||
import { ProductVariantPricing } from "../types/pricing"
|
import {ProductVariantPricing} from "../types/pricing"
|
||||||
import { buildQuery, isString, setMetadata } from "../utils"
|
import {buildQuery, isString, setMetadata} from "../utils"
|
||||||
import {
|
import {
|
||||||
PricingService,
|
PricingService,
|
||||||
ProductService,
|
ProductService,
|
||||||
@@ -461,9 +466,7 @@ class LineItemService extends TransactionBaseService {
|
|||||||
let lineItems = await this.list(selector)
|
let lineItems = await this.list(selector)
|
||||||
|
|
||||||
if (!lineItems.length) {
|
if (!lineItems.length) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
FindOptionsWhere,
|
FindOptionsWhere,
|
||||||
ILike,
|
ILike,
|
||||||
IsNull,
|
IsNull,
|
||||||
|
Not,
|
||||||
} from "typeorm"
|
} from "typeorm"
|
||||||
import { FindConfig, Selector } from "../types/common"
|
import { FindConfig, Selector } from "../types/common"
|
||||||
import {
|
import {
|
||||||
@@ -753,9 +754,12 @@ export default class OrderEditService extends TransactionBaseService {
|
|||||||
|
|
||||||
const lineItemServiceTx = this.lineItemService_.withTransaction(manager)
|
const lineItemServiceTx = this.lineItemService_.withTransaction(manager)
|
||||||
|
|
||||||
const [lineItems] = await promiseAll([
|
const [originalOrderLineItems] = await promiseAll([
|
||||||
lineItemServiceTx.update(
|
lineItemServiceTx.update(
|
||||||
{ order_id: orderEdit.order_id },
|
[
|
||||||
|
{ order_id: orderEdit.order_id, order_edit_id: Not(orderEditId) },
|
||||||
|
{ order_id: orderEdit.order_id, order_edit_id: IsNull() },
|
||||||
|
],
|
||||||
{ order_id: null }
|
{ order_id: null }
|
||||||
),
|
),
|
||||||
lineItemServiceTx.update(
|
lineItemServiceTx.update(
|
||||||
@@ -770,7 +774,7 @@ export default class OrderEditService extends TransactionBaseService {
|
|||||||
orderEdit = await orderEditRepository.save(orderEdit)
|
orderEdit = await orderEditRepository.save(orderEdit)
|
||||||
|
|
||||||
if (this.inventoryService_) {
|
if (this.inventoryService_) {
|
||||||
const itemsIds = lineItems.map((i) => i.id)
|
const itemsIds = originalOrderLineItems.map((i) => i.id)
|
||||||
await this.inventoryService_!.deleteReservationItemsByLineItem(
|
await this.inventoryService_!.deleteReservationItemsByLineItem(
|
||||||
itemsIds,
|
itemsIds,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
FlagRouter,
|
FlagRouter,
|
||||||
isDefined,
|
isDefined,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
promiseAll,
|
promiseAll, selectorConstraintsToString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
EntityManager,
|
EntityManager,
|
||||||
@@ -453,9 +453,8 @@ class OrderService extends TransactionBaseService {
|
|||||||
const raw = await orderRepo.findOneWithRelations(rels, query)
|
const raw = await orderRepo.findOneWithRelations(rels, query)
|
||||||
|
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map((key, value) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
`Order with ${selectorConstraints} was not found`
|
`Order with ${selectorConstraints} was not found`
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
UpdateProductCategoryInput,
|
UpdateProductCategoryInput,
|
||||||
} from "../types/product-category"
|
} from "../types/product-category"
|
||||||
import { buildQuery, nullableValue, setMetadata } from "../utils"
|
import { buildQuery, nullableValue, setMetadata } from "../utils"
|
||||||
|
import {selectorConstraintsToString} from "@medusajs/utils";
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -115,9 +116,7 @@ class ProductCategoryService extends TransactionBaseService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!productCategory) {
|
if (!productCategory) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
buildSelects,
|
buildSelects,
|
||||||
FlagRouter,
|
FlagRouter,
|
||||||
objectToStringPath,
|
objectToStringPath,
|
||||||
promiseAll,
|
promiseAll, selectorConstraintsToString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||||
import { EntityManager, In } from "typeorm"
|
import { EntityManager, In } from "typeorm"
|
||||||
@@ -306,9 +306,7 @@ class ProductService extends TransactionBaseService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!product) {
|
if (!product) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
} from "../types/publishable-api-key"
|
} from "../types/publishable-api-key"
|
||||||
import { buildQuery, isString } from "../utils"
|
import { buildQuery, isString } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
|
import {selectorConstraintsToString} from "@medusajs/utils";
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
manager: EntityManager
|
manager: EntityManager
|
||||||
@@ -123,9 +124,7 @@ class PublishableApiKeyService extends TransactionBaseService {
|
|||||||
const publishableApiKey = await repo.findOne(query)
|
const publishableApiKey = await repo.findOne(query)
|
||||||
|
|
||||||
if (!publishableApiKey) {
|
if (!publishableApiKey) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map((key, value) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { SalesChannelRepository } from "../repositories/sales-channel"
|
|||||||
import { buildQuery } from "../utils"
|
import { buildQuery } from "../utils"
|
||||||
import EventBusService from "./event-bus"
|
import EventBusService from "./event-bus"
|
||||||
import StoreService from "./store"
|
import StoreService from "./store"
|
||||||
|
import {selectorConstraintsToString} from "@medusajs/utils";
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
salesChannelRepository: typeof SalesChannelRepository
|
salesChannelRepository: typeof SalesChannelRepository
|
||||||
@@ -67,9 +68,7 @@ class SalesChannelService extends TransactionBaseService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!salesChannel) {
|
if (!salesChannel) {
|
||||||
const selectorConstraints = Object.entries(selector)
|
const selectorConstraints = selectorConstraintsToString(selector)
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
|
||||||
.join(", ")
|
|
||||||
|
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
@@ -14,13 +14,11 @@ import {
|
|||||||
IsObject,
|
IsObject,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
Validate,
|
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { Transform, Type } from "class-transformer"
|
import { Transform, Type } from "class-transformer"
|
||||||
|
|
||||||
import { BaseEntity } from "../interfaces"
|
import { BaseEntity } from "../interfaces"
|
||||||
import { ClassConstructor } from "./global"
|
import { ClassConstructor } from "./global"
|
||||||
import { ExactlyOne } from "./validators/exactly-one"
|
|
||||||
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
|
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
|
||||||
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
|
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
|
||||||
import { transformDate } from "../utils/validators/date-transform"
|
import { transformDate } from "../utils/validators/date-transform"
|
||||||
@@ -70,7 +68,7 @@ export type TreeQuerySelector<TEntity> = QuerySelector<TEntity> & {
|
|||||||
include_descendants_tree?: boolean
|
include_descendants_tree?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Selector<TEntity> = {
|
type InnerSelector<TEntity> = {
|
||||||
[key in keyof TEntity]?:
|
[key in keyof TEntity]?:
|
||||||
| TEntity[key]
|
| TEntity[key]
|
||||||
| TEntity[key][]
|
| TEntity[key][]
|
||||||
@@ -80,6 +78,10 @@ export type Selector<TEntity> = {
|
|||||||
| FindOperator<TEntity[key][] | string | string[]>
|
| FindOperator<TEntity[key][] | string | string[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Selector<TEntity> =
|
||||||
|
| InnerSelector<TEntity>
|
||||||
|
| InnerSelector<TEntity>[]
|
||||||
|
|
||||||
export type TotalField =
|
export type TotalField =
|
||||||
| "shipping_total"
|
| "shipping_total"
|
||||||
| "discount_total"
|
| "discount_total"
|
||||||
|
|||||||
@@ -99,8 +99,20 @@ export function buildQuery<TWhereKeys extends object, TEntity = unknown>(
|
|||||||
*/
|
*/
|
||||||
function buildWhere<TWhereKeys extends object, TEntity>(
|
function buildWhere<TWhereKeys extends object, TEntity>(
|
||||||
constraints: TWhereKeys
|
constraints: TWhereKeys
|
||||||
): FindOptionsWhere<TEntity> {
|
): FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] {
|
||||||
const where: FindOptionsWhere<TEntity> = {}
|
let where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] = {}
|
||||||
|
|
||||||
|
if (Array.isArray(constraints)) {
|
||||||
|
where = []
|
||||||
|
constraints.forEach((constraint) => {
|
||||||
|
;(where as FindOptionsWhere<TEntity>[]).push(
|
||||||
|
buildWhere(constraint) as FindOptionsWhere<TEntity>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return where
|
||||||
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(constraints)) {
|
for (const [key, value] of Object.entries(constraints)) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -97,8 +97,20 @@ export function buildQuery<TWhereKeys extends object, TEntity = unknown>(
|
|||||||
*/
|
*/
|
||||||
function buildWhere<TWhereKeys extends object, TEntity>(
|
function buildWhere<TWhereKeys extends object, TEntity>(
|
||||||
constraints: TWhereKeys
|
constraints: TWhereKeys
|
||||||
): FindOptionsWhere<TEntity> {
|
): FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] {
|
||||||
const where: FindOptionsWhere<TEntity> = {}
|
let where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[] = {}
|
||||||
|
|
||||||
|
if (Array.isArray(constraints)) {
|
||||||
|
where = []
|
||||||
|
constraints.forEach((constraint) => {
|
||||||
|
;(where as FindOptionsWhere<TEntity>[]).push(
|
||||||
|
buildWhere(constraint) as FindOptionsWhere<TEntity>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return where
|
||||||
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(constraints)) {
|
for (const [key, value] of Object.entries(constraints)) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export * from "./promise-all"
|
|||||||
export * from "./remote-query-object-from-string"
|
export * from "./remote-query-object-from-string"
|
||||||
export * from "./remote-query-object-to-string"
|
export * from "./remote-query-object-to-string"
|
||||||
export * from "./remove-nullisih"
|
export * from "./remove-nullisih"
|
||||||
|
export * from "./selector-constraints-to-string"
|
||||||
export * from "./set-metadata"
|
export * from "./set-metadata"
|
||||||
export * from "./simple-hash"
|
export * from "./simple-hash"
|
||||||
export * from "./string-to-select-relation-object"
|
export * from "./string-to-select-relation-object"
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
export function selectorConstraintsToString(
|
||||||
|
selector: object | object[]
|
||||||
|
): string {
|
||||||
|
const selectors = Array.isArray(selector) ? selector : [selector]
|
||||||
|
|
||||||
|
return selectors
|
||||||
|
.map((selector_) => {
|
||||||
|
return Object.entries(selector_)
|
||||||
|
.map(
|
||||||
|
([key, value]: [string, any]) =>
|
||||||
|
`${key}: ${value._type ? `${value._type}(${value._value})` : value}`
|
||||||
|
)
|
||||||
|
.join(", ")
|
||||||
|
})
|
||||||
|
.join(" or ")
|
||||||
|
}
|
||||||
Reference in new issue
Block a user