feat(pricing, types, utils, medusa-sdk): Pricing Module Setup + Currency (#4860)
What: - Setups the skeleton for pricing module - Creates service/model/repository for currency model - Setups types - Setups DB - Moved some utils to a common place RESOLVES CORE-1477 RESOLVES CORE-1476
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
import { FindConfig, DAL, Context } from "@medusajs/types"
|
||||
import { MedusaError, isDefined, lowerCaseFirst } from "../common"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
MedusaError,
|
||||
isDefined,
|
||||
lowerCaseFirst,
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
import { buildQuery } from "./build-query"
|
||||
|
||||
type RetrieveEntityParams<TDTO> = {
|
||||
id: string,
|
||||
entityName: string,
|
||||
id: string
|
||||
identifierColumn?: string
|
||||
entityName: string
|
||||
repository: DAL.TreeRepositoryService | DAL.RepositoryService
|
||||
config: FindConfig<TDTO>
|
||||
sharedContext?: Context
|
||||
}
|
||||
|
||||
export async function retrieveEntity<
|
||||
TEntity,
|
||||
TDTO,
|
||||
>({
|
||||
export async function retrieveEntity<TEntity, TDTO>({
|
||||
id,
|
||||
identifierColumn = "id",
|
||||
entityName,
|
||||
repository,
|
||||
config = {},
|
||||
@@ -23,23 +27,25 @@ export async function retrieveEntity<
|
||||
if (!isDefined(id)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`"${lowerCaseFirst(entityName)}Id" must be defined`
|
||||
`"${lowerCaseFirst(entityName)}${upperCaseFirst(
|
||||
identifierColumn
|
||||
)}" must be defined`
|
||||
)
|
||||
}
|
||||
|
||||
const queryOptions = buildQuery<TEntity>({
|
||||
id,
|
||||
}, config)
|
||||
|
||||
const entities = await repository.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
const queryOptions = buildQuery<TEntity>(
|
||||
{
|
||||
[identifierColumn]: id,
|
||||
},
|
||||
config
|
||||
)
|
||||
|
||||
const entities = await repository.find(queryOptions, sharedContext)
|
||||
|
||||
if (!entities?.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`${entityName} with id: ${id} was not found`
|
||||
`${entityName} with ${identifierColumn}: ${id} was not found`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user