From e8914f03cce7db31485ec26912ac7c20ec3165ce Mon Sep 17 00:00:00 2001 From: Anita Date: Sun, 19 Apr 2026 19:21:17 +0100 Subject: feat(profile): edición de perfil con bio, teléfono y empresa + validación de bio (200 caracteres) refs #5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/profile/services/profileService.ts | 67 +++++++++++++++++++------ 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'src/features/profile/services') diff --git a/src/features/profile/services/profileService.ts b/src/features/profile/services/profileService.ts index f7e89b4..c202c18 100644 --- a/src/features/profile/services/profileService.ts +++ b/src/features/profile/services/profileService.ts @@ -1,13 +1,21 @@ // src/features/profile/services/profileService.ts -import { doc, getDoc, setDoc } from 'firebase/firestore'; -import { updateProfile } from 'firebase/auth'; -import { db, auth } from '@/shared/lib/firebase/config'; -import { UserProfile } from '@/features/profile/types'; +import { UserProfile } from "@/features/profile/types"; +import { auth, db } from "@/shared/lib/firebase/config"; +import { mockDelay, mockUserProfile } from "@/shared/lib/mockData"; +import { updateProfile } from "firebase/auth"; +import { doc, getDoc, setDoc } from "firebase/firestore"; + +const USE_MOCK = process.env.EXPO_PUBLIC_USE_MOCK_DATA === "true"; export const profileService = { async getMyProfile(uid: string): Promise { - const snapshot = await getDoc(doc(db, 'users', uid)); + if (USE_MOCK) { + await mockDelay(); + return mockUserProfile.uid === uid ? mockUserProfile : null; + } + + const snapshot = await getDoc(doc(db, "users", uid)); if (!snapshot.exists()) { return null; @@ -17,9 +25,12 @@ export const profileService = { return { uid, - email: data.email ?? '', - displayName: data.displayName ?? '', - photoURL: data.photoURL ?? '', + email: data.email ?? "", + displayName: data.displayName ?? "", + photoURL: data.photoURL ?? "", + phone: data.phone ?? "", + company: data.company ?? "", + bio: data.bio ?? "", }; }, @@ -27,15 +38,43 @@ export const profileService = { uid: string; displayName: string; photoURL?: string; + phone?: string; + company?: string; + bio?: string; }): Promise { - const { uid, displayName, photoURL } = params; + if (USE_MOCK) { + await mockDelay(); + mockUserProfile.displayName = params.displayName; + if (params.photoURL !== undefined) { + mockUserProfile.photoURL = params.photoURL; + } + if (params.phone !== undefined) { + mockUserProfile.phone = params.phone; + } + if (params.company !== undefined) { + mockUserProfile.company = params.company; + } + if (params.bio !== undefined) { + mockUserProfile.bio = params.bio; + } + return; + } + + const { uid, displayName, photoURL, phone, company, bio } = params; const currentUser = auth.currentUser; - await setDoc(doc(db, 'users', uid), { - email: currentUser?.email ?? '', - displayName, - ...(photoURL !== undefined ? { photoURL } : {}), - }, { merge: true }); + await setDoc( + doc(db, "users", uid), + { + email: currentUser?.email ?? "", + displayName, + ...(photoURL !== undefined ? { photoURL } : {}), + ...(phone !== undefined ? { phone } : {}), + ...(company !== undefined ? { company } : {}), + ...(bio !== undefined ? { bio } : {}), + }, + { merge: true }, + ); if (currentUser) { await updateProfile(currentUser, { -- cgit v1.2.3-54-g00ecf