chore(medusa,types): [14/14] Add request types to API routes (#8576)
* chore(medusa,types): [14/14] Add request types to API routes * more types
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
import { BaseFile, BaseUploadFile } from "./common"
|
|
||||||
|
|
||||||
export interface AdminFile extends BaseFile {}
|
|
||||||
|
|
||||||
export type AdminUploadFile = BaseUploadFile
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseFile } from "../common"
|
||||||
|
|
||||||
|
export interface AdminFile extends BaseFile {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./payloads"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseUploadFile } from "../common";
|
||||||
|
|
||||||
|
export type AdminUploadFile = BaseUploadFile
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { AdminFile } from "./entities";
|
||||||
|
|
||||||
|
export interface AdminFileResponse {
|
||||||
|
file: AdminFile
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminFileListResponse {
|
||||||
|
files: AdminFile[]
|
||||||
|
}
|
||||||
@@ -36,3 +36,4 @@ export * from "./store"
|
|||||||
export * from "./tax-rate"
|
export * from "./tax-rate"
|
||||||
export * from "./tax-region"
|
export * from "./tax-region"
|
||||||
export * from "./user"
|
export * from "./user"
|
||||||
|
export * from "./workflow-execution"
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface AdminWorkflowExecution {
|
||||||
|
id: string
|
||||||
|
workflow_id: string
|
||||||
|
transaction_id: string
|
||||||
|
execution: string
|
||||||
|
context: string
|
||||||
|
state: any
|
||||||
|
created_at: Date
|
||||||
|
updated_at: Date
|
||||||
|
deleted_at: Date
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { PaginatedResponse } from "../../common/response";
|
||||||
|
import { AdminWorkflowExecution } from "./entities";
|
||||||
|
|
||||||
|
export interface AdminWorkflowExecutionResponse {
|
||||||
|
workflow_execution: AdminWorkflowExecution
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AdminWorkflowExecutionListResponse = PaginatedResponse<{
|
||||||
|
workflow_executions: AdminWorkflowExecution[]
|
||||||
|
}>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./admin"
|
||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../types/routing"
|
} from "../../../../types/routing"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminTaxRegionResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminTaxRegionDeleteResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ import {
|
|||||||
AdminGetTaxRegionsParamsType,
|
AdminGetTaxRegionsParamsType,
|
||||||
} from "./validators"
|
} from "./validators"
|
||||||
import { refetchTaxRegion } from "./helpers"
|
import { refetchTaxRegion } from "./helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateTaxRegionType>,
|
req: AuthenticatedMedusaRequest<AdminCreateTaxRegionType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminTaxRegionResponse>
|
||||||
) => {
|
) => {
|
||||||
const { result } = await createTaxRegionsWorkflow(req.scope).run({
|
const { result } = await createTaxRegionsWorkflow(req.scope).run({
|
||||||
input: [
|
input: [
|
||||||
@@ -36,7 +37,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetTaxRegionsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetTaxRegionsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminTaxRegionListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../types/routing"
|
} from "../../../../types/routing"
|
||||||
import { deleteFilesWorkflow } from "@medusajs/core-flows"
|
import { deleteFilesWorkflow } from "@medusajs/core-flows"
|
||||||
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFileResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const variables = { id: req.params.id }
|
const variables = { id: req.params.id }
|
||||||
@@ -32,7 +33,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"file">>
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { AdminGetUploadParamsType } from "./validators"
|
import { AdminGetUploadParamsType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetUploadParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetUploadParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminFileListResponse>
|
||||||
) => {
|
) => {
|
||||||
const input = req.files as Express.Multer.File[]
|
const input = req.files as Express.Multer.File[]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { deleteUsersWorkflow, updateUsersWorkflow } from "@medusajs/core-flows"
|
import { deleteUsersWorkflow, updateUsersWorkflow } from "@medusajs/core-flows"
|
||||||
import { UpdateUserDTO } from "@medusajs/types"
|
import { HttpTypes, UpdateUserDTO } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -16,7 +16,7 @@ import { refetchUser } from "../helpers"
|
|||||||
// Get user
|
// Get user
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
@@ -41,7 +41,7 @@ export const GET = async (
|
|||||||
// update user
|
// update user
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminUpdateUserType>,
|
req: AuthenticatedMedusaRequest<AdminUpdateUserType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserResponse>
|
||||||
) => {
|
) => {
|
||||||
const workflow = updateUsersWorkflow(req.scope)
|
const workflow = updateUsersWorkflow(req.scope)
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ export const POST = async (
|
|||||||
// delete user
|
// delete user
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserDeleteResponse>
|
||||||
) => {
|
) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
const workflow = deleteUsersWorkflow(req.scope)
|
const workflow = deleteUsersWorkflow(req.scope)
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import {
|
|||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "../../../../types/routing"
|
} from "../../../../types/routing"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.auth_context.actor_id
|
const id = req.auth_context.actor_id
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createUserAccountWorkflow } from "@medusajs/core-flows"
|
import { createUserAccountWorkflow } from "@medusajs/core-flows"
|
||||||
import { CreateUserDTO } from "@medusajs/types"
|
import { CreateUserDTO, HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
@@ -13,7 +13,7 @@ import { refetchUser } from "./helpers"
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<CreateUserDTO>,
|
req: AuthenticatedMedusaRequest<CreateUserDTO>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminUserResponse>
|
||||||
) => {
|
) => {
|
||||||
// If `actor_id` is present, the request carries authentication for an existing user
|
// If `actor_id` is present, the request carries authentication for an existing user
|
||||||
if (req.auth_context.actor_id) {
|
if (req.auth_context.actor_id) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -11,7 +12,7 @@ import {
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionDetailsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionDetailsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminWorkflowExecutionResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
const variables = { id: req.params.id }
|
const variables = { id: req.params.id }
|
||||||
|
|||||||
+2
-1
@@ -8,10 +8,11 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { AdminGetWorkflowExecutionDetailsParamsType } from "../../validators"
|
import { AdminGetWorkflowExecutionDetailsParamsType } from "../../validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionDetailsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionDetailsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminWorkflowExecutionResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { AdminCreateWorkflowsRunType } from "../../validators"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsRunType>,
|
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsRunType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{ acknowledgement: object }>
|
||||||
) => {
|
) => {
|
||||||
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
||||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsAsyncResponseType>,
|
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsAsyncResponseType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{ success: boolean }>
|
||||||
) => {
|
) => {
|
||||||
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
||||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators"
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsAsyncResponseType>,
|
req: AuthenticatedMedusaRequest<AdminCreateWorkflowsAsyncResponseType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<{ success: boolean }>
|
||||||
) => {
|
) => {
|
||||||
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
const workflowEngineService: IWorkflowEngineService = req.scope.resolve(
|
||||||
ModuleRegistrationName.WORKFLOW_ENGINE
|
ModuleRegistrationName.WORKFLOW_ENGINE
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -11,7 +12,7 @@ import {
|
|||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionsParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetWorkflowExecutionsParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.AdminWorkflowExecutionListResponse>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user