fix(medusa-plugin-ip-lookup): Remove outdated Typeorm usage (#3884)

* fix(medusa-plugin-ip-lookup): Use new Typeorm API

* Create dull-trainers-count.md
This commit is contained in:
Oliver Windall Juhl
2023-04-19 19:10:44 +02:00
committed by GitHub
parent 46ea671a46
commit 440f900af0
3 changed files with 17 additions and 11 deletions

View File

@@ -0,0 +1,6 @@
---
"medusa-plugin-ip-lookup": patch
"@medusajs/medusa": patch
---
fix(medusa-plugin-ip-lookup): Remove outdated Typeorm usage

View File

@@ -7,8 +7,7 @@ export default {
}
const ipLookupService = req.scope.resolve("ipLookupService")
const manager = req.scope.resolve("manager")
const countryRepository = req.scope.resolve("countryRepository")
const regionService = req.scope.resolve("regionService")
const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress
@@ -19,17 +18,18 @@ export default {
return
}
const countryRepo = manager.getCustomRepository(countryRepository)
const country = await countryRepo.findOne({
where: { iso_2: data.country_code.toLowerCase() },
})
const region = await regionService
.retrieveByCountryCode(data.country_code)
.catch(() => void 0)
// If country exists, add it to the body of the cart creation request
if (country?.region_id) {
req.body.region_id = country.region_id
req.body.country_code = country.iso_2
if (!region) {
next()
return
}
req.body.region_id = region.id
req.body.country_code = data.country_code.toLowerCase()
next()
} catch (error) {
next()

View File

@@ -422,7 +422,7 @@ class RegionService extends TransactionBaseService {
this.countryRepository_
)
const query = buildQuery({ code }, {})
const query = buildQuery({ iso_2: code.toLowerCase() }, {})
const country = await countryRepository.findOne(query)
if (!country) {