From eb78dcac1bac7a4c179574e450fdb53c052dbfdf Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Tue, 25 Feb 2025 16:23:14 -0300 Subject: [PATCH] feat: add vtex telephone (#1021) --- commerce/types.ts | 2 ++ vtex/loaders/user.ts | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/commerce/types.ts b/commerce/types.ts index 97667791d..05e3b5430 100644 --- a/commerce/types.ts +++ b/commerce/types.ts @@ -411,6 +411,8 @@ export interface Person extends Omit { image?: ImageObject[] | null; /** The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain. */ taxID?: string; + /** The telephone number. */ + telephone?: string; } // NON SCHEMA.ORG Compliant. Should be removed ASAP export interface Author extends Omit { diff --git a/vtex/loaders/user.ts b/vtex/loaders/user.ts index 174398e71..47a8ad03a 100644 --- a/vtex/loaders/user.ts +++ b/vtex/loaders/user.ts @@ -11,6 +11,8 @@ interface User { profilePicture?: string; gender?: string; document?: string; + homePhone?: string; + businessPhone?: string; } async function loader( @@ -26,7 +28,7 @@ async function loader( } const query = - "query getUserProfile { profile { id userId email firstName lastName profilePicture gender document }}"; + "query getUserProfile { profile { id userId email firstName lastName profilePicture gender document homePhone businessPhone }}"; try { const { profile: user } = await io.query<{ profile: User }, null>( @@ -40,9 +42,12 @@ async function loader( givenName: user.firstName, familyName: user.lastName, taxID: user?.document?.replace(/[^\d]/g, ""), - gender: user.gender === "f" - ? "https://schema.org/Female" - : "https://schema.org/Male", + gender: user.gender + ? user.gender === "f" + ? "https://schema.org/Female" + : "https://schema.org/Male" + : undefined, + telephone: user.homePhone ?? user.businessPhone, }; } catch (_) { return null;