From 13f40d721702fbcdf6c131354ec9a81322d4a662 Mon Sep 17 00:00:00 2001 From: Patrick <116003638+patrick-medusajs@users.noreply.github.com> Date: Thu, 16 Mar 2023 04:33:09 -0400 Subject: [PATCH] feat(oas): declare x-expanded-relations - Admin (#3483) * feat(oas): declare x-expanded-relations - Admin * fixup! feat(oas): declare x-expanded-relations - Admin * fixup! feat(oas): declare x-expanded-relations - Admin * fixup! feat(oas): declare x-expanded-relations - Admin * fixup! feat(oas): declare x-expanded-relations - Admin * fixup! feat(oas): declare x-expanded-relations - Admin * feat: move defaultAdminOrdersRelations and Fields to types directory * chore(changeset): patch * fix(test): update unit tests --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/fair-melons-run.md | 6 + .../routes/admin/collections/add-products.ts | 7 +- .../admin/collections/create-collection.ts | 5 +- .../src/api/routes/admin/collections/index.ts | 4 + .../admin/collections/update-collection.ts | 5 +- .../src/api/routes/admin/customers/index.ts | 5 + .../src/api/routes/admin/discounts/index.ts | 21 ++ .../api/routes/admin/draft-orders/index.ts | 66 +++- .../admin/draft-orders/register-payment.ts | 8 +- .../src/api/routes/admin/gift-cards/index.ts | 16 + .../inventory-items/create-inventory-item.ts | 5 +- .../inventory-items/create-location-level.ts | 3 + .../inventory-items/delete-inventory-item.ts | 2 + .../inventory-items/delete-location-level.ts | 4 +- .../api/routes/admin/inventory-items/index.ts | 7 +- .../inventory-items/update-inventory-item.ts | 3 + .../inventory-items/update-location-level.ts | 3 + .../api/routes/admin/notifications/index.ts | 8 + .../admin/order-edits/cancel-order-edit.ts | 3 +- .../src/api/routes/admin/order-edits/index.ts | 70 +++++ .../admin/orders/__tests__/get-order.js | 5 +- .../src/api/routes/admin/orders/index.ts | 282 +++++++++++++----- .../routes/admin/payment-collections/index.ts | 9 + .../admin/price-lists/create-price-list.ts | 12 +- .../src/api/routes/admin/price-lists/index.ts | 16 + .../routes/admin/product-categories/index.ts | 10 + .../routes/admin/products/create-variant.ts | 7 +- .../src/api/routes/admin/products/index.ts | 54 +++- .../api/routes/admin/products/set-metadata.ts | 7 +- .../routes/admin/products/update-option.ts | 7 +- .../src/api/routes/admin/regions/index.ts | 18 ++ .../admin/reservations/create-reservation.ts | 2 +- .../admin/reservations/get-reservation.ts | 2 +- .../admin/reservations/update-reservation.ts | 2 +- .../api/routes/admin/return-reasons/index.ts | 10 + .../api/routes/admin/returns/cancel-return.ts | 9 +- .../src/api/routes/admin/returns/index.ts | 66 ++++ .../api/routes/admin/returns/list-returns.ts | 3 +- .../routes/admin/returns/receive-return.ts | 5 +- .../__tests__/get-shipping-options.js | 25 +- .../shipping-options/get-shipping-option.ts | 8 +- .../routes/admin/shipping-options/index.ts | 18 ++ .../routes/admin/shipping-profiles/index.ts | 5 + .../update-shipping-profile.ts | 10 +- .../src/api/routes/admin/store/index.ts | 5 + .../routes/admin/swaps/__tests__/get-swap.js | 14 +- .../src/api/routes/admin/swaps/index.ts | 32 +- .../src/api/routes/admin/variants/index.ts | 14 +- packages/medusa/src/types/orders.ts | 73 +++++ 49 files changed, 854 insertions(+), 127 deletions(-) create mode 100644 .changeset/fair-melons-run.md diff --git a/.changeset/fair-melons-run.md b/.changeset/fair-melons-run.md new file mode 100644 index 0000000000..b588cebd52 --- /dev/null +++ b/.changeset/fair-melons-run.md @@ -0,0 +1,6 @@ +--- +"@medusajs/client-types": patch +"@medusajs/medusa": patch +--- + +feat(oas): declare x-expanded-relations - Admin diff --git a/packages/medusa/src/api/routes/admin/collections/add-products.ts b/packages/medusa/src/api/routes/admin/collections/add-products.ts index 9077ea2aaa..87095295c2 100644 --- a/packages/medusa/src/api/routes/admin/collections/add-products.ts +++ b/packages/medusa/src/api/routes/admin/collections/add-products.ts @@ -3,6 +3,7 @@ import { Request, Response } from "express" import { EntityManager } from "typeorm" import ProductCollectionService from "../../../../services/product-collection" +import { defaultAdminCollectionsRelations } from "./index" /** * @oas [post] /admin/collections/{id}/products/batch @@ -67,12 +68,16 @@ export default async (req: Request, res: Response) => { ) const manager: EntityManager = req.scope.resolve("manager") - const collection = await manager.transaction(async (transactionManager) => { + const updated = await manager.transaction(async (transactionManager) => { return await productCollectionService .withTransaction(transactionManager) .addProducts(id, validatedBody.product_ids) }) + const collection = await productCollectionService.retrieve(updated.id, { + relations: defaultAdminCollectionsRelations, + }) + res.status(200).json({ collection }) } diff --git a/packages/medusa/src/api/routes/admin/collections/create-collection.ts b/packages/medusa/src/api/routes/admin/collections/create-collection.ts index d3c37437f7..95ac6ba156 100644 --- a/packages/medusa/src/api/routes/admin/collections/create-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/create-collection.ts @@ -2,6 +2,7 @@ import { IsNotEmpty, IsObject, IsOptional, IsString } from "class-validator" import ProductCollectionService from "../../../../services/product-collection" import { Request, Response } from "express" import { EntityManager } from "typeorm" +import { defaultAdminCollectionsRelations } from "." /** * @oas [post] /admin/collections @@ -77,7 +78,9 @@ export default async (req: Request, res: Response) => { .create(validatedBody) }) - const collection = await productCollectionService.retrieve(created.id) + const collection = await productCollectionService.retrieve(created.id, { + relations: defaultAdminCollectionsRelations, + }) res.status(200).json({ collection }) } diff --git a/packages/medusa/src/api/routes/admin/collections/index.ts b/packages/medusa/src/api/routes/admin/collections/index.ts index b536b144a5..f17db5b76b 100644 --- a/packages/medusa/src/api/routes/admin/collections/index.ts +++ b/packages/medusa/src/api/routes/admin/collections/index.ts @@ -149,6 +149,10 @@ export type AdminDeleteProductsFromCollectionRes = { /** * @schema AdminCollectionsRes * type: object + * x-expanded-relations: + * field: collection + * relations: + * - products * required: * - collection * properties: diff --git a/packages/medusa/src/api/routes/admin/collections/update-collection.ts b/packages/medusa/src/api/routes/admin/collections/update-collection.ts index c98ffbb8fe..d466bf4362 100644 --- a/packages/medusa/src/api/routes/admin/collections/update-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/update-collection.ts @@ -2,6 +2,7 @@ import { IsObject, IsOptional, IsString } from "class-validator" import { Request, Response } from "express" import { EntityManager } from "typeorm" import ProductCollectionService from "../../../../services/product-collection" +import { defaultAdminCollectionsRelations } from "." /** * @oas [post] /admin/collections/{id} @@ -82,7 +83,9 @@ export default async (req: Request, res: Response) => { .update(id, validatedBody) }) - const collection = await productCollectionService.retrieve(updated.id) + const collection = await productCollectionService.retrieve(updated.id, { + relations: defaultAdminCollectionsRelations, + }) res.status(200).json({ collection }) } diff --git a/packages/medusa/src/api/routes/admin/customers/index.ts b/packages/medusa/src/api/routes/admin/customers/index.ts index dd92fae787..a5f3df6aa6 100644 --- a/packages/medusa/src/api/routes/admin/customers/index.ts +++ b/packages/medusa/src/api/routes/admin/customers/index.ts @@ -23,6 +23,11 @@ export default (app) => { /** * @schema AdminCustomersRes * type: object + * x-expanded-relations: + * field: customer + * relations: + * - orders + * - shipping_addresses * required: * - customer * properties: diff --git a/packages/medusa/src/api/routes/admin/discounts/index.ts b/packages/medusa/src/api/routes/admin/discounts/index.ts index 866d3c48ef..e1e4b5ea39 100644 --- a/packages/medusa/src/api/routes/admin/discounts/index.ts +++ b/packages/medusa/src/api/routes/admin/discounts/index.ts @@ -223,6 +223,16 @@ export const defaultAdminDiscountConditionRelations = ["discount_rule"] /** * @schema AdminDiscountsRes * type: object + * x-expanded-relations: + * field: discount + * relations: + * - parent_discount + * - regions + * - rule + * - rule.conditions + * eager: + * - regions.fulfillment_providers + * - regions.payment_providers * required: * - discount * properties: @@ -236,6 +246,10 @@ export type AdminDiscountsRes = { /** * @schema AdminDiscountConditionsRes * type: object + * x-expanded-relations: + * field: discount_condition + * relations: + * - discount_rule * required: * - discount_condition * properties: @@ -299,6 +313,13 @@ export type AdminDiscountConditionsDeleteRes = DeleteResponse & { /** * @schema AdminDiscountsListRes * type: object + * x-expanded-relations: + * field: discounts + * relations: + * - parent_discount + * - regions + * - rule + * - rule.conditions * required: * - discounts * - count diff --git a/packages/medusa/src/api/routes/admin/draft-orders/index.ts b/packages/medusa/src/api/routes/admin/draft-orders/index.ts index a02f7f74da..616079750a 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/index.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/index.ts @@ -103,10 +103,67 @@ export const defaultAdminDraftOrdersFields: (keyof DraftOrder)[] = [ export type AdminPostDraftOrdersDraftOrderRegisterPaymentRes = { order: Order } - /** * @schema AdminDraftOrdersRes * type: object + * x-expanded-relations: + * field: draft_order + * relations: + * - order + * - cart + * - cart.items + * - cart.items.adjustments + * - cart.billing_address + * - cart.customer + * - cart.discounts + * - cart.discounts.rule + * - cart.items + * - cart.items.adjustments + * - cart.payment + * - cart.payment_sessions + * - cart.region + * - cart.region.payment_providers + * - cart.shipping_address + * - cart.shipping_methods + * - cart.shipping_methods.shipping_option + * eager: + * - cart.region.fulfillment_providers + * - cart.region.payment_providers + * - cart.shipping_methods.shipping_option + * implicit: + * - cart.discounts + * - cart.discounts.rule + * - cart.gift_cards + * - cart.items + * - cart.items.adjustments + * - cart.items.tax_lines + * - cart.items.variant + * - cart.items.variant.product + * - cart.region + * - cart.region.tax_rates + * - cart.shipping_address + * - cart.shipping_methods + * - cart.shipping_methods.tax_lines + * totals: + * - cart.discount_total + * - cart.gift_card_tax_total + * - cart.gift_card_total + * - cart.item_tax_total + * - cart.refundable_amount + * - cart.refunded_total + * - cart.shipping_tax_total + * - cart.shipping_total + * - cart.subtotal + * - cart.tax_total + * - cart.total + * - cart.items.discount_total + * - cart.items.gift_card_total + * - cart.items.original_tax_total + * - cart.items.original_total + * - cart.items.refundable + * - cart.items.subtotal + * - cart.items.tax_total + * - cart.items.total * required: * - draft_order * properties: @@ -142,6 +199,13 @@ export type AdminDraftOrdersDeleteRes = DeleteResponse /** * @schema AdminDraftOrdersListRes * type: object + * x-expanded-relations: + * field: draft_orders + * relations: + * - order + * - cart + * - cart.items + * - cart.items.adjustments * required: * - draft_orders * - count diff --git a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts index fc9d7fc1b4..068435f7b9 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts @@ -5,14 +5,14 @@ import { PaymentProviderService, ProductVariantInventoryService, } from "../../../../services" -import { - defaultAdminOrdersFields as defaultOrderFields, - defaultAdminOrdersRelations as defaultOrderRelations, -} from "../orders/index" import { EntityManager } from "typeorm" import { Order } from "../../../../models" import { MedusaError } from "medusa-core-utils" +import { + defaultAdminOrdersFields as defaultOrderFields, + defaultAdminOrdersRelations as defaultOrderRelations, +} from "../../../../types/orders" /** * @oas [post] /admin/draft-orders/{id}/pay diff --git a/packages/medusa/src/api/routes/admin/gift-cards/index.ts b/packages/medusa/src/api/routes/admin/gift-cards/index.ts index 92b8f757d3..319433bb93 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/index.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/index.ts @@ -59,6 +59,14 @@ export const defaultAdminGiftCardRelations = ["region", "order"] /** * @schema AdminGiftCardsRes * type: object + * x-expanded-relations: + * field: gift_card + * relations: + * - order + * - region + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - gift_card * properties: @@ -94,6 +102,14 @@ export type AdminGiftCardsDeleteRes = DeleteResponse /** * @schema AdminGiftCardsListRes * type: object + * x-expanded-relations: + * field: gift_cards + * relations: + * - order + * - region + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - gift_cards * - count diff --git a/packages/medusa/src/api/routes/admin/inventory-items/create-inventory-item.ts b/packages/medusa/src/api/routes/admin/inventory-items/create-inventory-item.ts index d13471ec94..b96388812c 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/create-inventory-item.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/create-inventory-item.ts @@ -25,7 +25,10 @@ import { FindParams } from "../../../../types/common" * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminPostInventoryItemsItemLocationLevelsReq" + * $ref: "#/components/schemas/AdminPostInventoryItemsReq" + * x-codegen: + * method: create + * queryParams: AdminPostInventoryItemsParams * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/inventory-items/create-location-level.ts b/packages/medusa/src/api/routes/admin/inventory-items/create-location-level.ts index 734ea0cf27..cd70fa823c 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/create-location-level.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/create-location-level.ts @@ -22,6 +22,9 @@ import { FindParams } from "../../../../types/common" * application/json: * schema: * $ref: "#/components/schemas/AdminPostInventoryItemsItemLocationLevelsReq" + * x-codegen: + * method: createLocationLevel + * queryParams: AdminPostInventoryItemsItemLocationLevelsParams * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/inventory-items/delete-inventory-item.ts b/packages/medusa/src/api/routes/admin/inventory-items/delete-inventory-item.ts index e440db90e5..ba6e4fb76e 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/delete-inventory-item.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/delete-inventory-item.ts @@ -11,6 +11,8 @@ import { ProductVariantInventoryService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Inventory Item to delete. + * x-codegen: + * method: delete * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/inventory-items/delete-location-level.ts b/packages/medusa/src/api/routes/admin/inventory-items/delete-location-level.ts index 817b44906c..f26cb8e784 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/delete-location-level.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/delete-location-level.ts @@ -12,8 +12,8 @@ import { IInventoryService } from "../../../../interfaces" * parameters: * - (path) id=* {string} The ID of the Inventory Item. * - (path) location_id=* {string} The ID of the location. - * - (query) expand {string} Comma separated list of relations to include in the results. - * - (query) fields {string} Comma separated list of fields to include in the results. + * x-codegen: + * method: deleteLocationLevel * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/inventory-items/index.ts b/packages/medusa/src/api/routes/admin/inventory-items/index.ts index 7863179cfb..bcb6797b5d 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/index.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/index.ts @@ -11,7 +11,10 @@ import middlewares, { } from "../../../middlewares" import { AdminGetInventoryItemsParams } from "./list-inventory-items" import { AdminGetInventoryItemsItemParams } from "./get-inventory-item" -import { AdminPostInventoryItemsInventoryItemReq } from "./update-inventory-item" +import { + AdminPostInventoryItemsInventoryItemParams, + AdminPostInventoryItemsInventoryItemReq, +} from "./update-inventory-item" import { AdminGetInventoryItemsItemLocationLevelsParams } from "./list-location-levels" import { AdminPostInventoryItemsItemLocationLevelsParams, @@ -52,7 +55,7 @@ export default (app) => { route.post( "/:id", - transformQuery(AdminGetInventoryItemsItemParams, { + transformQuery(AdminPostInventoryItemsInventoryItemParams, { defaultFields: defaultAdminInventoryItemFields, defaultRelations: defaultAdminInventoryItemRelations, isList: false, diff --git a/packages/medusa/src/api/routes/admin/inventory-items/update-inventory-item.ts b/packages/medusa/src/api/routes/admin/inventory-items/update-inventory-item.ts index 38ed6637ae..32d5a28749 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/update-inventory-item.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/update-inventory-item.ts @@ -20,6 +20,9 @@ import { EntityManager } from "typeorm" * application/json: * schema: * $ref: "#/components/schemas/AdminPostInventoryItemsInventoryItemReq" + * x-codegen: + * method: update + * queryParams: AdminPostInventoryItemsInventoryItemParams * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/inventory-items/update-location-level.ts b/packages/medusa/src/api/routes/admin/inventory-items/update-location-level.ts index 2c7e3f8a7a..543ca67137 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/update-location-level.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/update-location-level.ts @@ -21,6 +21,9 @@ import { EntityManager } from "typeorm" * application/json: * schema: * $ref: "#/components/schemas/AdminPostInventoryItemsItemLocationLevelsLevelReq" + * x-codegen: + * method: updateLocationLevel + * queryParams: AdminPostInventoryItemsItemLocationLevelsLevelParams * x-codeSamples: * - lang: JavaScript * label: JS Client diff --git a/packages/medusa/src/api/routes/admin/notifications/index.ts b/packages/medusa/src/api/routes/admin/notifications/index.ts index c00624f7ba..36f4739944 100644 --- a/packages/medusa/src/api/routes/admin/notifications/index.ts +++ b/packages/medusa/src/api/routes/admin/notifications/index.ts @@ -39,6 +39,10 @@ export const defaultAdminNotificationsFields = [ /** * @schema AdminNotificationsListRes * type: object + * x-expanded-relations: + * field: notifications + * relations: + * - resends * required: * - notifications * properties: @@ -54,6 +58,10 @@ export type AdminNotificationsListRes = { /** * @schema AdminNotificationsRes * type: object + * x-expanded-relations: + * field: notification + * relations: + * - resends * required: * - notification * properties: diff --git a/packages/medusa/src/api/routes/admin/order-edits/cancel-order-edit.ts b/packages/medusa/src/api/routes/admin/order-edits/cancel-order-edit.ts index 1da4acc7f5..016d579c77 100644 --- a/packages/medusa/src/api/routes/admin/order-edits/cancel-order-edit.ts +++ b/packages/medusa/src/api/routes/admin/order-edits/cancel-order-edit.ts @@ -70,10 +70,11 @@ export default async (req: Request, res: Response) => { .cancel(id, { canceledBy: userId }) }) - const orderEdit = await orderEditService.retrieve(id, { + let orderEdit = await orderEditService.retrieve(id, { select: defaultOrderEditFields, relations: defaultOrderEditRelations, }) + orderEdit = await orderEditService.decorateTotals(orderEdit) return res.json({ order_edit: orderEdit }) } diff --git a/packages/medusa/src/api/routes/admin/order-edits/index.ts b/packages/medusa/src/api/routes/admin/order-edits/index.ts index 72614e6897..01152b2ca6 100644 --- a/packages/medusa/src/api/routes/admin/order-edits/index.ts +++ b/packages/medusa/src/api/routes/admin/order-edits/index.ts @@ -101,6 +101,41 @@ export default (app) => { /** * @schema AdminOrderEditsRes * type: object + * x-expanded-relations: + * field: order_edit + * relations: + * - changes + * - changes.line_item + * - changes.line_item.variant + * - changes.original_line_item + * - changes.original_line_item.variant + * - items + * - items.adjustments + * - items.tax_lines + * - items.variant + * - payment_collection + * implicit: + * - items + * - items.tax_lines + * - items.adjustments + * - items.variant + * totals: + * - difference_due + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total * required: * - order_edit * properties: @@ -114,6 +149,41 @@ export type AdminOrderEditsRes = { /** * @schema AdminOrderEditsListRes * type: object + * x-expanded-relations: + * field: order_edits + * relations: + * - changes + * - changes.line_item + * - changes.line_item.variant + * - changes.original_line_item + * - changes.original_line_item.variant + * - items + * - items.adjustments + * - items.tax_lines + * - items.variant + * - payment_collection + * implicit: + * - items + * - items.tax_lines + * - items.adjustments + * - items.variant + * totals: + * - difference_due + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total * required: * - order_edits * - count diff --git a/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js b/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js index a54a9d8c3e..e9f1c0b33f 100644 --- a/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js +++ b/packages/medusa/src/api/routes/admin/orders/__tests__/get-order.js @@ -1,7 +1,10 @@ import { IdMap } from "medusa-test-utils" import { request } from "../../../../../helpers/test-request" import { OrderServiceMock } from "../../../../../services/__mocks__/order" -import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "../index" +import { + defaultAdminOrdersFields, + defaultAdminOrdersRelations, +} from "../../../../../types/orders" describe("GET /admin/orders", () => { describe("successfully gets an order", () => { diff --git a/packages/medusa/src/api/routes/admin/orders/index.ts b/packages/medusa/src/api/routes/admin/orders/index.ts index 14fab96c71..bed6c08c98 100644 --- a/packages/medusa/src/api/routes/admin/orders/index.ts +++ b/packages/medusa/src/api/routes/admin/orders/index.ts @@ -72,6 +72,10 @@ import { AdminPostOrdersOrderClaimsClaimShipmentsParams, AdminPostOrdersOrderClaimsClaimShipmentsReq, } from "./create-claim-shipment" +import { + defaultAdminOrdersFields, + defaultAdminOrdersRelations, +} from "../../../../types/orders" const route = Router() @@ -480,6 +484,109 @@ export default (app, featureFlagRouter: FlagRouter) => { /** * @schema AdminOrdersRes * type: object + * x-expanded-relations: + * field: order + * relations: + * - billing_address + * - claims + * - claims.additional_items + * - claims.additional_items.variant + * - claims.claim_items + * - claims.claim_items.images + * - claims.claim_items.item + * - claims.fulfillments + * - claims.fulfillments.tracking_links + * - claims.return_order + * - claims.return_order.shipping_method + * - claims.return_order.shipping_method.tax_lines + * - claims.shipping_address + * - claims.shipping_methods + * - customer + * - discounts + * - discounts.rule + * - fulfillments + * - fulfillments.items + * - fulfillments.tracking_links + * - gift_card_transactions + * - gift_cards + * - items + * - payments + * - refunds + * - region + * - returns + * - returns.items + * - returns.items.reason + * - returns.shipping_method + * - returns.shipping_method.tax_lines + * - shipping_address + * - shipping_methods + * eager: + * - fulfillments.items + * - region.fulfillment_providers + * - region.payment_providers + * - returns.items + * - shipping_methods.shipping_option + * implicit: + * - claims + * - claims.additional_items + * - claims.additional_items.adjustments + * - claims.additional_items.refundable + * - claims.additional_items.tax_lines + * - discounts + * - discounts.rule + * - gift_card_transactions + * - gift_card_transactions.gift_card + * - gift_cards + * - items + * - items.adjustments + * - items.refundable + * - items.tax_lines + * - items.variant + * - items.variant.product + * - refunds + * - region + * - shipping_methods + * - shipping_methods.tax_lines + * - swaps + * - swaps.additional_items + * - swaps.additional_items.adjustments + * - swaps.additional_items.refundable + * - swaps.additional_items.tax_lines + * totals: + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - paid_total + * - refundable_amount + * - refunded_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - claims.additional_items.discount_total + * - claims.additional_items.gift_card_total + * - claims.additional_items.original_tax_total + * - claims.additional_items.original_total + * - claims.additional_items.refundable + * - claims.additional_items.subtotal + * - claims.additional_items.tax_total + * - claims.additional_items.total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total + * - swaps.additional_items.discount_total + * - swaps.additional_items.gift_card_total + * - swaps.additional_items.original_tax_total + * - swaps.additional_items.original_total + * - swaps.additional_items.refundable + * - swaps.additional_items.subtotal + * - swaps.additional_items.tax_total + * - swaps.additional_items.total * required: * - order * properties: @@ -493,6 +600,109 @@ export type AdminOrdersRes = { /** * @schema AdminOrdersListRes * type: object + * x-expanded-relations: + * field: orders + * relations: + * - billing_address + * - claims + * - claims.additional_items + * - claims.additional_items.variant + * - claims.claim_items + * - claims.claim_items.images + * - claims.claim_items.item + * - claims.fulfillments + * - claims.fulfillments.tracking_links + * - claims.return_order + * - claims.return_order.shipping_method + * - claims.return_order.shipping_method.tax_lines + * - claims.shipping_address + * - claims.shipping_methods + * - customer + * - discounts + * - discounts.rule + * - fulfillments + * - fulfillments.items + * - fulfillments.tracking_links + * - gift_card_transactions + * - gift_cards + * - items + * - payments + * - refunds + * - region + * - returns + * - returns.items + * - returns.items.reason + * - returns.shipping_method + * - returns.shipping_method.tax_lines + * - shipping_address + * - shipping_methods + * eager: + * - fulfillments.items + * - region.fulfillment_providers + * - region.payment_providers + * - returns.items + * - shipping_methods.shipping_option + * implicit: + * - claims + * - claims.additional_items + * - claims.additional_items.adjustments + * - claims.additional_items.refundable + * - claims.additional_items.tax_lines + * - discounts + * - discounts.rule + * - gift_card_transactions + * - gift_card_transactions.gift_card + * - gift_cards + * - items + * - items.adjustments + * - items.refundable + * - items.tax_lines + * - items.variant + * - items.variant.product + * - refunds + * - region + * - shipping_methods + * - shipping_methods.tax_lines + * - swaps + * - swaps.additional_items + * - swaps.additional_items.adjustments + * - swaps.additional_items.refundable + * - swaps.additional_items.tax_lines + * totals: + * - discount_total + * - gift_card_tax_total + * - gift_card_total + * - paid_total + * - refundable_amount + * - refunded_total + * - shipping_total + * - subtotal + * - tax_total + * - total + * - claims.additional_items.discount_total + * - claims.additional_items.gift_card_total + * - claims.additional_items.original_tax_total + * - claims.additional_items.original_total + * - claims.additional_items.refundable + * - claims.additional_items.subtotal + * - claims.additional_items.tax_total + * - claims.additional_items.total + * - items.discount_total + * - items.gift_card_total + * - items.original_tax_total + * - items.original_total + * - items.refundable + * - items.subtotal + * - items.tax_total + * - items.total + * - swaps.additional_items.discount_total + * - swaps.additional_items.gift_card_total + * - swaps.additional_items.original_tax_total + * - swaps.additional_items.original_total + * - swaps.additional_items.refundable + * - swaps.additional_items.subtotal + * - swaps.additional_items.tax_total + * - swaps.additional_items.total * required: * - orders * - count @@ -517,78 +727,6 @@ export type AdminOrdersListRes = PaginatedResponse & { orders: Order[] } -export const defaultAdminOrdersRelations = [ - "customer", - "billing_address", - "shipping_address", - "discounts", - "discounts.rule", - "shipping_methods", - "payments", - "items", - "refunds", - "region", - "fulfillments", - "fulfillments.tracking_links", - "fulfillments.items", - "returns", - "returns.shipping_method", - "returns.shipping_method.tax_lines", - "returns.items", - "returns.items.reason", - "gift_cards", - "gift_card_transactions", - "claims", - "claims.return_order", - "claims.return_order.shipping_method", - "claims.return_order.shipping_method.tax_lines", - "claims.shipping_methods", - "claims.shipping_address", - "claims.additional_items", - "claims.additional_items.variant", - "claims.fulfillments", - "claims.fulfillments.tracking_links", - "claims.claim_items", - "claims.claim_items.item", - "claims.claim_items.images", - // "claims.claim_items.tags", - "swaps", - "swaps.return_order", - "swaps.return_order.shipping_method", - "swaps.return_order.shipping_method.tax_lines", - "swaps.payment", - "swaps.shipping_methods", - "swaps.shipping_methods.tax_lines", - "swaps.shipping_address", - "swaps.additional_items", - "swaps.additional_items.variant", - "swaps.fulfillments", - "swaps.fulfillments.tracking_links", -] - -export const defaultAdminOrdersFields = [ - "id", - "status", - "fulfillment_status", - "payment_status", - "display_id", - "cart_id", - "draft_order_id", - "customer_id", - "email", - "region_id", - "currency_code", - "tax_rate", - "canceled_at", - "created_at", - "updated_at", - "metadata", - "items.refundable", - "swaps.additional_items.refundable", - "claims.additional_items.refundable", - "no_notification", -] as (keyof Order)[] - export const filterableAdminOrdersFields = [ "id", "status", diff --git a/packages/medusa/src/api/routes/admin/payment-collections/index.ts b/packages/medusa/src/api/routes/admin/payment-collections/index.ts index 99538714e2..6e9a4642e6 100644 --- a/packages/medusa/src/api/routes/admin/payment-collections/index.ts +++ b/packages/medusa/src/api/routes/admin/payment-collections/index.ts @@ -65,6 +65,15 @@ export const defaulPaymentCollectionRelations = [ /** * @schema AdminPaymentCollectionsRes * type: object + * x-expanded-relations: + * field: payment_collection + * relations: + * - payment_sessions + * - payments + * - region + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - payment_collection * properties: diff --git a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts index 3e79f3ca66..f3b6620bbc 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts @@ -19,6 +19,11 @@ import { EntityManager } from "typeorm" import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing" import PriceListService from "../../../../services/price-list" import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators" +import { + defaultAdminPriceListFields, + defaultAdminPriceListRelations, +} from "./index" +import { PriceList } from "../../../../models" /** * @oas [post] /admin/price-lists @@ -104,12 +109,17 @@ export default async (req: Request, res) => { req.scope.resolve("priceListService") const manager: EntityManager = req.scope.resolve("manager") - const priceList = await manager.transaction(async (transactionManager) => { + let priceList = await manager.transaction(async (transactionManager) => { return await priceListService .withTransaction(transactionManager) .create(req.validatedBody as CreatePriceListInput) }) + priceList = await priceListService.retrieve(priceList.id, { + select: defaultAdminPriceListFields as (keyof PriceList)[], + relations: defaultAdminPriceListRelations, + }) + res.json({ price_list: priceList }) } diff --git a/packages/medusa/src/api/routes/admin/price-lists/index.ts b/packages/medusa/src/api/routes/admin/price-lists/index.ts index 800678b6e0..6805fa3edf 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/index.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/index.ts @@ -96,6 +96,11 @@ export const defaultAdminPriceListRelations = ["prices", "customer_groups"] /** * @schema AdminPriceListRes * type: object + * x-expanded-relations: + * field: price_list + * relations: + * - customer_groups + * - prices * required: * - price_list * properties: @@ -234,6 +239,17 @@ export type AdminPriceListsListRes = PaginatedResponse & { /** * @schema AdminPriceListsProductsListRes * type: object + * x-expanded-relations: + * field: products + * relations: + * - categories + * - collection + * - images + * - options + * - tags + * - type + * - variants + * - variants.options * required: * - products * - count diff --git a/packages/medusa/src/api/routes/admin/product-categories/index.ts b/packages/medusa/src/api/routes/admin/product-categories/index.ts index 41087a789c..2ce3798f2f 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/index.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/index.ts @@ -153,6 +153,11 @@ export const defaultProductCategoryFields = [ /** * @schema AdminProductCategoriesCategoryRes * type: object + * x-expanded-relations: + * field: product_category + * relations: + * - category_children + * - parent_category * required: * - product_category * properties: @@ -188,6 +193,11 @@ export type AdminProductCategoriesCategoryDeleteRes = DeleteResponse /** * @schema AdminProductCategoriesListRes * type: object + * x-expanded-relations: + * field: product_categories + * relations: + * - category_children + * - parent_category * required: * - product_categories * - count diff --git a/packages/medusa/src/api/routes/admin/products/create-variant.ts b/packages/medusa/src/api/routes/admin/products/create-variant.ts index 3d4e0bd7d6..aa1f3d9145 100644 --- a/packages/medusa/src/api/routes/admin/products/create-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/create-variant.ts @@ -9,6 +9,7 @@ import { } from "class-validator" import { Type } from "class-transformer" import { + PricingService, ProductService, ProductVariantInventoryService, ProductVariantService, @@ -146,11 +147,15 @@ export default async (req, res) => { }) const productService: ProductService = req.scope.resolve("productService") - const product = await productService.retrieve(id, { + const pricingService: PricingService = req.scope.resolve("pricingService") + + const rawProduct = await productService.retrieve(id, { select: defaultAdminProductFields, relations: defaultAdminProductRelations, }) + const [product] = await pricingService.setProductPrices([rawProduct]) + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/index.ts b/packages/medusa/src/api/routes/admin/products/index.ts index 072ea12016..75385045b0 100644 --- a/packages/medusa/src/api/routes/admin/products/index.ts +++ b/packages/medusa/src/api/routes/admin/products/index.ts @@ -139,6 +139,17 @@ export const defaultAdminGetProductsVariantsFields = ["id", "product_id"] /** * @schema AdminProductsDeleteOptionRes * type: object + * x-expanded-relations: + * field: product + * relations: + * - collection + * - images + * - options + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - option_id * - object @@ -157,7 +168,7 @@ export const defaultAdminGetProductsVariantsFields = ["id", "product_id"] * description: Whether or not the items were deleted. * default: true * product: - * $ref: "#/components/schemas/Product" + * $ref: "#/components/schemas/PricedProduct" */ export type AdminProductsDeleteOptionRes = { option_id: string @@ -169,6 +180,17 @@ export type AdminProductsDeleteOptionRes = { /** * @schema AdminProductsDeleteVariantRes * type: object + * x-expanded-relations: + * field: product + * relations: + * - collection + * - images + * - options + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - variant_id * - object @@ -187,7 +209,7 @@ export type AdminProductsDeleteOptionRes = { * description: Whether or not the items were deleted. * default: true * product: - * $ref: "#/components/schemas/Product" + * $ref: "#/components/schemas/PricedProduct" */ export type AdminProductsDeleteVariantRes = { variant_id: string @@ -225,6 +247,17 @@ export type AdminProductsDeleteRes = { /** * @schema AdminProductsListRes * type: object + * x-expanded-relations: + * field: products + * relations: + * - collection + * - images + * - options + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - products * - count @@ -234,9 +267,7 @@ export type AdminProductsDeleteRes = { * products: * type: array * items: - * oneOf: - * - $ref: "#/components/schemas/Product" - * - $ref: "#/components/schemas/PricedProduct" + * $ref: "#/components/schemas/PricedProduct" * count: * type: integer * description: The total number of items available @@ -329,11 +360,22 @@ export type AdminProductsListTagsRes = { /** * @schema AdminProductsRes * type: object + * x-expanded-relations: + * field: product + * relations: + * - collection + * - images + * - options + * - tags + * - type + * - variants + * - variants.options + * - variants.prices * required: * - product * properties: * product: - * $ref: "#/components/schemas/Product" + * $ref: "#/components/schemas/PricedProduct" */ export type AdminProductsRes = { product: Product diff --git a/packages/medusa/src/api/routes/admin/products/set-metadata.ts b/packages/medusa/src/api/routes/admin/products/set-metadata.ts index 0898dc79df..56fc47bad6 100644 --- a/packages/medusa/src/api/routes/admin/products/set-metadata.ts +++ b/packages/medusa/src/api/routes/admin/products/set-metadata.ts @@ -3,6 +3,7 @@ import { defaultAdminProductFields, defaultAdminProductRelations } from "." import { IsString } from "class-validator" import { validator } from "../../../../utils/validator" import { EntityManager } from "typeorm" +import { PricingService } from "../../../../services" /** * @oas [post] /admin/products/{id}/metadata @@ -77,6 +78,8 @@ export default async (req, res) => { ) const productService = req.scope.resolve("productService") + const pricingService: PricingService = req.scope.resolve("pricingService") + const manager: EntityManager = req.scope.resolve("manager") await manager.transaction(async (transactionManager) => { return await productService.withTransaction(transactionManager).update(id, { @@ -84,11 +87,13 @@ export default async (req, res) => { }) }) - const product = await productService.retrieve(id, { + const rawProduct = await productService.retrieve(id, { select: defaultAdminProductFields, relations: defaultAdminProductRelations, }) + const [product] = await pricingService.setProductPrices([rawProduct]) + res.status(200).json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/update-option.ts b/packages/medusa/src/api/routes/admin/products/update-option.ts index 9f8da68a8c..345ceff5e1 100644 --- a/packages/medusa/src/api/routes/admin/products/update-option.ts +++ b/packages/medusa/src/api/routes/admin/products/update-option.ts @@ -1,7 +1,7 @@ import { defaultAdminProductFields, defaultAdminProductRelations } from "." import { IsString } from "class-validator" -import { ProductService } from "../../../../services" +import { PricingService, ProductService } from "../../../../services" import { validator } from "../../../../utils/validator" import { EntityManager } from "typeorm" @@ -77,6 +77,7 @@ export default async (req, res) => { ) const productService: ProductService = req.scope.resolve("productService") + const pricingService: PricingService = req.scope.resolve("pricingService") const manager: EntityManager = req.scope.resolve("manager") await manager.transaction(async (transactionManager) => { @@ -85,11 +86,13 @@ export default async (req, res) => { .updateOption(id, option_id, validated) }) - const product = await productService.retrieve(id, { + const rawProduct = await productService.retrieve(id, { select: defaultAdminProductFields, relations: defaultAdminProductRelations, }) + const [product] = await pricingService.setProductPrices([rawProduct]) + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/regions/index.ts b/packages/medusa/src/api/routes/admin/regions/index.ts index e9ddc218d8..3dbe4d72e7 100644 --- a/packages/medusa/src/api/routes/admin/regions/index.ts +++ b/packages/medusa/src/api/routes/admin/regions/index.ts @@ -88,6 +88,15 @@ export const defaultAdminRegionRelations = [ /** * @schema AdminRegionsRes * type: object + * x-expanded-relations: + * field: region + * relations: + * - countries + * - fulfillment_providers + * - payment_providers + * eager: + * - fulfillment_providers + * - payment_providers * required: * - region * properties: @@ -101,6 +110,15 @@ export class AdminRegionsRes { /** * @schema AdminRegionsListRes * type: object + * x-expanded-relations: + * field: regions + * relations: + * - countries + * - fulfillment_providers + * - payment_providers + * eager: + * - fulfillment_providers + * - payment_providers * required: * - regions * - count diff --git a/packages/medusa/src/api/routes/admin/reservations/create-reservation.ts b/packages/medusa/src/api/routes/admin/reservations/create-reservation.ts index c7443540d7..de6f70fac9 100644 --- a/packages/medusa/src/api/routes/admin/reservations/create-reservation.ts +++ b/packages/medusa/src/api/routes/admin/reservations/create-reservation.ts @@ -47,7 +47,7 @@ import { IInventoryService } from "../../../../interfaces" * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminPostReservationsReq" + * $ref: "#/components/schemas/AdminReservationsRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/reservations/get-reservation.ts b/packages/medusa/src/api/routes/admin/reservations/get-reservation.ts index c7ef301491..89e2805742 100644 --- a/packages/medusa/src/api/routes/admin/reservations/get-reservation.ts +++ b/packages/medusa/src/api/routes/admin/reservations/get-reservation.ts @@ -36,7 +36,7 @@ import { IInventoryService } from "../../../../interfaces" * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminPostReservationsReq" + * $ref: "#/components/schemas/AdminReservationsRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/reservations/update-reservation.ts b/packages/medusa/src/api/routes/admin/reservations/update-reservation.ts index 0b1c6dd26e..bd6ce32c25 100644 --- a/packages/medusa/src/api/routes/admin/reservations/update-reservation.ts +++ b/packages/medusa/src/api/routes/admin/reservations/update-reservation.ts @@ -48,7 +48,7 @@ import { IInventoryService } from "../../../../interfaces" * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminPostReservationsReq" + * $ref: "#/components/schemas/AdminReservationsRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/return-reasons/index.ts b/packages/medusa/src/api/routes/admin/return-reasons/index.ts index 902853c00a..630b03244e 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/index.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/index.ts @@ -55,6 +55,11 @@ export const defaultAdminReturnReasonsRelations: (keyof ReturnReason)[] = [ /** * @schema AdminReturnReasonsRes * type: object + * x-expanded-relations: + * field: return_reason + * relations: + * - parent_return_reason + * - return_reason_children * required: * - return_reason * properties: @@ -68,6 +73,11 @@ export type AdminReturnReasonsRes = { /** * @schema AdminReturnReasonsListRes * type: object + * x-expanded-relations: + * field: return_reasons + * relations: + * - parent_return_reason + * - return_reason_children * required: * - return_reasons * properties: diff --git a/packages/medusa/src/api/routes/admin/returns/cancel-return.ts b/packages/medusa/src/api/routes/admin/returns/cancel-return.ts index df64530ef8..49e3787448 100644 --- a/packages/medusa/src/api/routes/admin/returns/cancel-return.ts +++ b/packages/medusa/src/api/routes/admin/returns/cancel-return.ts @@ -1,9 +1,6 @@ import { OrderService, ReturnService } from "../../../../services" -import { - defaultAdminOrdersFields, - defaultAdminOrdersRelations, -} from "../orders" import { EntityManager } from "typeorm" +import { defaultReturnCancelFields, defaultReturnCancelRelations } from "." /** * @oas [post] /admin/returns/{id}/cancel @@ -75,8 +72,8 @@ export default async (req, res) => { } const order = await orderService.retrieve(result.order_id!, { - select: defaultAdminOrdersFields, - relations: defaultAdminOrdersRelations, + select: defaultReturnCancelFields, + relations: defaultReturnCancelRelations, }) res.status(200).json({ order }) diff --git a/packages/medusa/src/api/routes/admin/returns/index.ts b/packages/medusa/src/api/routes/admin/returns/index.ts index d74433e15a..0d240a3fce 100644 --- a/packages/medusa/src/api/routes/admin/returns/index.ts +++ b/packages/medusa/src/api/routes/admin/returns/index.ts @@ -3,6 +3,10 @@ import "reflect-metadata" import { Order, Return } from "../../../.." import { PaginatedResponse } from "../../../../types/common" import middlewares from "../../../middlewares" +import { + defaultAdminOrdersFields, + defaultAdminOrdersRelations, +} from "../../../../types/orders" const route = Router() @@ -27,9 +31,62 @@ export default (app) => { return app } +export const defaultRelations = ["swap"] +export const defaultRelationsList = ["swap", "order"] +export const defaultReturnCancelRelations = [...defaultAdminOrdersRelations] +export const defaultReturnCancelFields = [...defaultAdminOrdersFields] + /** * @schema AdminReturnsCancelRes * type: object + * x-expanded-relations: + * field: order + * relations: + * - billing_address + * - claims + * - claims.additional_items + * - claims.additional_items.variant + * - claims.claim_items + * - claims.claim_items.images + * - claims.claim_items.item + * - claims.fulfillments + * - claims.fulfillments.tracking_links + * - claims.return_order + * - claims.return_order.shipping_method + * - claims.return_order.shipping_method.tax_lines + * - claims.shipping_address + * - claims.shipping_methods + * - customer + * - discounts + * - discounts.rule + * - fulfillments + * - fulfillments.items + * - fulfillments.tracking_links + * - gift_card_transactions + * - gift_cards + * - items + * - payments + * - refunds + * - region + * - returns + * - returns.items + * - returns.items.reason + * - returns.shipping_method + * - returns.shipping_method.tax_lines + * - shipping_address + * - shipping_methods + * - swaps + * - swaps.additional_items + * - swaps.additional_items.variant + * - swaps.fulfillments + * - swaps.fulfillments.tracking_links + * - swaps.payment + * - swaps.return_order + * - swaps.return_order.shipping_method + * - swaps.return_order.shipping_method.tax_lines + * - swaps.shipping_address + * - swaps.shipping_methods + * - swaps.shipping_methods.tax_lines * required: * - order * properties: @@ -43,6 +100,11 @@ export type AdminReturnsCancelRes = { /** * @schema AdminReturnsListRes * type: object + * x-expanded-relation: + * field: returns + * relations: + * - order + * - swap * required: * - returns * - count @@ -70,6 +132,10 @@ export type AdminReturnsListRes = PaginatedResponse & { /** * @schema AdminReturnsRes * type: object + * x-expanded-relation: + * field: return + * relations: + * - swap * required: * - return * properties: diff --git a/packages/medusa/src/api/routes/admin/returns/list-returns.ts b/packages/medusa/src/api/routes/admin/returns/list-returns.ts index 83b6189292..93dc4626a6 100644 --- a/packages/medusa/src/api/routes/admin/returns/list-returns.ts +++ b/packages/medusa/src/api/routes/admin/returns/list-returns.ts @@ -5,6 +5,7 @@ import { Type } from "class-transformer" import { validator } from "../../../../utils/validator" import { FindConfig } from "../../../../types/common" import { Return } from "../../../../models" +import { defaultRelationsList } from "." /** * @oas [get] /admin/returns @@ -66,7 +67,7 @@ export default async (req, res) => { const selector = {} const listConfig = { - relations: ["swap", "order"], + relations: defaultRelationsList, skip: validated.offset, take: validated.limit, order: { created_at: "DESC" }, diff --git a/packages/medusa/src/api/routes/admin/returns/receive-return.ts b/packages/medusa/src/api/routes/admin/returns/receive-return.ts index 75e5a354d5..b13b42a25b 100644 --- a/packages/medusa/src/api/routes/admin/returns/receive-return.ts +++ b/packages/medusa/src/api/routes/admin/returns/receive-return.ts @@ -11,6 +11,7 @@ import { Type } from "class-transformer" import { isDefined } from "medusa-core-utils" import { EntityManager } from "typeorm" import { validator } from "../../../../utils/validator" +import { defaultRelations } from "." /** * @oas [post] /admin/returns/{id}/receive @@ -124,7 +125,9 @@ export default async (req, res) => { } }) - receivedReturn = await returnService.retrieve(id, { relations: ["swap"] }) + receivedReturn = await returnService.retrieve(id, { + relations: defaultRelations, + }) res.status(200).json({ return: receivedReturn }) } diff --git a/packages/medusa/src/api/routes/admin/shipping-options/__tests__/get-shipping-options.js b/packages/medusa/src/api/routes/admin/shipping-options/__tests__/get-shipping-options.js index abe50a807d..ffd130580e 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/__tests__/get-shipping-options.js +++ b/packages/medusa/src/api/routes/admin/shipping-options/__tests__/get-shipping-options.js @@ -2,6 +2,25 @@ import { IdMap } from "medusa-test-utils" import { request } from "../../../../../helpers/test-request" import { ShippingOptionServiceMock } from "../../../../../services/__mocks__/shipping-option" +const defaultFields = [ + "id", + "name", + "region_id", + "profile_id", + "provider_id", + "price_type", + "amount", + "is_return", + "admin_only", + "data", + "created_at", + "updated_at", + "deleted_at", + "metadata", +] + +const defaultRelations = ["region", "profile", "requirements"] + describe("GET /admin/shipping-options/:optionId", () => { describe("successful retrieval", () => { let subject @@ -27,7 +46,11 @@ describe("GET /admin/shipping-options/:optionId", () => { it("calls service retrieve", () => { expect(ShippingOptionServiceMock.retrieve).toHaveBeenCalledTimes(1) expect(ShippingOptionServiceMock.retrieve).toHaveBeenCalledWith( - IdMap.getId("validId") + IdMap.getId("validId"), + { + select: defaultFields, + relations: defaultRelations, + } ) }) }) diff --git a/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts index 55b5b605f3..f6a1f6e317 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts @@ -1,3 +1,5 @@ +import { defaultFields, defaultRelations } from "." + /** * @oas [get] /admin/shipping-options/{id} * operationId: "GetShippingOptionsOption" @@ -52,7 +54,11 @@ export default async (req, res) => { const { option_id } = req.params const optionService = req.scope.resolve("shippingOptionService") - const data = await optionService.retrieve(option_id) + + const data = await optionService.retrieve(option_id, { + select: defaultFields, + relations: defaultRelations, + }) res.status(200).json({ shipping_option: data }) } diff --git a/packages/medusa/src/api/routes/admin/shipping-options/index.ts b/packages/medusa/src/api/routes/admin/shipping-options/index.ts index 222798dc75..59101fdf06 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/index.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/index.ts @@ -55,6 +55,15 @@ export const defaultRelations = ["region", "profile", "requirements"] /** * @schema AdminShippingOptionsListRes * type: object + * x-expanded-relations: + * field: shipping_options + * relations: + * - profile + * - region + * - requirements + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - shipping_options * - count @@ -82,6 +91,15 @@ export type AdminShippingOptionsListRes = PaginatedResponse & { /** * @schema AdminShippingOptionsRes * type: object + * x-expanded-relations: + * field: shipping_option + * relations: + * - profile + * - region + * - requirements + * eager: + * - region.fulfillment_providers + * - region.payment_providers * required: * - shipping_option * properties: diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/index.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/index.ts index 0f7f986278..e88ed1caf4 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/index.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/index.ts @@ -69,6 +69,11 @@ export type AdminDeleteShippingProfileRes = DeleteResponse /** * @schema AdminShippingProfilesRes * type: object + * x-expanded-relations: + * field: shipping_profile + * relations: + * - products + * - shipping_options * required: * - shipping_profile * properties: diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts index 06815f04b7..5dc2799bd3 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts @@ -10,6 +10,10 @@ import { EntityManager } from "typeorm" import { ShippingProfileType } from "../../../../models" import { ShippingProfileService } from "../../../../services" import { validator } from "../../../../utils/validator" +import { + defaultAdminShippingProfilesFields, + defaultAdminShippingProfilesRelations, +} from "." /** * @oas [post] /admin/shipping-profiles/{id} @@ -91,7 +95,11 @@ export default async (req, res) => { .update(profile_id, validated) }) - const data = await profileService.retrieve(profile_id) + const data = await profileService.retrieve(profile_id, { + select: defaultAdminShippingProfilesFields, + relations: defaultAdminShippingProfilesRelations, + }) + res.status(200).json({ shipping_profile: data }) } diff --git a/packages/medusa/src/api/routes/admin/store/index.ts b/packages/medusa/src/api/routes/admin/store/index.ts index 728c1dc596..61db135a58 100644 --- a/packages/medusa/src/api/routes/admin/store/index.ts +++ b/packages/medusa/src/api/routes/admin/store/index.ts @@ -35,6 +35,11 @@ export const defaultRelationsExtended = ["currencies", "default_currency"] /** * @schema AdminExtendedStoresRes * type: object + * x-expanded-relations: + * field: store + * relations: + * - currencies + * - default_currency * required: * - store * properties: diff --git a/packages/medusa/src/api/routes/admin/swaps/__tests__/get-swap.js b/packages/medusa/src/api/routes/admin/swaps/__tests__/get-swap.js index f20facbb21..cc39fbcc8c 100644 --- a/packages/medusa/src/api/routes/admin/swaps/__tests__/get-swap.js +++ b/packages/medusa/src/api/routes/admin/swaps/__tests__/get-swap.js @@ -3,18 +3,18 @@ import { request } from "../../../../../helpers/test-request" import { SwapServiceMock } from "../../../../../services/__mocks__/swap" const defaultRelations = [ - "order", "additional_items", "additional_items.adjustments", - "return_order", - "fulfillments", - "payment", - "shipping_address", - "shipping_methods", "cart", "cart.items", - "cart.items.variant", "cart.items.adjustments", + "cart.items.variant", + "fulfillments", + "order", + "payment", + "return_order", + "shipping_address", + "shipping_methods", ] const defaultFields = [ diff --git a/packages/medusa/src/api/routes/admin/swaps/index.ts b/packages/medusa/src/api/routes/admin/swaps/index.ts index 74461ede6a..10a9d43f25 100644 --- a/packages/medusa/src/api/routes/admin/swaps/index.ts +++ b/packages/medusa/src/api/routes/admin/swaps/index.ts @@ -22,18 +22,18 @@ export default (app) => { } export const defaultAdminSwapRelations = [ - "order", "additional_items", "additional_items.adjustments", - "return_order", - "fulfillments", - "payment", - "shipping_address", - "shipping_methods", "cart", "cart.items", - "cart.items.variant", "cart.items.adjustments", + "cart.items.variant", + "fulfillments", + "order", + "payment", + "return_order", + "shipping_address", + "shipping_methods", ] export const defaultAdminSwapFields = [ @@ -84,6 +84,24 @@ export type AdminSwapsListRes = PaginatedResponse & { /** * @schema AdminSwapsRes * type: object + * x-expanded-relations: + * field: swap + * relations: + * - additional_items + * - additional_items.adjustments + * - cart + * - cart.items + * - cart.items.adjustments + * - cart.items.variant + * - fulfillments + * - order + * - payment + * - return_order + * - shipping_address + * - shipping_methods + * eager: + * - fulfillments.items + * - shipping_methods.shipping_option * required: * - swap * properties: diff --git a/packages/medusa/src/api/routes/admin/variants/index.ts b/packages/medusa/src/api/routes/admin/variants/index.ts index c88ddceb8a..2becbbe587 100644 --- a/packages/medusa/src/api/routes/admin/variants/index.ts +++ b/packages/medusa/src/api/routes/admin/variants/index.ts @@ -75,6 +75,12 @@ export const defaultAdminVariantFields: (keyof ProductVariant)[] = [ /** * @schema AdminVariantsListRes * type: object + * x-expanded-relations: + * field: variants + * relations: + * - options + * - prices + * - product * required: * - variants * - count @@ -84,7 +90,7 @@ export const defaultAdminVariantFields: (keyof ProductVariant)[] = [ * variants: * type: array * items: - * $ref: "#/components/schemas/ProductVariant" + * $ref: "#/components/schemas/PricedVariant" * count: * type: integer * description: The total number of items available @@ -102,6 +108,12 @@ export type AdminVariantsListRes = PaginatedResponse & { /** * @schema AdminVariantsRes * type: object + * x-expanded-relations: + * field: variant + * relations: + * - options + * - prices + * - product * required: * - variant * properties: diff --git a/packages/medusa/src/types/orders.ts b/packages/medusa/src/types/orders.ts index e3127f4959..de03e47588 100644 --- a/packages/medusa/src/types/orders.ts +++ b/packages/medusa/src/types/orders.ts @@ -101,6 +101,79 @@ export type UpdateOrderInput = { payment_status?: PaymentStatus metadata?: Record } + +export const defaultAdminOrdersRelations = [ + "billing_address", + "claims", + "claims.additional_items", + "claims.additional_items.variant", + "claims.claim_items", + "claims.claim_items.images", + "claims.claim_items.item", + "claims.fulfillments", + "claims.fulfillments.tracking_links", + "claims.return_order", + "claims.return_order.shipping_method", + "claims.return_order.shipping_method.tax_lines", + "claims.shipping_address", + "claims.shipping_methods", + "customer", + "discounts", + "discounts.rule", + "fulfillments", + "fulfillments.items", + "fulfillments.tracking_links", + "gift_card_transactions", + "gift_cards", + "items", + "payments", + "refunds", + "region", + "returns", + "returns.items", + "returns.items.reason", + "returns.shipping_method", + "returns.shipping_method.tax_lines", + "shipping_address", + "shipping_methods", + "swaps", + "swaps.additional_items", + "swaps.additional_items.variant", + "swaps.fulfillments", + "swaps.fulfillments.tracking_links", + "swaps.payment", + "swaps.return_order", + "swaps.return_order.shipping_method", + "swaps.return_order.shipping_method.tax_lines", + "swaps.shipping_address", + "swaps.shipping_methods", + "swaps.shipping_methods.tax_lines", + // "claims.claim_items.tags", +] + +export const defaultAdminOrdersFields = [ + "id", + "status", + "fulfillment_status", + "payment_status", + "display_id", + "cart_id", + "draft_order_id", + "customer_id", + "email", + "region_id", + "currency_code", + "tax_rate", + "canceled_at", + "created_at", + "updated_at", + "metadata", + "items.refundable", + "swaps.additional_items.refundable", + "claims.additional_items.refundable", + "no_notification", +] as (keyof Order)[] + export class AdminListOrdersSelector { @IsString() @IsOptional()