Skip to content

Commit

Permalink
fix(product): Add metadata to property to product category data model (
Browse files Browse the repository at this point in the history
…#8766)

* fix: Add metadata to property to product category data model

* chore: Add migration for adding metadata column to product category

* chore: Added test for product category metadata
  • Loading branch information
Alexnortung authored Aug 27, 2024
1 parent ff6fcfb commit ac18b5d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ medusaIntegrationTestRunner({
})
)
})

it('gets the metadata of a category', async () => {
await api.post(
`/admin/product-categories/${productCategory.id}`,
{
metadata: {
test: "test"
},
},
adminHeaders
)

const response = await api.get(
`/admin/product-categories/${productCategory.id}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.product_category.metadata).toEqual({ test: "test" })
})
})

describe("GET /admin/product-categories", () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/modules/product/src/migrations/Migration202408271511.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Migration } from "@mikro-orm/migrations"

export class Migration202408271511 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table if exists "product_category" add column if not exists "metadata" jsonb;'
);
}

async down(): Promise<void> {
this.addSql(
'alter table if exists "product_category" drop column if exists "metadata";'
);
}
}
3 changes: 3 additions & 0 deletions packages/modules/product/src/models/product-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class ProductCategory {
@Property({ columnType: "timestamptz", nullable: true })
deleted_at?: Date

@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null

@ManyToMany(() => Product, (product) => product.categories)
products = new Collection<Product>(this)

Expand Down

0 comments on commit ac18b5d

Please sign in to comment.