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>
This commit is contained in:
6
.changeset/fair-melons-run.md
Normal file
6
.changeset/fair-melons-run.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/client-types": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat(oas): declare x-expanded-relations - Admin
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -149,6 +149,10 @@ export type AdminDeleteProductsFromCollectionRes = {
|
||||
/**
|
||||
* @schema AdminCollectionsRes
|
||||
* type: object
|
||||
* x-expanded-relations:
|
||||
* field: collection
|
||||
* relations:
|
||||
* - products
|
||||
* required:
|
||||
* - collection
|
||||
* properties:
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ export default (app) => {
|
||||
/**
|
||||
* @schema AdminCustomersRes
|
||||
* type: object
|
||||
* x-expanded-relations:
|
||||
* field: customer
|
||||
* relations:
|
||||
* - orders
|
||||
* - shipping_addresses
|
||||
* required:
|
||||
* - customer
|
||||
* properties:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 })
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -101,6 +101,79 @@ export type UpdateOrderInput = {
|
||||
payment_status?: PaymentStatus
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user