feat(types,utils): DML can create a bigNumber property (#7801)

what:

- adds bigNumber as a property to DML
- creates a bigNumber options field (`raw_{{ field }}`) as a part of the schema

RESOLVES CORE-2375
This commit is contained in:
Riqwan Thamir
2024-06-24 10:29:18 +02:00
committed by GitHub
parent ae6dbc06be
commit 5c944ae5d0
11 changed files with 279 additions and 54 deletions

View File

@@ -1,7 +1,7 @@
import { Property } from "@mikro-orm/core"
import { isPresent, trimZeros } from "../../common"
import { BigNumber } from "../../totals/big-number"
import { BigNumberInput } from "@medusajs/types"
import { Property } from "@mikro-orm/core"
import { isDefined, isPresent, trimZeros } from "../../common"
import { BigNumber } from "../../totals/big-number"
export function MikroOrmBigNumberProperty(
options: Parameters<typeof Property>[0] & {
@@ -45,12 +45,22 @@ export function MikroOrmBigNumberProperty(
const raw = bigNumber.raw!
raw.value = trimZeros(raw.value as string)
this.__helper.__data[columnName] = bigNumber.numeric
this.__helper.__data[rawColumnName] = raw
// Note: this.__helper isn't present when directly working with the entity
// Adding this in optionally for it not to break.
if (isDefined(this.__helper)) {
this.__helper.__data[columnName] = bigNumber.numeric
this.__helper.__data[rawColumnName] = raw
}
this[rawColumnName] = raw
}
// Note: this.__helper isn't present when directly working with the entity
// Adding this in optionally for it not to break.
if (!isDefined(this.__helper)) {
return
}
// This is custom code to keep track of which fields are bignumber, as well as their data
if (!this.__helper.__bignumberdata) {
this.__helper.__bignumberdata = {}