Skip to content

Commit ec44432

Browse files
authored
chore: fixes to http and request types for products (medusajs#13833)
## Summary **What** — What changes are introduced in this PR? This PR is part of a series of PRs to fix HTTP and request type arguments. This is the last PR in the series. It includes a changeset for the changes made. **Why** — Why are these changes relevant or necessary? These types impact the outputted OAS which we show on the API reference. By fixing up the types, we ensure accurate request parameters in the API reference. **How** — How have these changes been implemented? Made changes to HTTP types and request type arguments **Testing** — How have these changes been tested, or how can the reviewer test the feature? - --- ## Examples - --- ## Checklist Please ensure the following before requesting a review: - [ ] I have added a **changeset** for this PR - Every non-breaking change should be marked as a **patch** - To add a changeset, run `yarn changeset` and follow the prompts - [ ] The changes are covered by relevant **tests** - [ ] I have verified the code works as intended locally - [ ] I have linked the related issue(s) if applicable --- ## Additional Context -
1 parent 799b57c commit ec44432

File tree

25 files changed

+124
-47
lines changed

25 files changed

+124
-47
lines changed

.changeset/empty-peaches-crash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/types": patch
3+
"@medusajs/medusa": patch
4+
---
5+
6+
chore(types,medusa): clean up HTTP and request type arguments

packages/core/types/src/http/product/admin/payloads.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ export interface AdminUpdateProduct {
404404
* The product's images.
405405
*/
406406
images?: {
407+
/**
408+
* The ID of the image to update
409+
* or set for existing images.
410+
*/
411+
id?: string
407412
/**
408413
* The image's URL.
409414
*/
@@ -532,6 +537,12 @@ export interface AdminUpdateProductOption {
532537
values?: string[]
533538
}
534539

540+
/**
541+
* @privateRemarks
542+
* These types don't match the validators, however, they're used by the admin
543+
* dashboard. We should update the admin dashboard to use different types that it
544+
* needs instead.
545+
*/
535546
interface AdminCreateProductVariantInventoryItem {
536547
/**
537548
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant, Medusa checks the availability of the quantity multiplied by the
@@ -548,6 +559,12 @@ interface AdminCreateProductVariantInventoryItem {
548559
variant_id: string
549560
}
550561

562+
/**
563+
* @privateRemarks
564+
* These types don't match the validators, however, they're used by the admin
565+
* dashboard. We should update the admin dashboard to use different types that it
566+
* needs instead.
567+
*/
551568
interface AdminUpdateProductVariantInventoryItem {
552569
/**
553570
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant, Medusa checks the availability of the quantity multiplied by the

packages/core/types/src/http/product/admin/queries.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,16 @@ export interface AdminProductListParams
6060
*/
6161
variants?: Omit<AdminProductVariantParams, "q">
6262
}
63+
64+
export interface AdminProductExportParams extends Omit<AdminProductListParams, "tags" | "variants"> {
65+
tags?: {
66+
id?: string[]
67+
}
68+
variants?: {
69+
options?: {
70+
value?: string
71+
option_id?: string
72+
option?: Record<string, any>
73+
}
74+
}
75+
}

packages/medusa/src/api/admin/collections/[id]/products/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { batchLinkProductsToCollectionWorkflow } from "@medusajs/core-flows"
2-
import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types"
2+
import { HttpTypes } from "@medusajs/framework/types"
33
import {
44
AuthenticatedMedusaRequest,
55
MedusaResponse,
66
} from "@medusajs/framework/http"
77
import { refetchCollection } from "../../helpers"
88

99
export const POST = async (
10-
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
10+
req: AuthenticatedMedusaRequest<
11+
HttpTypes.AdminBatchLink,
12+
HttpTypes.AdminCollectionParams
13+
>,
1114
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
1215
) => {
1316
const id = req.params.id

packages/medusa/src/api/admin/collections/[id]/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { refetchCollection } from "../helpers"
1313
import { AdminUpdateCollectionType } from "../validators"
1414

1515
export const GET = async (
16-
req: AuthenticatedMedusaRequest,
16+
req: AuthenticatedMedusaRequest<HttpTypes.AdminCollectionParams>,
1717
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
1818
) => {
1919
const collection = await refetchCollection(
@@ -26,7 +26,10 @@ export const GET = async (
2626
}
2727

2828
export const POST = async (
29-
req: AuthenticatedMedusaRequest<AdminUpdateCollectionType & AdditionalData>,
29+
req: AuthenticatedMedusaRequest<
30+
AdminUpdateCollectionType & AdditionalData,
31+
HttpTypes.AdminCollectionParams
32+
>,
3033
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
3134
) => {
3235
const existingCollection = await refetchCollection(req.params.id, req.scope, [

packages/medusa/src/api/admin/collections/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export const GET = async (
3737
}
3838

3939
export const POST = async (
40-
req: AuthenticatedMedusaRequest<AdminCreateCollectionType & AdditionalData>,
40+
req: AuthenticatedMedusaRequest<
41+
AdminCreateCollectionType & AdditionalData,
42+
HttpTypes.AdminCollectionParams
43+
>,
4144
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
4245
) => {
4346
const { additional_data, ...rest } = req.validatedBody

packages/medusa/src/api/admin/product-categories/[id]/products/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { batchLinkProductsToCategoryWorkflow } from "@medusajs/core-flows"
22
import {
33
AdminProductCategoryResponse,
4-
LinkMethodRequest,
4+
HttpTypes,
55
} from "@medusajs/framework/types"
66
import {
77
AuthenticatedMedusaRequest,
@@ -10,7 +10,10 @@ import {
1010
} from "@medusajs/framework/http"
1111

1212
export const POST = async (
13-
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
13+
req: AuthenticatedMedusaRequest<
14+
HttpTypes.AdminBatchLink,
15+
HttpTypes.AdminProductCategoryParams
16+
>,
1417
res: MedusaResponse<AdminProductCategoryResponse>
1518
) => {
1619
const { id } = req.params

packages/medusa/src/api/admin/product-categories/[id]/route.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import {
1111
MedusaResponse,
1212
refetchEntities,
1313
} from "@medusajs/framework/http"
14-
import {
15-
AdminProductCategoryParamsType,
16-
AdminUpdateProductCategoryType,
17-
} from "../validators"
1814
import { MedusaError } from "@medusajs/framework/utils"
1915

2016
export const GET = async (
21-
req: AuthenticatedMedusaRequest<AdminProductCategoryParamsType>,
17+
req: AuthenticatedMedusaRequest<
18+
HttpTypes.AdminProductCategoryListParams
19+
>,
2220
res: MedusaResponse<AdminProductCategoryResponse>
2321
) => {
2422
const {
@@ -42,7 +40,10 @@ export const GET = async (
4240
}
4341

4442
export const POST = async (
45-
req: AuthenticatedMedusaRequest<AdminUpdateProductCategoryType>,
43+
req: AuthenticatedMedusaRequest<
44+
HttpTypes.AdminUpdateProductCategory,
45+
HttpTypes.AdminProductCategoryParams
46+
>,
4647
res: MedusaResponse<AdminProductCategoryResponse>
4748
) => {
4849
const { id } = req.params

packages/medusa/src/api/admin/product-categories/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export const GET = async (
2727
}
2828

2929
export const POST = async (
30-
req: AuthenticatedMedusaRequest<HttpTypes.AdminCreateProductCategory>,
30+
req: AuthenticatedMedusaRequest<
31+
HttpTypes.AdminCreateProductCategory,
32+
HttpTypes.AdminProductCategoryParams
33+
>,
3134
res: MedusaResponse<HttpTypes.AdminProductCategoryResponse>
3235
) => {
3336
const { result } = await createProductCategoriesWorkflow(req.scope).run({

packages/medusa/src/api/admin/product-tags/[id]/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ import {
77
MedusaResponse,
88
refetchEntity,
99
} from "@medusajs/framework/http"
10-
11-
import {
12-
AdminGetProductTagParamsType,
13-
AdminUpdateProductTagType,
14-
} from "../validators"
1510
import { HttpTypes } from "@medusajs/framework/types"
1611
import { MedusaError } from "@medusajs/framework/utils"
1712

1813
export const GET = async (
19-
req: AuthenticatedMedusaRequest<AdminGetProductTagParamsType>,
14+
req: AuthenticatedMedusaRequest<
15+
HttpTypes.AdminProductTagParams
16+
>,
2017
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
2118
) => {
2219
const productTag = await refetchEntity({
@@ -30,7 +27,10 @@ export const GET = async (
3027
}
3128

3229
export const POST = async (
33-
req: AuthenticatedMedusaRequest<AdminUpdateProductTagType>,
30+
req: AuthenticatedMedusaRequest<
31+
HttpTypes.AdminUpdateProductTag,
32+
HttpTypes.AdminProductTagParams
33+
>,
3434
res: MedusaResponse<HttpTypes.AdminProductTagResponse>
3535
) => {
3636
const existingProductTag = await refetchEntity({

0 commit comments

Comments
 (0)