feat(pricing, utils, types): adds money amount to pricing module (#4909)

What:

- Adds money amount service / repo / model
- Adds money amount to entry service
- Adds tests for services
- Refreshes schema
- Update joiner config to include money amounts


RESOLVES CORE-1478
RESOLVES CORE-1479

Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2023-08-31 15:03:10 +02:00
committed by GitHub
parent 0627d06f72
commit fcb6b4f510
27 changed files with 1481 additions and 112 deletions

View File

@@ -22,14 +22,14 @@ export async function run({
logger.info(`Loading seed data from ${path}...`)
const { currenciesData } = await import(resolve(process.cwd(), path)).catch(
(e) => {
logger?.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following currenciesData.${EOL}${e}`
)
throw e
}
)
const { currenciesData, moneyAmountsData } = await import(
resolve(process.cwd(), path)
).catch((e) => {
logger?.error(
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: currenciesData, moneyAmountsData.${EOL}${e}`
)
throw e
})
const dbData = ModulesSdkUtils.loadDatabaseConfig("pricing", options)!
const entities = Object.values(PricingModels) as unknown as EntitySchema[]
@@ -40,12 +40,14 @@ export async function run({
entities,
pathToMigrations
)
const manager = orm.em.fork()
try {
logger.info("Inserting currencies")
logger.info("Inserting currencies & money_amounts")
await createCurrencies(manager, currenciesData)
await createMoneyAmounts(manager, moneyAmountsData)
} catch (e) {
logger.error(
`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${EOL}${e}`
@@ -59,7 +61,7 @@ async function createCurrencies(
manager: SqlEntityManager,
data: RequiredEntityData<PricingModels.Currency>[]
) {
const currencies: any[] = data.map((currencyData) => {
const currencies = data.map((currencyData) => {
return manager.create(PricingModels.Currency, currencyData)
})
@@ -67,3 +69,16 @@ async function createCurrencies(
return currencies
}
async function createMoneyAmounts(
manager: SqlEntityManager,
data: RequiredEntityData<PricingModels.MoneyAmount>[]
) {
const moneyAmounts = data.map((moneyAmountData) => {
return manager.create(PricingModels.MoneyAmount, moneyAmountData)
})
await manager.persistAndFlush(moneyAmounts)
return moneyAmounts
}