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:
Riqwan Thamir
2023-08-29 21:58:34 +00:00
committed by GitHub
parent 470379e631
commit 460161a69f
70 changed files with 3022 additions and 75 deletions
+4 -4
View File
@@ -1,8 +1,8 @@
export * as DALUtils from "./dal"
export * as DecoratorUtils from "./decorators"
export * as EventBusUtils from "./event-bus"
export * as SearchUtils from "./search"
export * as ModulesSdkUtils from "./modules-sdk"
export * as DALUtils from "./dal"
export * as FeatureFlagUtils from "./feature-flags"
export * as ShippingProfileUtils from "./shipping"
export * as ModulesSdkUtils from "./modules-sdk"
export * as ProductUtils from "./product"
export * as SearchUtils from "./search"
export * as ShippingProfileUtils from "./shipping"
+2 -1
View File
@@ -1,4 +1,5 @@
export * from "./build-query"
export * from "./container"
export * from "./deduplicate"
export * from "./errors"
export * from "./generate-entity-id"
@@ -20,6 +21,6 @@ export * from "./stringify-circular"
export * from "./to-camel-case"
export * from "./to-kebab-case"
export * from "./to-pascal-case"
export * from "./transaction"
export * from "./upper-case-first"
export * from "./wrap-handler"
export * from "./container"
@@ -0,0 +1,3 @@
export function doNotForceTransaction(): boolean {
return false
}
@@ -0,0 +1,2 @@
export * from "./do-not-force-transaction"
export * from "./should-force-transaction"
@@ -0,0 +1,5 @@
import { MODULE_RESOURCE_TYPE } from "@medusajs/types"
export function shouldForceTransaction(target: any): boolean {
return target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
}
+4 -3
View File
@@ -1,6 +1,7 @@
export * from "./mikro-orm/mikro-orm-create-connection"
export * from "./mikro-orm/mikro-orm-repository"
export * from "./mikro-orm/mikro-orm-soft-deletable-filter"
export * from "./mikro-orm/utils"
export * from "./repositories"
export * from "./repository"
export * from "./utils"
export * from "./mikro-orm/utils"
export * from "./mikro-orm/mikro-orm-create-connection"
export * from "./mikro-orm/mikro-orm-soft-deletable-filter"
@@ -0,0 +1 @@
export * from "./load-custom-repositories"
@@ -0,0 +1,35 @@
import { Constructor, DAL } from "@medusajs/types"
import { asClass } from "awilix"
import { lowerCaseFirst } from "../../common"
/**
* Load the repositories from the custom repositories object. If a repository is not
* present in the custom repositories object, the default repository will be used.
*
* @param customRepositories
* @param container
*/
export function loadCustomRepositories({
defaultRepositories,
customRepositories,
container,
}) {
const customRepositoriesMap = new Map(Object.entries(customRepositories))
Object.entries(defaultRepositories).forEach(([key, defaultRepository]) => {
let finalRepository = customRepositoriesMap.get(key)
if (
!finalRepository ||
!(finalRepository as Constructor<DAL.RepositoryService>).prototype.find
) {
finalRepository = defaultRepository
}
container.register({
[lowerCaseFirst(key)]: asClass(
finalRepository as Constructor<DAL.RepositoryService>
).singleton(),
})
})
}
+4 -4
View File
@@ -1,10 +1,10 @@
export * from "./bundles"
export * from "./common"
export * from "./dal"
export * from "./decorators"
export * from "./event-bus"
export * from "./search"
export * from "./modules-sdk"
export * from "./dal"
export * from "./feature-flags"
export * from "./shipping"
export * from "./modules-sdk"
export * from "./product"
export * from "./search"
export * from "./shipping"
@@ -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`
)
}