chore(medusa,types): [8] Add request types to API routes (#8565)

This commit is contained in:
Shahed Nasser
2024-08-13 10:10:10 +03:00
committed by GitHub
parent 571a3d1671
commit fc439a32f1
20 changed files with 84 additions and 43 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -0,0 +1,3 @@
export * from "./entities"
export * from "./payloads"
export * from "./responses"

View File

@@ -0,0 +1,9 @@
export type AdminAcceptInvite = {
first_name: string
last_name: string
}
export type AdminCreateInvite = {
email: string
metadata?: Record<string, unknown>
}

View File

@@ -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
}

View File

@@ -7,10 +7,11 @@ import {
MedusaResponse,
} from "../../../types/routing"
import { AdminFulfillmentProvidersParamsType } from "./validators"
import { HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<AdminFulfillmentProvidersParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminFulfillmentProviderListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const queryObject = remoteQueryObjectFromString({

View File

@@ -5,6 +5,7 @@ import {
import {
AdminFulfillmentSetResponse,
AdminServiceZoneResponse,
DeleteResponse,
IFulfillmentModuleService,
} from "@medusajs/types"
import {
@@ -93,7 +94,7 @@ export const POST = async (
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
res: MedusaResponse<DeleteResponse<"service_zone">>
) => {
const { id, zone_id } = req.params

View File

@@ -2,10 +2,11 @@ import { createServiceZonesWorkflow } from "@medusajs/core-flows"
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
import { AdminCreateFulfillmentSetServiceZonesType } from "../../validators"
import { refetchFulfillmentSet } from "../../helpers"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: MedusaRequest<AdminCreateFulfillmentSetServiceZonesType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminFulfillmentSetResponse>
) => {
const workflowInput = {
data: [

View File

@@ -5,10 +5,11 @@ import {
} from "../../../../../types/routing"
import { refetchFulfillment } from "../../helpers"
import { AdminCancelFulfillmentType } from "../../validators"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCancelFulfillmentType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
) => {
const { id } = req.params
await cancelFulfillmentWorkflow(req.scope).run({

View File

@@ -5,10 +5,11 @@ import {
} from "../../../../../types/routing"
import { refetchFulfillment } from "../../helpers"
import { AdminCreateShipmentType } from "../../validators"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateShipmentType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
) => {
const { id } = req.params

View File

@@ -5,10 +5,11 @@ import {
} from "../../../types/routing"
import { refetchFulfillment } from "./helpers"
import { AdminCreateFulfillmentType } from "./validators"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateFulfillmentType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminFulfillmentResponse>
) => {
const { result: fullfillment } = await createFulfillmentWorkflow(
req.scope

View File

@@ -11,8 +11,12 @@ import {
} from "@medusajs/core-flows"
import { refetchInventoryItem } from "../../../helpers"
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 remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
@@ -61,7 +65,7 @@ export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
export const POST = async (
req: MedusaRequest<AdminUpdateInventoryLocationLevelType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
) => {
const { id, location_id } = req.params
await updateInventoryLevelsWorkflow(req.scope).run({

View File

@@ -14,7 +14,7 @@ export const POST = async (
AdminUpdateInventoryLocationLevelType
>
>,
res: MedusaResponse
res: MedusaResponse<{ inventory_item: {} }>
) => {
const { id } = req.params

View File

@@ -10,10 +10,11 @@ import {
AdminGetInventoryLocationLevelsParamsType,
} from "../../validators"
import { refetchInventoryItem } from "../../helpers"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: MedusaRequest<AdminCreateInventoryLocationLevelType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
) => {
const { id } = req.params
@@ -39,7 +40,7 @@ export const POST = async (
export const GET = async (
req: MedusaRequest<AdminGetInventoryLocationLevelsParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryLevelListResponse>
) => {
const { id } = req.params

View File

@@ -9,10 +9,11 @@ import {
AdminUpdateInventoryItemType,
} from "../validators"
import { refetchInventoryItem } from "../helpers"
import { DeleteResponse, HttpTypes } from "@medusajs/types"
export const GET = async (
req: MedusaRequest<AdminGetInventoryItemParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
) => {
const { id } = req.params
const inventoryItem = await refetchInventoryItem(
@@ -35,7 +36,7 @@ export const GET = async (
// Update inventory item
export const POST = async (
req: MedusaRequest<AdminUpdateInventoryItemType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
) => {
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 deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)

View File

@@ -13,10 +13,11 @@ import {
AdminGetInventoryItemsParamsType,
} from "./validators"
import { refetchInventoryItem } from "./helpers"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateInventoryItemType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemResponse>
) => {
const { result } = await createInventoryItemsWorkflow(req.scope).run({
input: { items: [req.validatedBody] },
@@ -33,7 +34,7 @@ export const POST = async (
export const GET = async (
req: AuthenticatedMedusaRequest<AdminGetInventoryItemsParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInventoryItemListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

View File

@@ -2,8 +2,12 @@ import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
import { refreshInviteTokensWorkflow } from "@medusajs/core-flows"
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 input = {

View File

@@ -6,10 +6,11 @@ import { MedusaError } from "@medusajs/utils"
import { deleteInvitesWorkflow } from "@medusajs/core-flows"
import { refetchInvite } from "../helpers"
import { DeleteResponse, HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInviteResponse>
) => {
const { id } = req.params
const invite = await refetchInvite(
@@ -30,7 +31,7 @@ export const GET = async (
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
res: MedusaResponse<DeleteResponse<"invite">>
) => {
const { id } = req.params
const workflow = deleteInvitesWorkflow(req.scope)

View File

@@ -1,5 +1,5 @@
import { acceptInviteWorkflow } from "@medusajs/core-flows"
import { InviteWorkflow } from "@medusajs/types"
import { HttpTypes, InviteWorkflow } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
@@ -9,7 +9,7 @@ import { AdminInviteAcceptType } from "../validators"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminInviteAcceptType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminAcceptInviteResponse>
) => {
if (req.auth_context.actor_id) {
throw new MedusaError(

View File

@@ -10,10 +10,11 @@ import {
import { createInvitesWorkflow } from "@medusajs/core-flows"
import { AdminCreateInviteType, AdminGetInvitesParamsType } from "./validators"
import { refetchInvite } from "./helpers"
import { HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<AdminGetInvitesParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInviteListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const queryObject = remoteQueryObjectFromString({
@@ -37,7 +38,7 @@ export const GET = async (
export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateInviteType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.AdminInviteResponse>
) => {
const workflow = createInvitesWorkflow(req.scope)