diff options
| author | Anita <ana.tqtc@gmail.com> | 2026-04-19 19:21:17 +0100 |
|---|---|---|
| committer | Anita <ana.tqtc@gmail.com> | 2026-04-19 19:21:17 +0100 |
| commit | e8914f03cce7db31485ec26912ac7c20ec3165ce (patch) | |
| tree | 21d1a6d18a007be907369a12656a4b364a0e50a4 /src/features/profile/services | |
| parent | ed52756173468bfe98cdb62d95483b4949b27351 (diff) | |
feat(profile): edición de perfil con bio, teléfono y empresa + validación de bio (200 caracteres) refs #5
Diffstat (limited to 'src/features/profile/services')
| -rw-r--r-- | src/features/profile/services/profileService.ts | 67 |
1 files changed, 53 insertions, 14 deletions
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<UserProfile | null> { - 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<void> { - 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, { |