chore(medusa,types): [8] Add request types to API routes (#8565)
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
export type AdminAcceptInvite = {
|
|
||||||
first_name: string
|
|
||||||
last_name: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AdminCreateInvite = {
|
|
||||||
email: string
|
|
||||||
metadata?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AdminInviteResponse = {
|
|
||||||
id: string
|
|
||||||
email: string
|
|
||||||
accepted: boolean
|
|
||||||
token: string
|
|
||||||
expires_at?: Date
|
|
||||||
metadata?: Record<string, unknown>
|
|
||||||
created_at?: Date
|
|
||||||
updated_at?: Date
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export interface AdminInvite {
|
||||||
|
id: string
|
||||||
|
email: string
|
||||||
|
accepted: boolean
|
||||||
|
token: string
|
||||||
|
expires_at?: Date
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
created_at?: Date
|
||||||
|
updated_at?: Date
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./payloads"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export type AdminAcceptInvite = {
|
||||||
|
first_name: string
|
||||||
|
last_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AdminCreateInvite = {
|
||||||
|
email: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { AdminUser } from "../../user";
|
||||||
|
import { AdminInvite } from "./entities";
|
||||||
|
|
||||||
|
export interface AdminInviteResponse {
|
||||||
|
invite: AdminInvite
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AdminInviteListResponse = PaginatedResponse<{
|
||||||
|
invites: AdminInvite[]
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type AdminAcceptInviteResponse = {
|
||||||
|
user: AdminUser
|
||||||
|
} | {
|
||||||
|
message: string
|
||||||
|
}
|
||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { AdminFulfillmentProvidersParamsType } from "./validators"
|
import { AdminFulfillmentProvidersParamsType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminFulfillmentProvidersParamsType>,
|
req: AuthenticatedMedusaRequest<AdminFulfillmentProvidersParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFulfillmentProviderListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
|||||||
+2
-1
@@ -5,6 +5,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
AdminFulfillmentSetResponse,
|
AdminFulfillmentSetResponse,
|
||||||
AdminServiceZoneResponse,
|
AdminServiceZoneResponse,
|
||||||
|
DeleteResponse,
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
@@ -93,7 +94,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"service_zone">>
|
||||||
) => {
|
) => {
|
||||||
const { id, zone_id } = req.params
|
const { id, zone_id } = req.params
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { createServiceZonesWorkflow } from "@medusajs/core-flows"
|
|||||||
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
||||||
import { AdminCreateFulfillmentSetServiceZonesType } from "../../validators"
|
import { AdminCreateFulfillmentSetServiceZonesType } from "../../validators"
|
||||||
import { refetchFulfillmentSet } from "../../helpers"
|
import { refetchFulfillmentSet } from "../../helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<AdminCreateFulfillmentSetServiceZonesType>,
|
req: MedusaRequest<AdminCreateFulfillmentSetServiceZonesType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFulfillmentSetResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflowInput = {
|
const workflowInput = {
|
||||||
data: [
|
data: [
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
} from "../../../../../types/routing"
|
} from "../../../../../types/routing"
|
||||||
import { refetchFulfillment } from "../../helpers"
|
import { refetchFulfillment } from "../../helpers"
|
||||||
import { AdminCancelFulfillmentType } from "../../validators"
|
import { AdminCancelFulfillmentType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCancelFulfillmentType>,
|
req: AuthenticatedMedusaRequest<AdminCancelFulfillmentType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
await cancelFulfillmentWorkflow(req.scope).run({
|
await cancelFulfillmentWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
} from "../../../../../types/routing"
|
} from "../../../../../types/routing"
|
||||||
import { refetchFulfillment } from "../../helpers"
|
import { refetchFulfillment } from "../../helpers"
|
||||||
import { AdminCreateShipmentType } from "../../validators"
|
import { AdminCreateShipmentType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateShipmentType>,
|
req: AuthenticatedMedusaRequest<AdminCreateShipmentType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { refetchFulfillment } from "./helpers"
|
import { refetchFulfillment } from "./helpers"
|
||||||
import { AdminCreateFulfillmentType } from "./validators"
|
import { AdminCreateFulfillmentType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateFulfillmentType>,
|
req: AuthenticatedMedusaRequest<AdminCreateFulfillmentType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
|
||||||
) => {
|
) => {
|
||||||
const { result: fullfillment } = await createFulfillmentWorkflow(
|
const { result: fullfillment } = await createFulfillmentWorkflow(
|
||||||
req.scope
|
req.scope
|
||||||
|
|||||||
+6
-2
@@ -11,8 +11,12 @@ import {
|
|||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { refetchInventoryItem } from "../../../helpers"
|
import { refetchInventoryItem } from "../../../helpers"
|
||||||
import { AdminUpdateInventoryLocationLevelType } from "../../../validators"
|
import { AdminUpdateInventoryLocationLevelType } from "../../../validators"
|
||||||
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const DELETE = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<DeleteResponse<"inventory-level">>
|
||||||
|
) => {
|
||||||
const { id, location_id } = req.params
|
const { id, location_id } = req.params
|
||||||
|
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
@@ -61,7 +65,7 @@ export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<AdminUpdateInventoryLocationLevelType>,
|
req: MedusaRequest<AdminUpdateInventoryLocationLevelType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id, location_id } = req.params
|
const { id, location_id } = req.params
|
||||||
await updateInventoryLevelsWorkflow(req.scope).run({
|
await updateInventoryLevelsWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const POST = async (
|
|||||||
AdminUpdateInventoryLocationLevelType
|
AdminUpdateInventoryLocationLevelType
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{ inventory_item: {} }>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import {
|
|||||||
AdminGetInventoryLocationLevelsParamsType,
|
AdminGetInventoryLocationLevelsParamsType,
|
||||||
} from "../../validators"
|
} from "../../validators"
|
||||||
import { refetchInventoryItem } from "../../helpers"
|
import { refetchInventoryItem } from "../../helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<AdminCreateInventoryLocationLevelType>,
|
req: MedusaRequest<AdminCreateInventoryLocationLevelType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<AdminGetInventoryLocationLevelsParamsType>,
|
req: MedusaRequest<AdminGetInventoryLocationLevelsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryLevelListResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import {
|
|||||||
AdminUpdateInventoryItemType,
|
AdminUpdateInventoryItemType,
|
||||||
} from "../validators"
|
} from "../validators"
|
||||||
import { refetchInventoryItem } from "../helpers"
|
import { refetchInventoryItem } from "../helpers"
|
||||||
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<AdminGetInventoryItemParamsType>,
|
req: MedusaRequest<AdminGetInventoryItemParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const inventoryItem = await refetchInventoryItem(
|
const inventoryItem = await refetchInventoryItem(
|
||||||
@@ -35,7 +36,7 @@ export const GET = async (
|
|||||||
// Update inventory item
|
// Update inventory item
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<AdminUpdateInventoryItemType>,
|
req: MedusaRequest<AdminUpdateInventoryItemType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
@@ -56,7 +57,10 @@ export const POST = async (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const DELETE = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<DeleteResponse<"inventory_item">>
|
||||||
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)
|
const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ import {
|
|||||||
AdminGetInventoryItemsParamsType,
|
AdminGetInventoryItemsParamsType,
|
||||||
} from "./validators"
|
} from "./validators"
|
||||||
import { refetchInventoryItem } from "./helpers"
|
import { refetchInventoryItem } from "./helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateInventoryItemType>,
|
req: AuthenticatedMedusaRequest<AdminCreateInventoryItemType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
|
||||||
) => {
|
) => {
|
||||||
const { result } = await createInventoryItemsWorkflow(req.scope).run({
|
const { result } = await createInventoryItemsWorkflow(req.scope).run({
|
||||||
input: { items: [req.validatedBody] },
|
input: { items: [req.validatedBody] },
|
||||||
@@ -33,7 +34,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetInventoryItemsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetInventoryItemsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInventoryItemListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
|
|||||||
|
|
||||||
import { refreshInviteTokensWorkflow } from "@medusajs/core-flows"
|
import { refreshInviteTokensWorkflow } from "@medusajs/core-flows"
|
||||||
import { refetchInvite } from "../../helpers"
|
import { refetchInvite } from "../../helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const POST = async (
|
||||||
|
req: MedusaRequest,
|
||||||
|
res: MedusaResponse<HttpTypes.AdminInviteResponse>
|
||||||
|
) => {
|
||||||
const workflow = refreshInviteTokensWorkflow(req.scope)
|
const workflow = refreshInviteTokensWorkflow(req.scope)
|
||||||
|
|
||||||
const input = {
|
const input = {
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import { MedusaError } from "@medusajs/utils"
|
|||||||
|
|
||||||
import { deleteInvitesWorkflow } from "@medusajs/core-flows"
|
import { deleteInvitesWorkflow } from "@medusajs/core-flows"
|
||||||
import { refetchInvite } from "../helpers"
|
import { refetchInvite } from "../helpers"
|
||||||
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInviteResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const invite = await refetchInvite(
|
const invite = await refetchInvite(
|
||||||
@@ -30,7 +31,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"invite">>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const workflow = deleteInvitesWorkflow(req.scope)
|
const workflow = deleteInvitesWorkflow(req.scope)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { acceptInviteWorkflow } from "@medusajs/core-flows"
|
import { acceptInviteWorkflow } from "@medusajs/core-flows"
|
||||||
import { InviteWorkflow } from "@medusajs/types"
|
import { HttpTypes, InviteWorkflow } from "@medusajs/types"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
@@ -9,7 +9,7 @@ import { AdminInviteAcceptType } from "../validators"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminInviteAcceptType>,
|
req: AuthenticatedMedusaRequest<AdminInviteAcceptType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminAcceptInviteResponse>
|
||||||
) => {
|
) => {
|
||||||
if (req.auth_context.actor_id) {
|
if (req.auth_context.actor_id) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import {
|
|||||||
import { createInvitesWorkflow } from "@medusajs/core-flows"
|
import { createInvitesWorkflow } from "@medusajs/core-flows"
|
||||||
import { AdminCreateInviteType, AdminGetInvitesParamsType } from "./validators"
|
import { AdminCreateInviteType, AdminGetInvitesParamsType } from "./validators"
|
||||||
import { refetchInvite } from "./helpers"
|
import { refetchInvite } from "./helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetInvitesParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetInvitesParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInviteListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
@@ -37,7 +38,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateInviteType>,
|
req: AuthenticatedMedusaRequest<AdminCreateInviteType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminInviteResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflow = createInvitesWorkflow(req.scope)
|
const workflow = createInvitesWorkflow(req.scope)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user