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:
@@ -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 {}
|
||||
|
||||
14
packages/core/types/src/http/currency/common.ts
Normal file
14
packages/core/types/src/http/currency/common.ts
Normal 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
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./admin"
|
||||
export * from "./common"
|
||||
export * from "./store"
|
||||
3
packages/core/types/src/http/currency/store/entities.ts
Normal file
3
packages/core/types/src/http/currency/store/entities.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { BaseCurrency } from "../common";
|
||||
|
||||
export interface StoreCurrency extends BaseCurrency {}
|
||||
2
packages/core/types/src/http/currency/store/index.ts
Normal file
2
packages/core/types/src/http/currency/store/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./entities"
|
||||
export * from "./responses"
|
||||
9
packages/core/types/src/http/currency/store/responses.ts
Normal file
9
packages/core/types/src/http/currency/store/responses.ts
Normal 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[] }> {}
|
||||
7
packages/core/types/src/http/customer/store/entities.ts
Normal file
7
packages/core/types/src/http/customer/store/entities.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import {
|
||||
BaseCustomer,
|
||||
BaseCustomerAddress,
|
||||
} from "../common"
|
||||
|
||||
export interface StoreCustomer extends BaseCustomer {}
|
||||
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
||||
4
packages/core/types/src/http/customer/store/index.ts
Normal file
4
packages/core/types/src/http/customer/store/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -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 {}
|
||||
8
packages/core/types/src/http/customer/store/queries.ts
Normal file
8
packages/core/types/src/http/customer/store/queries.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import {
|
||||
BaseCustomerAddressFilters,
|
||||
BaseCustomerFilters,
|
||||
} from "../common"
|
||||
|
||||
export interface StoreCustomerFilters extends BaseCustomerFilters {}
|
||||
export interface StoreCustomerAddressFilters
|
||||
extends BaseCustomerAddressFilters {}
|
||||
13
packages/core/types/src/http/customer/store/responses.ts
Normal file
13
packages/core/types/src/http/customer/store/responses.ts
Normal 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[] }> {}
|
||||
@@ -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 } }
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user