From ded9396001afb78157246bb5946942c49d2bc346 Mon Sep 17 00:00:00 2001 From: Niklas Marion Date: Mon, 27 May 2024 15:10:52 +0200 Subject: [PATCH] format phone numbers --- package-lock.json | 12 ++++++++++++ package.json | 1 + .../athlete_representatives.service.ts | 12 ++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index a7d908f..2a76d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@sentry/node": "^7.81.0", "@sentry/tracing": "^7.81.0", "graphql-request": "^6.1.0", + "libphonenumber-js": "^1.11.2", "reflect-metadata": "^0.1.13", "rimraf": "^5.0.5", "rxjs": "^7.8.1", @@ -4240,6 +4241,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.11.2", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.2.tgz", + "integrity": "sha512-V9mGLlaXN1WETzqQvSu6qf6XVAr3nFuJvWsHcuzCCCo6xUKawwSxOPTpan5CGOSKTn5w/bQuCZcLPJkyysgC3w==", + "license": "MIT" + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -9388,6 +9395,11 @@ "type-check": "~0.4.0" } }, + "libphonenumber-js": { + "version": "1.11.2", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.2.tgz", + "integrity": "sha512-V9mGLlaXN1WETzqQvSu6qf6XVAr3nFuJvWsHcuzCCCo6xUKawwSxOPTpan5CGOSKTn5w/bQuCZcLPJkyysgC3w==" + }, "lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", diff --git a/package.json b/package.json index 5098fca..7ee6346 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@sentry/node": "^7.81.0", "@sentry/tracing": "^7.81.0", "graphql-request": "^6.1.0", + "libphonenumber-js": "^1.11.2", "reflect-metadata": "^0.1.13", "rimraf": "^5.0.5", "rxjs": "^7.8.1", diff --git a/src/athlete_representatives/athlete_representatives.service.ts b/src/athlete_representatives/athlete_representatives.service.ts index 03271ab..4fc96cb 100644 --- a/src/athlete_representatives/athlete_representatives.service.ts +++ b/src/athlete_representatives/athlete_representatives.service.ts @@ -8,6 +8,7 @@ import { } from './athlete_representatives.query'; import { z } from 'zod'; import { formatLastname } from 'src/name.utils'; +import parsePhoneNumber from 'libphonenumber-js'; @Injectable() export class AthleteRepresentativesService { @@ -57,6 +58,12 @@ export class AthleteRepresentativesService { if (!response.getAthleteRepresentativeProfile) { return null; } + + const phoneNumber = + response.getAthleteRepresentativeProfile.mobile.length > 0 + ? parsePhoneNumber(response.getAthleteRepresentativeProfile.mobile[0]) + : null; + return { country: response.getAthleteRepresentativeProfile.countryCode, email: @@ -69,10 +76,7 @@ export class AthleteRepresentativesService { lastname: formatLastname( response.getAthleteRepresentativeProfile.lastName, ), - phone: - response.getAthleteRepresentativeProfile.mobile.length > 0 - ? response.getAthleteRepresentativeProfile.mobile[0] - : null, + phone: phoneNumber ? phoneNumber.formatInternational() : null, id: response.getAthleteRepresentativeProfile.athleteRepresentativeId, }; }