This reverts commit a095245d71.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { BigNumberInput } from "@medusajs/types"
|
||||
import { EntityProperty, Platform, Property, Type } from "@mikro-orm/core"
|
||||
import { isDefined, isObject, isPresent, trimZeros } from "../../common"
|
||||
import { Property } from "@mikro-orm/core"
|
||||
import { isDefined, isPresent, trimZeros } from "../../common"
|
||||
import { BigNumber } from "../../totals/big-number"
|
||||
|
||||
export function MikroOrmBigNumberProperty(
|
||||
@@ -24,11 +24,6 @@ export function MikroOrmBigNumberProperty(
|
||||
return value
|
||||
},
|
||||
set(value: BigNumberInput) {
|
||||
// convert 'null' to null
|
||||
if (value === "null") {
|
||||
value = null as unknown as BigNumberInput
|
||||
}
|
||||
|
||||
if (options?.nullable && !isPresent(value)) {
|
||||
this.__helper.__data[columnName] = null
|
||||
this.__helper.__data[rawColumnName] = null
|
||||
@@ -94,7 +89,7 @@ export function MikroOrmBigNumberProperty(
|
||||
})
|
||||
|
||||
Property({
|
||||
type: BigNumberNumeric,
|
||||
type: "any",
|
||||
columnType: "numeric",
|
||||
trackChanges: false,
|
||||
runtimeType: "any",
|
||||
@@ -102,43 +97,3 @@ export function MikroOrmBigNumberProperty(
|
||||
})(target, columnName)
|
||||
}
|
||||
}
|
||||
|
||||
class BigNumberNumeric extends Type<string | number, string> {
|
||||
constructor(public mode?: "number" | "string") {
|
||||
super()
|
||||
}
|
||||
|
||||
override convertToJSValue(value: string): number | string {
|
||||
if ((this.mode ?? this.prop?.runtimeType) === "number") {
|
||||
return +value
|
||||
}
|
||||
|
||||
if (isObject(value)) {
|
||||
return value // Special case for BigNumberRawValue because the setter will manage the dispatch automatically at a later stage
|
||||
}
|
||||
|
||||
return String(value)
|
||||
}
|
||||
|
||||
override compareValues(a: string, b: string): boolean {
|
||||
return this.format(a) === this.format(b)
|
||||
}
|
||||
|
||||
private format(val: string | number) {
|
||||
/* istanbul ignore next */
|
||||
if (this.prop?.scale == null) {
|
||||
return +val
|
||||
}
|
||||
|
||||
const base = Math.pow(10, this.prop.scale)
|
||||
return Math.round((+val + Number.EPSILON) * base) / base
|
||||
}
|
||||
|
||||
override getColumnType(prop: EntityProperty, platform: Platform) {
|
||||
return platform.getDecimalTypeDeclarationSQL(prop)
|
||||
}
|
||||
|
||||
override compareAsType(): string {
|
||||
return this.mode ?? this.prop?.runtimeType ?? "string"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,11 @@ export class MikroOrmBase {
|
||||
transaction?: TManager
|
||||
} = {}
|
||||
): Promise<any> {
|
||||
this.manager_.global = true // this prevent mikro orm from synchronising the transaction manager entity map back to the manager. Also, it will save us from always forking the manager for each transaction while the transacation manager will fork it again for transaction purpose
|
||||
const freshManager = this.getFreshManager
|
||||
? this.getFreshManager()
|
||||
: this.manager_
|
||||
|
||||
return await transactionWrapper(this.manager_, task, options).catch(
|
||||
return await transactionWrapper(freshManager, task, options).catch(
|
||||
dbErrorMapper
|
||||
)
|
||||
}
|
||||
@@ -465,7 +467,11 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
if (!("strategy" in findOptions_.options)) {
|
||||
if (findOptions_.options.limit != null || findOptions_.options.offset) {
|
||||
Object.assign(findOptions_.options, {
|
||||
strategy: LoadStrategy.BALANCED,
|
||||
strategy: LoadStrategy.SELECT_IN,
|
||||
})
|
||||
} else {
|
||||
Object.assign(findOptions_.options, {
|
||||
strategy: LoadStrategy.JOINED,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user