chore(medusa): return endpoints (#7823)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { linkSalesChannelsToApiKeyWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { ApiKeyType, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { refetchApiKey } from "../../helpers"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { linkSalesChannelsToApiKeyWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { batchLinkProductsToCollectionWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchCollection } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchCustomerGroup } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { batchPriceListPricesWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { fetchPriceList, fetchPriceListPriceIdsForProduct } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
|
||||
@@ -1,35 +1,20 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { receiveReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { AdminPostReceiveReturnsReqSchemaType } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<AdminPostReceiveReturnsReqSchemaType>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const input = req.validatedBody as AdminPostReceiveReturnsReqSchemaType
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
const workflow = receiveReturnOrderWorkflow(req.scope)
|
||||
const { result } = await workflow.run({
|
||||
input,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
})
|
||||
res.status(200).json({ return: result })
|
||||
}
|
||||
|
||||
@@ -19,17 +19,13 @@ export const GET = async (
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
},
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
const [orderReturn] = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
return: orderReturn,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {createReturnOrderWorkflow} from "@medusajs/core-flows"
|
||||
import { createReturnOrderWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../types/routing"
|
||||
import {AdminPostReturnsReqSchemaType} from "./validators"
|
||||
import { AdminPostReturnsReqSchemaType } from "./validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
@@ -16,7 +16,7 @@ export const GET = async (
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "order",
|
||||
entryPoint: "returns",
|
||||
variables: {
|
||||
filters: {
|
||||
...req.filterableFields,
|
||||
@@ -26,10 +26,10 @@ export const GET = async (
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const { rows: orders, metadata } = await remoteQuery(queryObject)
|
||||
const { rows: returns, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
orders,
|
||||
returns,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
|
||||
@@ -53,7 +53,7 @@ export const AdminPostReturnsReqSchema = z.object({
|
||||
order_id: z.string(),
|
||||
items: z.array(ItemSchema),
|
||||
return_shipping: ReturnShippingSchema,
|
||||
note: z.string().nullish(),
|
||||
internal_note: z.string().nullish(),
|
||||
receive_now: z.boolean().optional(),
|
||||
refund_amount: z.number().optional(),
|
||||
location_id: z.string().nullish(),
|
||||
@@ -61,3 +61,12 @@ export const AdminPostReturnsReqSchema = z.object({
|
||||
export type AdminPostReturnsReqSchemaType = z.infer<
|
||||
typeof AdminPostReturnsReqSchema
|
||||
>
|
||||
|
||||
export const AdminPostReceiveReturnsReqSchema = z.object({
|
||||
return_id: z.string(),
|
||||
items: z.array(ItemSchema),
|
||||
internal_note: z.string().nullish(),
|
||||
})
|
||||
export type AdminPostReceiveReturnsReqSchemaType = z.infer<
|
||||
typeof AdminPostReceiveReturnsReqSchema
|
||||
>
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchSalesChannel } from "../../helpers"
|
||||
import { linkProductsToSalesChannelWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchSalesChannel } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types/src"
|
||||
import { refetchStockLocation } from "../../helpers"
|
||||
import { linkSalesChannelsToStockLocationWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchStockLocation } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
|
||||
Reference in New Issue
Block a user