chore(medusa,types): [2] Add request types to API routes (#8559)

* chore(medusa,types): [2] Add request types to API routes

* fix up base currency
This commit is contained in:
Shahed Nasser
2024-08-13 09:36:41 +03:00
committed by GitHub
parent 96bdf3e2c6
commit e5e8489cc0
17 changed files with 87 additions and 34 deletions

View File

@@ -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.StoreCurrencyResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const variables = { filters: { code: req.params.code } }

View File

@@ -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.StoreCurrencyListResponse>
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const queryObject = remoteQueryObjectFromString({

View File

@@ -18,10 +18,11 @@ import {
StoreUpdateCustomerAddressType,
} from "../../../validators"
import { refetchCustomer } from "../../../helpers"
import { DeleteResponse, HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerAddressResponse>
) => {
const customerId = req.auth_context.actor_id
@@ -47,7 +48,7 @@ export const GET = async (
export const POST = async (
req: AuthenticatedMedusaRequest<StoreUpdateCustomerAddressType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
) => {
const id = req.auth_context.actor_id!
await validateCustomerAddress(req.scope, id, req.params.address_id)
@@ -71,7 +72,7 @@ export const POST = async (
export const DELETE = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
res: MedusaResponse<DeleteResponse<"address">>
) => {
const id = req.auth_context.actor_id
await validateCustomerAddress(req.scope, id, req.params.address_id)

View File

@@ -13,10 +13,11 @@ import {
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { refetchCustomer } from "../../helpers"
import { HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressesParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerAddressListResponse>
) => {
const customerId = req.auth_context.actor_id
@@ -42,7 +43,7 @@ export const GET = async (
export const POST = async (
req: AuthenticatedMedusaRequest<StoreCreateCustomerAddressType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
) => {
const customerId = req.auth_context.actor_id

View File

@@ -10,10 +10,11 @@ import {
import { refetchCustomer } from "../helpers"
import { MedusaError } from "@medusajs/utils"
import { updateCustomersWorkflow } from "@medusajs/core-flows"
import { HttpTypes } from "@medusajs/types"
export const GET = async (
req: AuthenticatedMedusaRequest<StoreGetCustomerParamsType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
) => {
const id = req.auth_context.actor_id
const customer = await refetchCustomer(
@@ -34,7 +35,7 @@ export const GET = async (
export const POST = async (
req: AuthenticatedMedusaRequest<StoreUpdateCustomerType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
) => {
const customerId = req.auth_context.actor_id
await updateCustomersWorkflow(req.scope).run({

View File

@@ -7,10 +7,11 @@ import { MedusaError } from "@medusajs/utils"
import { createCustomerAccountWorkflow } from "@medusajs/core-flows"
import { refetchCustomer } from "./helpers"
import { StoreCreateCustomerType } from "./validators"
import { HttpTypes } from "@medusajs/types"
export const POST = async (
req: AuthenticatedMedusaRequest<StoreCreateCustomerType>,
res: MedusaResponse
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
) => {
// If `actor_id` is present, the request carries authentication for an existing customer
if (req.auth_context.actor_id) {