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 {
|
export interface AdminCurrency extends BaseCurrency {}
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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 "./admin"
|
||||||
|
export * from "./common"
|
||||||
|
export * from "./store"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BaseCurrency } from "../common";
|
||||||
|
|
||||||
|
export interface StoreCurrency extends BaseCurrency {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./responses"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { PaginatedResponse } from "../../common";
|
||||||
|
import { StoreCurrency } from "./entities";
|
||||||
|
|
||||||
|
export interface StoreCurrencyResponse {
|
||||||
|
currency: StoreCurrency
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StoreCurrencyListResponse
|
||||||
|
extends PaginatedResponse<{ currencies: StoreCurrency[] }> {}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import {
|
||||||
|
BaseCustomer,
|
||||||
|
BaseCustomerAddress,
|
||||||
|
} from "../common"
|
||||||
|
|
||||||
|
export interface StoreCustomer extends BaseCustomer {}
|
||||||
|
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export * from "./entities"
|
||||||
|
export * from "./payloads"
|
||||||
|
export * from "./queries"
|
||||||
|
export * from "./responses"
|
||||||
+1
-11
@@ -1,19 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
BaseCreateCustomer,
|
BaseCreateCustomer,
|
||||||
BaseCreateCustomerAddress,
|
BaseCreateCustomerAddress,
|
||||||
BaseCustomer,
|
|
||||||
BaseCustomerAddress,
|
|
||||||
BaseCustomerAddressFilters,
|
|
||||||
BaseCustomerFilters,
|
|
||||||
BaseUpdateCustomer,
|
BaseUpdateCustomer,
|
||||||
BaseUpdateCustomerAddress,
|
BaseUpdateCustomerAddress,
|
||||||
} from "./common"
|
} from "../common"
|
||||||
|
|
||||||
export interface StoreCustomer extends BaseCustomer {}
|
|
||||||
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
|
||||||
export interface StoreCustomerFilters extends BaseCustomerFilters {}
|
|
||||||
export interface StoreCustomerAddressFilters
|
|
||||||
extends BaseCustomerAddressFilters {}
|
|
||||||
|
|
||||||
export interface StoreCreateCustomer extends BaseCreateCustomer {}
|
export interface StoreCreateCustomer extends BaseCreateCustomer {}
|
||||||
export interface StoreUpdateCustomer extends BaseUpdateCustomer {}
|
export interface StoreUpdateCustomer extends BaseUpdateCustomer {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import {
|
||||||
|
BaseCustomerAddressFilters,
|
||||||
|
BaseCustomerFilters,
|
||||||
|
} from "../common"
|
||||||
|
|
||||||
|
export interface StoreCustomerFilters extends BaseCustomerFilters {}
|
||||||
|
export interface StoreCustomerAddressFilters
|
||||||
|
extends BaseCustomerAddressFilters {}
|
||||||
@@ -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,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
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 remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
const variables = { filters: { code: req.params.code } }
|
const variables = { filters: { code: req.params.code } }
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
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 remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
const queryObject = remoteQueryObjectFromString({
|
const queryObject = remoteQueryObjectFromString({
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ import {
|
|||||||
StoreUpdateCustomerAddressType,
|
StoreUpdateCustomerAddressType,
|
||||||
} from "../../../validators"
|
} from "../../../validators"
|
||||||
import { refetchCustomer } from "../../../helpers"
|
import { refetchCustomer } from "../../../helpers"
|
||||||
|
import { DeleteResponse, HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressParamsType>,
|
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerAddressResponse>
|
||||||
) => {
|
) => {
|
||||||
const customerId = req.auth_context.actor_id
|
const customerId = req.auth_context.actor_id
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreUpdateCustomerAddressType>,
|
req: AuthenticatedMedusaRequest<StoreUpdateCustomerAddressType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.auth_context.actor_id!
|
const id = req.auth_context.actor_id!
|
||||||
await validateCustomerAddress(req.scope, id, req.params.address_id)
|
await validateCustomerAddress(req.scope, id, req.params.address_id)
|
||||||
@@ -71,7 +72,7 @@ export const POST = async (
|
|||||||
|
|
||||||
export const DELETE = async (
|
export const DELETE = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<DeleteResponse<"address">>
|
||||||
) => {
|
) => {
|
||||||
const id = req.auth_context.actor_id
|
const id = req.auth_context.actor_id
|
||||||
await validateCustomerAddress(req.scope, id, req.params.address_id)
|
await validateCustomerAddress(req.scope, id, req.params.address_id)
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ import {
|
|||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { refetchCustomer } from "../../helpers"
|
import { refetchCustomer } from "../../helpers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressesParamsType>,
|
req: AuthenticatedMedusaRequest<StoreGetCustomerAddressesParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerAddressListResponse>
|
||||||
) => {
|
) => {
|
||||||
const customerId = req.auth_context.actor_id
|
const customerId = req.auth_context.actor_id
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreCreateCustomerAddressType>,
|
req: AuthenticatedMedusaRequest<StoreCreateCustomerAddressType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
|
||||||
) => {
|
) => {
|
||||||
const customerId = req.auth_context.actor_id
|
const customerId = req.auth_context.actor_id
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import {
|
|||||||
import { refetchCustomer } from "../helpers"
|
import { refetchCustomer } from "../helpers"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { updateCustomersWorkflow } from "@medusajs/core-flows"
|
import { updateCustomersWorkflow } from "@medusajs/core-flows"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreGetCustomerParamsType>,
|
req: AuthenticatedMedusaRequest<StoreGetCustomerParamsType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
|
||||||
) => {
|
) => {
|
||||||
const id = req.auth_context.actor_id
|
const id = req.auth_context.actor_id
|
||||||
const customer = await refetchCustomer(
|
const customer = await refetchCustomer(
|
||||||
@@ -34,7 +35,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreUpdateCustomerType>,
|
req: AuthenticatedMedusaRequest<StoreUpdateCustomerType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
|
||||||
) => {
|
) => {
|
||||||
const customerId = req.auth_context.actor_id
|
const customerId = req.auth_context.actor_id
|
||||||
await updateCustomersWorkflow(req.scope).run({
|
await updateCustomersWorkflow(req.scope).run({
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import { MedusaError } from "@medusajs/utils"
|
|||||||
import { createCustomerAccountWorkflow } from "@medusajs/core-flows"
|
import { createCustomerAccountWorkflow } from "@medusajs/core-flows"
|
||||||
import { refetchCustomer } from "./helpers"
|
import { refetchCustomer } from "./helpers"
|
||||||
import { StoreCreateCustomerType } from "./validators"
|
import { StoreCreateCustomerType } from "./validators"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreCreateCustomerType>,
|
req: AuthenticatedMedusaRequest<StoreCreateCustomerType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse<HttpTypes.StoreCustomerResponse>
|
||||||
) => {
|
) => {
|
||||||
// If `actor_id` is present, the request carries authentication for an existing customer
|
// If `actor_id` is present, the request carries authentication for an existing customer
|
||||||
if (req.auth_context.actor_id) {
|
if (req.auth_context.actor_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user