From af80e0fd2ed75cd3c15282ddcbfb949060dfdd33 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Tue, 6 Sep 2022 15:49:18 +0200 Subject: [PATCH] fix: make prices optional param when updating a variant (#2155) **Why** - It should be possible to update variant props without having to send the prices array with every update --- .changeset/two-cats-stare.md | 5 +++ .../api/__tests__/admin/product.js | 42 +++++++++++++++++++ .../routes/admin/products/update-variant.ts | 1 + 3 files changed, 48 insertions(+) create mode 100644 .changeset/two-cats-stare.md diff --git a/.changeset/two-cats-stare.md b/.changeset/two-cats-stare.md new file mode 100644 index 0000000000..3154db4d51 --- /dev/null +++ b/.changeset/two-cats-stare.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): make prices optional param when updating a variant diff --git a/integration-tests/api/__tests__/admin/product.js b/integration-tests/api/__tests__/admin/product.js index ecf115a234..cec69f5992 100644 --- a/integration-tests/api/__tests__/admin/product.js +++ b/integration-tests/api/__tests__/admin/product.js @@ -2374,6 +2374,48 @@ describe("/admin/products", () => { }) }) + describe("POST /admin/products/:id/variants/:id", () => { + beforeEach(async () => { + await adminSeeder(dbConnection) + + await simpleProductFactory(dbConnection, { + id: "test-product-to-update", + variants: [ + { + id: "test-variant-to-update", + }, + ], + }) + }) + + afterEach(async () => { + const db = useDb() + await db.teardown() + }) + + it("successfully updates variant without prices", async () => { + const api = useApi() + + const res = await api + .post( + "/admin/products/test-product-to-update/variants/test-variant-to-update", + { + inventory_quantity: 10, + }, + { + headers: { + Authorization: "Bearer test_token", + }, + } + ) + .catch((err) => { + console.log(err) + }) + + expect(res.status).toEqual(200) + }) + }) + describe("GET /admin/products/tag-usage", () => { beforeEach(async () => { await productSeeder(dbConnection) diff --git a/packages/medusa/src/api/routes/admin/products/update-variant.ts b/packages/medusa/src/api/routes/admin/products/update-variant.ts index aec9018fff..221e6bbaff 100644 --- a/packages/medusa/src/api/routes/admin/products/update-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/update-variant.ts @@ -310,6 +310,7 @@ export class AdminPostProductsProductVariantsVariantReq { metadata?: object @IsArray() + @IsOptional() @ValidateNested({ each: true }) @Type(() => ProductVariantPricesUpdateReq) prices: ProductVariantPricesUpdateReq[]