feat: Add decimal digits and rounding info to currencies (#6991)
This commit is contained in:
1 parent
667c8609cc
commit
7302d078a9
9 files changed
+89
-49
No files matched your search
@@ -19,10 +19,12 @@ moduleIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
code: "cad",
|
||||
name: "Canadian Dollar",
|
||||
decimal_digits: 2,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
name: "US Dollar",
|
||||
decimal_digits: 2,
|
||||
}),
|
||||
])
|
||||
)
|
||||
@@ -116,7 +118,7 @@ moduleIntegrationTestRunner({
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["code"],
|
||||
select: ["code", "rounding"],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -126,6 +128,8 @@ moduleIntegrationTestRunner({
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
code: "aed",
|
||||
rounding: 0,
|
||||
raw_rounding: expect.any(Object),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -41,6 +41,35 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"decimal_digits": {
|
||||
"name": "decimal_digits",
|
||||
"type": "int",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "0",
|
||||
"mappedType": "integer"
|
||||
},
|
||||
"rounding": {
|
||||
"name": "rounding",
|
||||
"type": "numeric",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "0",
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"raw_rounding": {
|
||||
"name": "raw_rounding",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
}
|
||||
},
|
||||
"name": "currency",
|
||||
|
||||
@@ -2,8 +2,24 @@ import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class InitialSetup20240228133303 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
const currencyTables = await this.execute(
|
||||
"select * from information_schema.tables where table_name = 'currency' and table_schema = 'public'"
|
||||
)
|
||||
|
||||
if (currencyTables.length > 0) {
|
||||
// This is so we can still run the api tests, remove completely once that is not needed
|
||||
this.addSql(
|
||||
`alter table "currency" add column "decimal_digits" int not null default 0;`
|
||||
)
|
||||
this.addSql(
|
||||
`alter table "currency" add column "rounding" numeric not null default 0;`
|
||||
)
|
||||
this.addSql(`alter table "currency" add column "raw_rounding" jsonb;`)
|
||||
}
|
||||
|
||||
this.addSql(`create table if not exists "currency"
|
||||
("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null,
|
||||
"decimal_digits" int not null default 0, "rounding" numeric not null default 0, "raw_rounding" jsonb not null,
|
||||
constraint "currency_pkey" primary key ("code"));`)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/utils"
|
||||
import { Entity, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity({ tableName: "currency" })
|
||||
@@ -13,6 +15,15 @@ class Currency {
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "int", default: 0 })
|
||||
decimal_digits: number
|
||||
|
||||
@MikroOrmBigNumberProperty({ default: 0 })
|
||||
rounding: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_rounding: BigNumberRawValue
|
||||
}
|
||||
|
||||
export default Currency
|
||||
Reference in new issue
Block a user