feat: Add supported currencies to store model (#6562)

I ultimately went with having a flat list of settings for the store. It wouldn't be very difficult to change it if we wish to do so, but for now this keeps the codebase simpler
This commit is contained in:
Stevche Radevski
2024-03-01 15:43:47 +00:00
committed by GitHub
parent 347aba719c
commit 71ed21de4a
10 changed files with 40 additions and 3 deletions
@@ -46,11 +46,15 @@ describe("Store - Admin", () => {
it("should correctly implement the entire lifecycle of a store", async () => { it("should correctly implement the entire lifecycle of a store", async () => {
const api = useApi() as any const api = useApi() as any
const createdStore = await service.create({ name: "Test store" }) const createdStore = await service.create({
name: "Test store",
supported_currency_codes: ["usd"],
})
expect(createdStore).toEqual( expect(createdStore).toEqual(
expect.objectContaining({ expect.objectContaining({
id: createdStore.id, id: createdStore.id,
supported_currency_codes: ["usd"],
name: "Test store", name: "Test store",
}) })
) )
@@ -3,6 +3,7 @@ export const allowedAdminStoreRelations = []
export const defaultAdminStoreFields = [ export const defaultAdminStoreFields = [
"id", "id",
"name", "name",
"supported_currency_codes",
"default_sales_channel_id", "default_sales_channel_id",
"default_region_id", "default_region_id",
"default_location_id", "default_location_id",
@@ -1,5 +1,11 @@
import { Type } from "class-transformer" import { Type } from "class-transformer"
import { IsObject, IsOptional, IsString, ValidateNested } from "class-validator" import {
IsArray,
IsObject,
IsOptional,
IsString,
ValidateNested,
} from "class-validator"
import { FindParams, extendedFindParamsMixin } from "../../../types/common" import { FindParams, extendedFindParamsMixin } from "../../../types/common"
export class AdminGetStoresStoreParams extends FindParams {} export class AdminGetStoresStoreParams extends FindParams {}
@@ -41,6 +47,10 @@ export class AdminPostStoresStoreReq {
@IsString() @IsString()
name?: string name?: string
@IsOptional()
@IsArray()
supported_currency_codes?: string[]
@IsOptional() @IsOptional()
@IsString() @IsString()
default_sales_channel_id?: string default_sales_channel_id?: string
@@ -2,6 +2,7 @@ import { StoreTypes } from "@medusajs/types"
export const createStoreFixture: StoreTypes.CreateStoreDTO = { export const createStoreFixture: StoreTypes.CreateStoreDTO = {
name: "Test store", name: "Test store",
supported_currency_codes: ["usd", "eur"],
default_sales_channel_id: "test-sales-channel", default_sales_channel_id: "test-sales-channel",
default_region_id: "test-region", default_region_id: "test-region",
metadata: { metadata: {
@@ -19,6 +19,7 @@ moduleIntegrationTestRunner({
expect(store).toEqual( expect(store).toEqual(
expect.objectContaining({ expect.objectContaining({
name: "Test store", name: "Test store",
supported_currency_codes: expect.arrayContaining(["eur", "usd"]),
default_sales_channel_id: "test-sales-channel", default_sales_channel_id: "test-sales-channel",
default_region_id: "test-region", default_region_id: "test-region",
metadata: { metadata: {
@@ -25,6 +25,16 @@
"default": "'Medusa Store'", "default": "'Medusa Store'",
"mappedType": "text" "mappedType": "text"
}, },
"supported_currency_codes": {
"name": "supported_currency_codes",
"type": "text[]",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "'{}'",
"mappedType": "array"
},
"default_sales_channel_id": { "default_sales_channel_id": {
"name": "default_sales_channel_id", "name": "default_sales_channel_id",
"type": "text", "type": "text",
@@ -24,6 +24,9 @@ export class InitialSetup20240226130829 extends Migration {
this.addSql( this.addSql(
`alter table "store" add column "deleted_at" timestamptz null;` `alter table "store" add column "deleted_at" timestamptz null;`
) )
this.addSql(
`alter table "store" add column "supported_currency_codes" text[] not null default \'{}\';`
)
this.addSql( this.addSql(
'create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;' 'create index if not exists "IDX_store_deleted_at" on "store" (deleted_at) where deleted_at is not null;'
@@ -35,7 +38,7 @@ export class InitialSetup20240226130829 extends Migration {
// this.addSql(`alter table "store" drop column "invite_link_template";`) // this.addSql(`alter table "store" drop column "invite_link_template";`)
} else { } else {
this.addSql(`create table if not exists "store" this.addSql(`create table if not exists "store"
("id" text not null, "name" text not null default \'Medusa Store\', ("id" text not null, "name" text not null default \'Medusa Store\', "supported_currency_codes" text[] not null default \'{}\',
"default_sales_channel_id" text null, "default_region_id" text null, "default_location_id" text null, "default_sales_channel_id" text null, "default_region_id" text null, "default_location_id" text null,
"metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null,
constraint "store_pkey" primary key ("id"));`) constraint "store_pkey" primary key ("id"));`)
+3
View File
@@ -35,6 +35,9 @@ export default class Store {
@Property({ columnType: "text", default: "Medusa Store" }) @Property({ columnType: "text", default: "Medusa Store" })
name: string name: string
@Property({ type: "array", default: "{}" })
supported_currency_codes: string[] = []
@Property({ columnType: "text", nullable: true }) @Property({ columnType: "text", nullable: true })
default_sales_channel_id: string | null = null default_sales_channel_id: string | null = null
+1
View File
@@ -3,6 +3,7 @@ import { BaseFilterable } from "../../dal"
export interface StoreDTO { export interface StoreDTO {
id: string id: string
name: string name: string
supported_currency_codes: string[]
default_sales_channel_id?: string default_sales_channel_id?: string
default_region_id?: string default_region_id?: string
default_location_id?: string default_location_id?: string
@@ -1,5 +1,6 @@
export interface CreateStoreDTO { export interface CreateStoreDTO {
name?: string name?: string
supported_currency_codes?: string[]
default_sales_channel_id?: string default_sales_channel_id?: string
default_region_id?: string default_region_id?: string
default_location_id?: string default_location_id?: string
@@ -9,6 +10,7 @@ export interface CreateStoreDTO {
export interface UpsertStoreDTO { export interface UpsertStoreDTO {
id?: string id?: string
name?: string name?: string
supported_currency_codes?: string[]
default_sales_channel_id?: string default_sales_channel_id?: string
default_region_id?: string default_region_id?: string
default_location_id?: string default_location_id?: string
@@ -17,6 +19,7 @@ export interface UpsertStoreDTO {
export interface UpdateStoreDTO { export interface UpdateStoreDTO {
name?: string name?: string
supported_currency_codes?: string[]
default_sales_channel_id?: string default_sales_channel_id?: string
default_region_id?: string default_region_id?: string
default_location_id?: string default_location_id?: string