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

@@ -1,14 +1,3 @@
import { RawRounding } from "../../../common"
import { BaseCurrency } from "../common"
export interface AdminCurrency {
code: string
symbol: string
symbol_native: string
name: string
decimal_digits: number
raw_rounding: RawRounding
rounding: number
created_at: string
updated_at: string
deleted_at: string | null
}
export interface AdminCurrency extends BaseCurrency {}

View File

@@ -0,0 +1,14 @@
import { RawRounding } from "../../common"
export interface BaseCurrency {
code: string
symbol: string
symbol_native: string
name: string
decimal_digits: number
rounding: number
raw_rounding: RawRounding
created_at: string
updated_at: string
deleted_at: string | null
}

View File

@@ -1 +1,3 @@
export * from "./admin"
export * from "./common"
export * from "./store"

View File

@@ -0,0 +1,3 @@
import { BaseCurrency } from "../common";
export interface StoreCurrency extends BaseCurrency {}

View File

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

View File

@@ -0,0 +1,9 @@
import { PaginatedResponse } from "../../common";
import { StoreCurrency } from "./entities";
export interface StoreCurrencyResponse {
currency: StoreCurrency
}
export interface StoreCurrencyListResponse
extends PaginatedResponse<{ currencies: StoreCurrency[] }> {}

View File

@@ -0,0 +1,7 @@
import {
BaseCustomer,
BaseCustomerAddress,
} from "../common"
export interface StoreCustomer extends BaseCustomer {}
export interface StoreCustomerAddress extends BaseCustomerAddress {}

View File

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

View File

@@ -1,19 +1,9 @@
import {
BaseCreateCustomer,
BaseCreateCustomerAddress,
BaseCustomer,
BaseCustomerAddress,
BaseCustomerAddressFilters,
BaseCustomerFilters,
BaseUpdateCustomer,
BaseUpdateCustomerAddress,
} from "./common"
export interface StoreCustomer extends BaseCustomer {}
export interface StoreCustomerAddress extends BaseCustomerAddress {}
export interface StoreCustomerFilters extends BaseCustomerFilters {}
export interface StoreCustomerAddressFilters
extends BaseCustomerAddressFilters {}
} from "../common"
export interface StoreCreateCustomer extends BaseCreateCustomer {}
export interface StoreUpdateCustomer extends BaseUpdateCustomer {}

View File

@@ -0,0 +1,8 @@
import {
BaseCustomerAddressFilters,
BaseCustomerFilters,
} from "../common"
export interface StoreCustomerFilters extends BaseCustomerFilters {}
export interface StoreCustomerAddressFilters
extends BaseCustomerAddressFilters {}

View File

@@ -0,0 +1,13 @@
import { PaginatedResponse } from "../../common";
import { StoreCustomer, StoreCustomerAddress } from "./entities";
export interface StoreCustomerResponse {
customer: StoreCustomer
}
export interface StoreCustomerAddressResponse {
address: StoreCustomerAddress
}
export interface StoreCustomerAddressListResponse
extends PaginatedResponse<{ addresses: StoreCustomerAddress[] }> {}

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) {