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 authored and GitHub committed 2023-04-19 19:10:44 +02:00
1 parent 46ea671a46
commit 440f900af0
3 files changed
+17 -11

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"medusa-plugin-ip-lookup": patch
"@medusajs/medusa": patch
---
fix(medusa-plugin-ip-lookup): Remove outdated Typeorm usage
@@ -7,8 +7,7 @@ export default {
} }
const ipLookupService = req.scope.resolve("ipLookupService") const ipLookupService = req.scope.resolve("ipLookupService")
const manager = req.scope.resolve("manager") const regionService = req.scope.resolve("regionService")
const countryRepository = req.scope.resolve("countryRepository")
const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress
@@ -19,17 +18,18 @@ export default {
return return
} }
const countryRepo = manager.getCustomRepository(countryRepository) const region = await regionService
const country = await countryRepo.findOne({ .retrieveByCountryCode(data.country_code)
where: { iso_2: data.country_code.toLowerCase() }, .catch(() => void 0)
})
// If country exists, add it to the body of the cart creation request if (!region) {
if (country?.region_id) { next()
req.body.region_id = country.region_id return
req.body.country_code = country.iso_2
} }
req.body.region_id = region.id
req.body.country_code = data.country_code.toLowerCase()
next() next()
} catch (error) { } catch (error) {
next() next()
+1 -1
View File
@@ -422,7 +422,7 @@ class RegionService extends TransactionBaseService {
this.countryRepository_ this.countryRepository_
) )
const query = buildQuery({ code }, {}) const query = buildQuery({ iso_2: code.toLowerCase() }, {})
const country = await countryRepository.findOne(query) const country = await countryRepository.findOne(query)
if (!country) { if (!country) {