Feat(admin-ui, medusa): request return with location (#3451)
* add location_id to request_return endpoint to support "receive_now" returns * changeset * admin request return * add locations to recieving returns * cleanup test * add check for inventory service
This commit is contained in:
@@ -18,6 +18,8 @@ import { EntityManager } from "typeorm"
|
||||
import { Order, Return } from "../../../../models"
|
||||
import { OrdersReturnItem } from "../../../../types/orders"
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import { IInventoryService } from "../../../../interfaces"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/orders/{id}/return
|
||||
@@ -97,7 +99,7 @@ import { FindParams } from "../../../../types/common"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const value = req.validatedBody
|
||||
const value = req.validatedBody as AdminPostOrdersOrderReturnsReq
|
||||
|
||||
const idempotencyKeyService = req.scope.resolve("idempotencyKeyService")
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
@@ -121,6 +123,9 @@ export default async (req, res) => {
|
||||
|
||||
try {
|
||||
const orderService: OrderService = req.scope.resolve("orderService")
|
||||
const inventoryServiceEnabled =
|
||||
!!req.scope.resolve("inventoryService") &&
|
||||
!!req.scope.resolve("stockLocationService")
|
||||
const returnService: ReturnService = req.scope.resolve("returnService")
|
||||
const eventBus: EventBusService = req.scope.resolve("eventBusService")
|
||||
|
||||
@@ -140,6 +145,9 @@ export default async (req, res) => {
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
items: value.items,
|
||||
}
|
||||
if (isDefined(value.location_id) && inventoryServiceEnabled) {
|
||||
returnObj.location_id = value.location_id
|
||||
}
|
||||
|
||||
if (value.return_shipping) {
|
||||
returnObj.shipping_method = value.return_shipping
|
||||
@@ -284,6 +292,7 @@ type ReturnObj = {
|
||||
shipping_method?: ReturnShipping
|
||||
refund_amount?: number
|
||||
no_notification?: boolean
|
||||
location_id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,6 +372,10 @@ export class AdminPostOrdersOrderReturnsReq {
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
refund?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
location_id?: string
|
||||
}
|
||||
|
||||
class ReturnShipping {
|
||||
|
||||
Reference in New Issue
Block a user