feat: Add currency module and remove currency models from region and pricing modules (#6536)
What: - Creates a new currency module - Removes currency model from the pricing module - Removes currency model from region module
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { defaultAdminCurrencyFields } from "../query-config"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const variables = { code: req.params.code }
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "currency",
|
||||
variables,
|
||||
fields: defaultAdminCurrencyFields,
|
||||
})
|
||||
|
||||
const [currency] = await remoteQuery(queryObject)
|
||||
res.status(200).json({ currency })
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { transformQuery } from "../../../api/middlewares"
|
||||
import { MiddlewareRoute } from "../../../loaders/helpers/routing/types"
|
||||
import { authenticate } from "../../../utils/authenticate-middleware"
|
||||
import * as QueryConfig from "./query-config"
|
||||
import {
|
||||
AdminGetCurrenciesCurrencyParams,
|
||||
AdminGetCurrenciesParams,
|
||||
} from "./validators"
|
||||
|
||||
export const adminCurrencyRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["ALL"],
|
||||
matcher: "/admin/currencies*",
|
||||
middlewares: [authenticate("admin", ["bearer", "session", "api-key"])],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/currencies",
|
||||
middlewares: [
|
||||
transformQuery(
|
||||
AdminGetCurrenciesParams,
|
||||
QueryConfig.listTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/currencies/:code",
|
||||
middlewares: [
|
||||
transformQuery(
|
||||
AdminGetCurrenciesCurrencyParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
export const defaultAdminCurrencyRelations = []
|
||||
export const allowedAdminCurrencyRelations = []
|
||||
export const defaultAdminCurrencyFields = [
|
||||
"code",
|
||||
"name",
|
||||
"symbol",
|
||||
"symbol_native",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminCurrencyFields,
|
||||
defaultRelations: defaultAdminCurrencyRelations,
|
||||
allowedRelations: allowedAdminCurrencyRelations,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const listTransformQueryConfig = {
|
||||
defaultLimit: 50,
|
||||
isList: true,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import { defaultAdminCurrencyFields } from "./query-config"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "currency",
|
||||
variables: {
|
||||
filters: req.filterableFields,
|
||||
order: req.listConfig.order,
|
||||
skip: req.listConfig.skip,
|
||||
take: req.listConfig.take,
|
||||
},
|
||||
fields: defaultAdminCurrencyFields,
|
||||
})
|
||||
|
||||
const { rows: currencies, metadata } = await remoteQuery(queryObject)
|
||||
|
||||
res.json({
|
||||
currencies,
|
||||
count: metadata.count,
|
||||
offset: metadata.skip,
|
||||
limit: metadata.take,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Type } from "class-transformer"
|
||||
import { IsOptional, IsString, ValidateNested } from "class-validator"
|
||||
import { FindParams, extendedFindParamsMixin } from "../../../types/common"
|
||||
|
||||
export class AdminGetCurrenciesCurrencyParams extends FindParams {}
|
||||
/**
|
||||
* Parameters used to filter and configure the pagination of the retrieved currencies.
|
||||
*/
|
||||
export class AdminGetCurrenciesParams extends extendedFindParamsMixin({
|
||||
limit: 50,
|
||||
offset: 0,
|
||||
}) {
|
||||
/**
|
||||
* Search parameter for currencies.
|
||||
*/
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
code?: string | string[]
|
||||
|
||||
// Additional filters from BaseFilterable
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => AdminGetCurrenciesParams)
|
||||
$and?: AdminGetCurrenciesParams[]
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => AdminGetCurrenciesParams)
|
||||
$or?: AdminGetCurrenciesParams[]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export const defaultAdminRegionRelations = ["countries", "currency"]
|
||||
export const allowedAdminRegionRelations = ["countries", "currency"]
|
||||
export const defaultAdminRegionRelations = ["countries"]
|
||||
export const allowedAdminRegionRelations = ["countries"]
|
||||
export const defaultAdminRegionFields = [
|
||||
"id",
|
||||
"name",
|
||||
@@ -13,10 +13,6 @@ export const defaultAdminRegionFields = [
|
||||
"countries.iso_3",
|
||||
"countries.num_code",
|
||||
"countries.name",
|
||||
"currency.code",
|
||||
"currency.symbol",
|
||||
"currency.symbol_native",
|
||||
"currency.name",
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
|
||||
Reference in New Issue
Block a user