chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
33
packages/modules/currency/src/loaders/initial-data.ts
Normal file
33
packages/modules/currency/src/loaders/initial-data.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ModulesSdkTypes, LoaderOptions, Logger } from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys, defaultCurrencies } from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
|
||||
export default async ({
|
||||
container,
|
||||
options,
|
||||
}: LoaderOptions<
|
||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
>): Promise<void> => {
|
||||
// TODO: Add default logger to the container when running tests
|
||||
const logger =
|
||||
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
const {
|
||||
currencyService_,
|
||||
}: { currencyService_: ModulesSdkTypes.InternalModuleService<Currency> } =
|
||||
container.resolve(ModuleRegistrationName.CURRENCY)
|
||||
|
||||
try {
|
||||
const normalizedCurrencies = Object.values(defaultCurrencies).map((c) => ({
|
||||
...c,
|
||||
code: c.code.toLowerCase(),
|
||||
}))
|
||||
const resp = await currencyService_.upsert(normalizedCurrencies)
|
||||
logger.info(`Loaded ${resp.length} currencies`)
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
`Failed to load currencies, skipping loader. Original error: ${error.message}`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user