From 6d210c67b13fbb134a9c3146140183ed64bca8f5 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 13 Aug 2024 09:37:36 +0300 Subject: [PATCH] chore(medusa,types): [6] Add request types to API routes (#8563) * chore(medusa,types): [6] Add request types to API routes * more types --- .../core/types/src/http/customer/admin.ts | 30 ------------------- .../types/src/http/customer/admin/entities.ts | 12 ++++++++ .../types/src/http/customer/admin/index.ts | 4 +++ .../types/src/http/customer/admin/payloads.ts | 12 ++++++++ .../types/src/http/customer/admin/queries.ts | 11 +++++++ .../src/http/customer/admin/responses.ts | 24 +++++++++++++++ .../admin/collections/[id]/products/route.ts | 4 +-- .../src/api/admin/collections/[id]/route.ts | 7 +++-- .../medusa/src/api/admin/collections/route.ts | 5 ++-- .../src/api/admin/currencies/[code]/route.ts | 6 +++- .../medusa/src/api/admin/currencies/route.ts | 6 +++- .../customer-groups/[id]/customers/route.ts | 4 +-- .../api/admin/customer-groups/[id]/route.ts | 7 +++-- .../src/api/admin/customer-groups/route.ts | 5 ++-- .../[id]/addresses/[address_id]/route.ts | 8 ++--- .../admin/customers/[id]/addresses/route.ts | 6 ++-- .../src/api/admin/customers/[id]/route.ts | 8 ++--- .../medusa/src/api/admin/customers/route.ts | 10 ++----- 18 files changed, 105 insertions(+), 64 deletions(-) delete mode 100644 packages/core/types/src/http/customer/admin.ts create mode 100644 packages/core/types/src/http/customer/admin/entities.ts create mode 100644 packages/core/types/src/http/customer/admin/index.ts create mode 100644 packages/core/types/src/http/customer/admin/payloads.ts create mode 100644 packages/core/types/src/http/customer/admin/queries.ts create mode 100644 packages/core/types/src/http/customer/admin/responses.ts diff --git a/packages/core/types/src/http/customer/admin.ts b/packages/core/types/src/http/customer/admin.ts deleted file mode 100644 index 68c83bbd2e..0000000000 --- a/packages/core/types/src/http/customer/admin.ts +++ /dev/null @@ -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 {} diff --git a/packages/core/types/src/http/customer/admin/entities.ts b/packages/core/types/src/http/customer/admin/entities.ts new file mode 100644 index 0000000000..e1019d470b --- /dev/null +++ b/packages/core/types/src/http/customer/admin/entities.ts @@ -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 {} \ No newline at end of file diff --git a/packages/core/types/src/http/customer/admin/index.ts b/packages/core/types/src/http/customer/admin/index.ts new file mode 100644 index 0000000000..2f1b9df166 --- /dev/null +++ b/packages/core/types/src/http/customer/admin/index.ts @@ -0,0 +1,4 @@ +export * from "./entities" +export * from "./payloads" +export * from "./queries" +export * from "./responses" \ No newline at end of file diff --git a/packages/core/types/src/http/customer/admin/payloads.ts b/packages/core/types/src/http/customer/admin/payloads.ts new file mode 100644 index 0000000000..76842515f2 --- /dev/null +++ b/packages/core/types/src/http/customer/admin/payloads.ts @@ -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 {} diff --git a/packages/core/types/src/http/customer/admin/queries.ts b/packages/core/types/src/http/customer/admin/queries.ts new file mode 100644 index 0000000000..62d4001d3b --- /dev/null +++ b/packages/core/types/src/http/customer/admin/queries.ts @@ -0,0 +1,11 @@ +import { + BaseCustomerAddressFilters, + BaseCustomerFilters, + CustomerGroupInCustomerFilters, +} from "../common" + +export interface AdminCustomerFilters extends BaseCustomerFilters { + groups: CustomerGroupInCustomerFilters | string[] | string +} +export interface AdminCustomerAddressFilters + extends BaseCustomerAddressFilters {} diff --git a/packages/core/types/src/http/customer/admin/responses.ts b/packages/core/types/src/http/customer/admin/responses.ts new file mode 100644 index 0000000000..5a55d30d97 --- /dev/null +++ b/packages/core/types/src/http/customer/admin/responses.ts @@ -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[] +}> \ No newline at end of file diff --git a/packages/medusa/src/api/admin/collections/[id]/products/route.ts b/packages/medusa/src/api/admin/collections/[id]/products/route.ts index ebc3486745..d8fc15ea84 100644 --- a/packages/medusa/src/api/admin/collections/[id]/products/route.ts +++ b/packages/medusa/src/api/admin/collections/[id]/products/route.ts @@ -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, - res: MedusaResponse + res: MedusaResponse ) => { const id = req.params.id const { add = [], remove = [] } = req.validatedBody diff --git a/packages/medusa/src/api/admin/collections/[id]/route.ts b/packages/medusa/src/api/admin/collections/[id]/route.ts index 5cbbd3a430..2f8fa8bf4c 100644 --- a/packages/medusa/src/api/admin/collections/[id]/route.ts +++ b/packages/medusa/src/api/admin/collections/[id]/route.ts @@ -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 ) => { const collection = await refetchCollection( req.params.id, @@ -25,7 +26,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse ) => { await updateCollectionsWorkflow(req.scope).run({ input: { @@ -45,7 +46,7 @@ export const POST = async ( export const DELETE = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse ) => { const id = req.params.id diff --git a/packages/medusa/src/api/admin/collections/route.ts b/packages/medusa/src/api/admin/collections/route.ts index fd4a26f900..c9bf12f1b4 100644 --- a/packages/medusa/src/api/admin/collections/route.ts +++ b/packages/medusa/src/api/admin/collections/route.ts @@ -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 ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) @@ -38,7 +39,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse ) => { const input = [ { diff --git a/packages/medusa/src/api/admin/currencies/[code]/route.ts b/packages/medusa/src/api/admin/currencies/[code]/route.ts index 29e4d9dde9..e7df69df34 100644 --- a/packages/medusa/src/api/admin/currencies/[code]/route.ts +++ b/packages/medusa/src/api/admin/currencies/[code]/route.ts @@ -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 +) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) const variables = { filters: { code: req.params.code } } diff --git a/packages/medusa/src/api/admin/currencies/route.ts b/packages/medusa/src/api/admin/currencies/route.ts index 51947a58da..4bc34c614f 100644 --- a/packages/medusa/src/api/admin/currencies/route.ts +++ b/packages/medusa/src/api/admin/currencies/route.ts @@ -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 +) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) const queryObject = remoteQueryObjectFromString({ diff --git a/packages/medusa/src/api/admin/customer-groups/[id]/customers/route.ts b/packages/medusa/src/api/admin/customer-groups/[id]/customers/route.ts index 8200f47b5e..17f02e1b31 100644 --- a/packages/medusa/src/api/admin/customer-groups/[id]/customers/route.ts +++ b/packages/medusa/src/api/admin/customer-groups/[id]/customers/route.ts @@ -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, - res: MedusaResponse + res: MedusaResponse ) => { const { id } = req.params const { add, remove } = req.validatedBody diff --git a/packages/medusa/src/api/admin/customer-groups/[id]/route.ts b/packages/medusa/src/api/admin/customer-groups/[id]/route.ts index ff8e20a737..48857c1abd 100644 --- a/packages/medusa/src/api/admin/customer-groups/[id]/route.ts +++ b/packages/medusa/src/api/admin/customer-groups/[id]/route.ts @@ -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 ) => { const customerGroup = await refetchCustomerGroup( req.params.id, @@ -33,7 +34,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse ) => { await updateCustomerGroupsWorkflow(req.scope).run({ input: { @@ -52,7 +53,7 @@ export const POST = async ( export const DELETE = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse> ) => { const id = req.params.id const deleteCustomerGroups = deleteCustomerGroupsWorkflow(req.scope) diff --git a/packages/medusa/src/api/admin/customer-groups/route.ts b/packages/medusa/src/api/admin/customer-groups/route.ts index 2cc21efbb0..e691878375 100644 --- a/packages/medusa/src/api/admin/customer-groups/route.ts +++ b/packages/medusa/src/api/admin/customer-groups/route.ts @@ -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 ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) @@ -37,7 +38,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse ) => { const createGroups = createCustomerGroupsWorkflow(req.scope) const customersData = [ diff --git a/packages/medusa/src/api/admin/customers/[id]/addresses/[address_id]/route.ts b/packages/medusa/src/api/admin/customers/[id]/addresses/[address_id]/route.ts index 6b5d9fab88..746d75b45a 100644 --- a/packages/medusa/src/api/admin/customers/[id]/addresses/[address_id]/route.ts +++ b/packages/medusa/src/api/admin/customers/[id]/addresses/[address_id]/route.ts @@ -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 ) => { 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 ) => { const { additional_data, ...rest } = req.validatedBody @@ -61,7 +61,7 @@ export const POST = async ( export const DELETE = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse> ) => { const id = req.params.address_id const deleteAddress = deleteCustomerAddressesWorkflow(req.scope) diff --git a/packages/medusa/src/api/admin/customers/[id]/addresses/route.ts b/packages/medusa/src/api/admin/customers/[id]/addresses/route.ts index 63d995d866..c7fbf4d8a3 100644 --- a/packages/medusa/src/api/admin/customers/[id]/addresses/route.ts +++ b/packages/medusa/src/api/admin/customers/[id]/addresses/route.ts @@ -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 ) => { 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 ) => { const { additional_data, ...rest } = req.validatedBody const customerId = req.params.id diff --git a/packages/medusa/src/api/admin/customers/[id]/route.ts b/packages/medusa/src/api/admin/customers/[id]/route.ts index 40579c8452..6309b61f73 100644 --- a/packages/medusa/src/api/admin/customers/[id]/route.ts +++ b/packages/medusa/src/api/admin/customers/[id]/route.ts @@ -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 ) => { const customer = await refetchCustomer( req.params.id, @@ -33,7 +33,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse<{ customer: AdminCustomer }> + res: MedusaResponse ) => { const { additional_data, ...rest } = req.validatedBody @@ -55,7 +55,7 @@ export const POST = async ( export const DELETE = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse + res: MedusaResponse> ) => { const id = req.params.id const deleteCustomers = deleteCustomersWorkflow(req.scope) diff --git a/packages/medusa/src/api/admin/customers/route.ts b/packages/medusa/src/api/admin/customers/route.ts index 8aec2cc9f3..84e32b1a45 100644 --- a/packages/medusa/src/api/admin/customers/route.ts +++ b/packages/medusa/src/api/admin/customers/route.ts @@ -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> + res: MedusaResponse ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) @@ -43,7 +39,7 @@ export const GET = async ( export const POST = async ( req: AuthenticatedMedusaRequest, - res: MedusaResponse<{ customer: AdminCustomer }> + res: MedusaResponse ) => { const { additional_data, ...rest } = req.validatedBody const createCustomers = createCustomersWorkflow(req.scope)