chore(medusa,types): [6] Add request types to API routes (#8563)
* chore(medusa,types): [6] Add request types to API routes * more types
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import {
|
||||
BaseCreateCustomer,
|
||||
BaseCreateCustomerAddress,
|
||||
BaseCustomer,
|
||||
BaseCustomerAddress,
|
||||
BaseCustomerAddressFilters,
|
||||
BaseCustomerFilters,
|
||||
BaseCustomerGroup,
|
||||
BaseUpdateCustomer,
|
||||
BaseUpdateCustomerAddress,
|
||||
CustomerGroupInCustomerFilters,
|
||||
} from "./common"
|
||||
|
||||
export interface AdminCustomerGroup extends BaseCustomerGroup {}
|
||||
export interface AdminCustomer extends BaseCustomer {
|
||||
has_account: boolean
|
||||
groups?: AdminCustomerGroup[]
|
||||
}
|
||||
export interface AdminCustomerAddress extends BaseCustomerAddress {}
|
||||
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
||||
groups: CustomerGroupInCustomerFilters | string[] | string
|
||||
}
|
||||
export interface AdminCustomerAddressFilters
|
||||
extends BaseCustomerAddressFilters {}
|
||||
|
||||
export interface AdminCreateCustomer extends BaseCreateCustomer {}
|
||||
export interface AdminUpdateCustomer extends BaseUpdateCustomer {}
|
||||
|
||||
export interface AdminCreateCustomerAddress extends BaseCreateCustomerAddress {}
|
||||
export interface AdminUpdateCustomerAddress extends BaseUpdateCustomerAddress {}
|
||||
12
packages/core/types/src/http/customer/admin/entities.ts
Normal file
12
packages/core/types/src/http/customer/admin/entities.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
BaseCustomer,
|
||||
BaseCustomerAddress,
|
||||
BaseCustomerGroup,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminCustomerGroup extends BaseCustomerGroup {}
|
||||
export interface AdminCustomer extends BaseCustomer {
|
||||
has_account: boolean
|
||||
groups?: AdminCustomerGroup[]
|
||||
}
|
||||
export interface AdminCustomerAddress extends BaseCustomerAddress {}
|
||||
4
packages/core/types/src/http/customer/admin/index.ts
Normal file
4
packages/core/types/src/http/customer/admin/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
12
packages/core/types/src/http/customer/admin/payloads.ts
Normal file
12
packages/core/types/src/http/customer/admin/payloads.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
BaseCreateCustomer,
|
||||
BaseCreateCustomerAddress,
|
||||
BaseUpdateCustomer,
|
||||
BaseUpdateCustomerAddress,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminCreateCustomer extends BaseCreateCustomer {}
|
||||
export interface AdminUpdateCustomer extends BaseUpdateCustomer {}
|
||||
|
||||
export interface AdminCreateCustomerAddress extends BaseCreateCustomerAddress {}
|
||||
export interface AdminUpdateCustomerAddress extends BaseUpdateCustomerAddress {}
|
||||
11
packages/core/types/src/http/customer/admin/queries.ts
Normal file
11
packages/core/types/src/http/customer/admin/queries.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
BaseCustomerAddressFilters,
|
||||
BaseCustomerFilters,
|
||||
CustomerGroupInCustomerFilters,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
||||
groups: CustomerGroupInCustomerFilters | string[] | string
|
||||
}
|
||||
export interface AdminCustomerAddressFilters
|
||||
extends BaseCustomerAddressFilters {}
|
||||
24
packages/core/types/src/http/customer/admin/responses.ts
Normal file
24
packages/core/types/src/http/customer/admin/responses.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { AdminCustomer, AdminCustomerAddress, AdminCustomerGroup } from "./entities";
|
||||
|
||||
export interface AdminCustomerResponse {
|
||||
customer: AdminCustomer
|
||||
}
|
||||
|
||||
export type AdminCustomerListResponse = PaginatedResponse<{ customers: AdminCustomer }>
|
||||
|
||||
export interface AdminCustomerGroupResponse {
|
||||
customer_group: AdminCustomerGroup
|
||||
}
|
||||
|
||||
export type AdminCustomerGroupListResponse = PaginatedResponse<{
|
||||
customer_groups: AdminCustomerGroup[]
|
||||
}>
|
||||
|
||||
export interface AdminCustomerAddressResponse {
|
||||
address: AdminCustomerAddress
|
||||
}
|
||||
|
||||
export type AdminCustomerAddressListResponse = PaginatedResponse<{
|
||||
addresses: AdminCustomerAddress[]
|
||||
}>
|
||||
@@ -1,5 +1,5 @@
|
||||
import { batchLinkProductsToCollectionWorkflow } from "@medusajs/core-flows"
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
@@ -8,7 +8,7 @@ import { refetchCollection } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const { add = [], remove = [] } = req.validatedBody
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
|
||||
import { AdminUpdateCollectionType } from "../validators"
|
||||
import { refetchCollection } from "../helpers"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const collection = await refetchCollection(
|
||||
req.params.id,
|
||||
@@ -25,7 +26,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateCollectionType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
await updateCollectionsWorkflow(req.scope).run({
|
||||
input: {
|
||||
@@ -45,7 +46,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionDeleteResponse>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { AdminCreateCollectionType } from "./validators"
|
||||
import { refetchCollection } from "./helpers"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -38,7 +39,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateCollectionType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCollectionResponse>
|
||||
) => {
|
||||
const input = [
|
||||
{
|
||||
|
||||
@@ -4,8 +4,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminCurrencyResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const variables = { filters: { code: req.params.code } }
|
||||
|
||||
@@ -3,8 +3,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse<HttpTypes.AdminCurrencyListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
|
||||
@@ -4,12 +4,12 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
import { LinkMethodRequest } from "@medusajs/types"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||
import { refetchCustomerGroup } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerGroupResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
const { add, remove } = req.validatedBody
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { refetchCustomerGroup } from "../helpers"
|
||||
import { AdminUpdateCustomerGroupType } from "../validators"
|
||||
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerGroupResponse>
|
||||
) => {
|
||||
const customerGroup = await refetchCustomerGroup(
|
||||
req.params.id,
|
||||
@@ -33,7 +34,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateCustomerGroupType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerGroupResponse>
|
||||
) => {
|
||||
await updateCustomerGroupsWorkflow(req.scope).run({
|
||||
input: {
|
||||
@@ -52,7 +53,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"customer_group">>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const deleteCustomerGroups = deleteCustomerGroupsWorkflow(req.scope)
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { AdminCreateCustomerGroupType } from "./validators"
|
||||
import { refetchCustomerGroup } from "./helpers"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerGroupListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -37,7 +38,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateCustomerGroupType>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerGroupResponse>
|
||||
) => {
|
||||
const createGroups = createCustomerGroupsWorkflow(req.scope)
|
||||
const customersData = [
|
||||
|
||||
@@ -13,11 +13,11 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { AdminCreateCustomerAddressType } from "../../../validators"
|
||||
import { refetchCustomer } from "../../../helpers"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { AdditionalData, DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerAddressResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
@@ -37,7 +37,7 @@ export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminCreateCustomerAddressType & AdditionalData
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
|
||||
@@ -61,7 +61,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"customer_address">>
|
||||
) => {
|
||||
const id = req.params.address_id
|
||||
const deleteAddress = deleteCustomerAddressesWorkflow(req.scope)
|
||||
|
||||
@@ -9,11 +9,11 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { AdminCreateCustomerAddressType } from "../../validators"
|
||||
import { refetchCustomer } from "../../helpers"
|
||||
import { AdditionalData } from "@medusajs/types"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerAddressListResponse>
|
||||
) => {
|
||||
const customerId = req.params.id
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
@@ -41,7 +41,7 @@ export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
AdminCreateCustomerAddressType & AdditionalData
|
||||
>,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
const customerId = req.params.id
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
deleteCustomersWorkflow,
|
||||
updateCustomersWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { AdditionalData, AdminCustomer } from "@medusajs/types"
|
||||
import { AdditionalData, DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
@@ -13,7 +13,7 @@ import { AdminUpdateCustomerType } from "../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const customer = await refetchCustomer(
|
||||
req.params.id,
|
||||
@@ -33,7 +33,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminUpdateCustomerType & AdditionalData>,
|
||||
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
|
||||
@@ -55,7 +55,7 @@ export const POST = async (
|
||||
|
||||
export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
res: MedusaResponse<DeleteResponse<"customer">>
|
||||
) => {
|
||||
const id = req.params.id
|
||||
const deleteCustomers = deleteCustomersWorkflow(req.scope)
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { createCustomersWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
import {
|
||||
AdditionalData,
|
||||
AdminCustomer,
|
||||
PaginatedResponse,
|
||||
} from "@medusajs/types"
|
||||
import { AdditionalData, HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -18,7 +14,7 @@ import { AdminCreateCustomerType } from "./validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<PaginatedResponse<{ customers: AdminCustomer }>>
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerListResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
@@ -43,7 +39,7 @@ export const GET = async (
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminCreateCustomerType & AdditionalData>,
|
||||
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const { additional_data, ...rest } = req.validatedBody
|
||||
const createCustomers = createCustomersWorkflow(req.scope)
|
||||
|
||||
Reference in New Issue
Block a user