From ec5bd25c8dd2a48a260a4ce1d67290ad3c521c0c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 6 Jun 2026 13:22:55 +0200 Subject: [PATCH] Refactor country code logic --- apps/api/src/helper/country.helper.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 apps/api/src/helper/country.helper.ts diff --git a/apps/api/src/helper/country.helper.ts b/apps/api/src/helper/country.helper.ts new file mode 100644 index 000000000..9d14d8778 --- /dev/null +++ b/apps/api/src/helper/country.helper.ts @@ -0,0 +1,17 @@ +import { countries } from 'countries-list'; + +export function getCountryCodeByName({ + aliases = {}, + name +}: { + aliases?: Record; + name: string; +}): string { + for (const [code, country] of Object.entries(countries)) { + if (country.name === name || country.name === aliases[name]) { + return code; + } + } + + return undefined; +}