Skip to main content

Overview

BarberApp uses dependency injection with repository tokens to maintain clean architecture. All Firebase services implement repository interfaces and are located in src/app/services/firebase/.
Services are injected via tokens (e.g., AUTH_REPOSITORY) rather than concrete classes, allowing easy swapping of implementations.

Firebase Services

FirebaseAuthService

Handles authentication operations using Firebase Authentication. Location: src/app/services/firebase/firebase-auth.service.ts:18 Implements: AuthRepository
@Injectable({ providedIn: 'root' })
export class FirebaseAuthService implements AuthRepository

Methods

Creates a new user account with email and password.Parameters:
  • email - User’s email address
  • password - User’s password
Returns: The Firebase UID of the newly created userLocation: firebase-auth.service.ts:22
async register(email: string, password: string): Promise<string> {
  const userCredential = await createUserWithEmailAndPassword(
    this.auth, 
    email, 
    password
  );
  return userCredential.user.uid;
}
Authenticates a user with email and password.Parameters:
  • email - User’s email address
  • password - User’s password
Throws: Firebase auth errors (e.g., auth/invalid-credential)Location: firebase-auth.service.ts:27
Signs out the current user.Location: firebase-auth.service.ts:31
Checks if a user is currently authenticated.Returns: true if a user is signed in, false otherwiseLocation: firebase-auth.service.ts:35Uses onAuthStateChanged to detect the current auth state.
Retrieves the complete user profile of the authenticated user.Returns: Full UserBase object from Firestore, or null if not authenticatedLocation: firebase-auth.service.ts:43Behavior:
  • First checks Firebase Auth for the current user
  • Then fetches full user data from Firestore via FirebaseUserService
  • Falls back to a minimal UserBase object if Firestore data is missing

FirebaseUserService

Manages user data in Firestore. Location: src/app/services/firebase/firebase-user.service.ts:18 Implements: UserRepository
@Injectable({ providedIn: 'root' })
export class FirebaseUserService implements UserRepository

Methods

Creates a new user document in Firestore.Parameters:
  • user - Client or Specialist object with all required fields
Location: firebase-user.service.ts:21Behavior:
  • Automatically assigns a default profile picture URL if not provided
  • Stores the document with the user’s ID as the document ID
Checks if a DNI (national ID) is already registered.Parameters:
  • dni - National identity document number
Returns: true if DNI exists, false otherwiseLocation: firebase-user.service.ts:33Used during registration to prevent duplicate DNIs.
Fetches a user by their Firebase Authentication UID.Parameters:
  • uid - Firebase Authentication user ID
Returns: User object or null if not foundLocation: firebase-user.service.ts:42
Converts Firestore timestamp fields to JavaScript Date objects
Fetches a user by their application-specific ID.Parameters:
  • id - Application user ID (may differ from Firebase UID)
Returns: User object or null if not foundLocation: firebase-user.service.ts:57
Fetches multiple users by their IDs in a single query.Parameters:
  • ids - Array of user IDs
Returns: Array of matching usersLocation: firebase-user.service.ts:72
Firestore in queries are limited to 30 elements. For larger batches, you’ll need to split the query.
Retrieves all users with a specific role.Parameters:
  • role - User role (e.g., 'client', 'specialist')
Returns: Array of users with the specified roleLocation: firebase-user.service.ts:89
Updates an existing user’s data.Parameters:
  • updatedData - Partial user object with id and fields to update
Throws: Error if id is missing or user not foundLocation: firebase-user.service.ts:105

FirebaseAppointmentService

Manages appointments in Firestore. Location: src/app/services/firebase/firebase-appointment.service.ts:20 Implements: AppointmentRepository
@Injectable({ providedIn: 'root' })
export class FirebaseAppointmentService implements AppointmentRepository

Methods

Creates a new appointment document.Parameters:
  • appointment - Complete appointment object
Location: firebase-appointment.service.ts:24
Fetches an appointment by ID.Parameters:
  • id - Appointment ID
Returns: Appointment object or nullLocation: firebase-appointment.service.ts:33
Updates an existing appointment.Parameters:
  • appointment - Partial appointment object with id required
Location: firebase-appointment.service.ts:47Uses setDoc with merge: true to perform partial updates.
Retrieves all appointments for a specific client, sorted by date ascending.Parameters:
  • clientId - Client’s user ID
Returns: Array of appointmentsLocation: firebase-appointment.service.ts:81
Retrieves all appointments for a specific specialist, sorted by date ascending.Parameters:
  • specialistId - Specialist’s user ID
Returns: Array of appointmentsLocation: firebase-appointment.service.ts:85
Gets all completed appointments for a client, sorted by date descending.Parameters:
  • clientId - Client’s user ID
Returns: Array of completed appointments (newest first)Location: firebase-appointment.service.ts:89Used for displaying client medical history.
Fetches specialist appointments filtered by multiple statuses.Parameters:
  • specialistId - Specialist’s user ID
  • statuses - Array of appointment statuses to include
Returns: Array of matching appointmentsLocation: firebase-appointment.service.ts:108Example:
await service.getForSpecialistByStatuses(
  'specialist123',
  [AppointmentStatus.PENDING, AppointmentStatus.COMPLETED]
);
Retrieves specialist appointments within a date range.Parameters:
  • specialistId - Specialist’s user ID
  • startDate - Range start date
  • endDate - Range end date
Returns: Array of appointments in the date rangeLocation: firebase-appointment.service.ts:127
Retrieves client appointments within a date range.Parameters:
  • clientId - Client’s user ID
  • startDate - Range start date
  • endDate - Range end date
Returns: Array of appointments in the date rangeLocation: firebase-appointment.service.ts:147

FirebaseSpecialtyService

Manages specialty/service definitions. Location: src/app/services/firebase/firebase-specialty.service.ts:17 Implements: SpecialtyRepository
@Injectable({ providedIn: 'root' })
export class FirebaseSpecialtyService implements SpecialtyRepository

Methods

Retrieves all specialties from Firestore.Returns: Array of all specialty objectsLocation: firebase-specialty.service.ts:21
Fetches a single specialty by ID.Parameters:
  • id - Specialty ID
Returns: Specialty object or nullLocation: firebase-specialty.service.ts:28
Creates a new specialty.Parameters:
  • specialty - Complete specialty object
Location: firebase-specialty.service.ts:34
Updates an existing specialty.Parameters:
  • specialty - Complete specialty object with updated fields
Location: firebase-specialty.service.ts:39
Deletes a specialty.Parameters:
  • id - Specialty ID to delete
Location: firebase-specialty.service.ts:44

External Services

CloudinaryService

Handles image uploads and transformations using Cloudinary CDN. Location: src/app/services/cloudinary/cloudinary.service.ts:8
@Injectable({ providedIn: 'root' })
export class CloudinaryService

Properties

defaultProfilePictureUrl
string
Default profile picture URL used for new users

Methods

Uploads an image file to Cloudinary.Parameters:
  • file - Image file to upload
Returns: Secure URL of the uploaded imageLocation: cloudinary.service.ts:15Example:
const file = event.target.files[0];
const imageUrl = await cloudinaryService.uploadImage(file);
Uses the upload preset configured in environment.cloudinaryConfig.upload_preset.
Generates a Cloudinary URL with optional transformations.Parameters:
  • imageUrl - Original Cloudinary image URL
  • transformations - Optional transformation string (e.g., 'w_200,h_200,c_fill')
Returns: Transformed image URLLocation: cloudinary.service.ts:42Example:
const thumbnailUrl = cloudinaryService.getTransformedUrl(
  originalUrl,
  'w_150,h_150,c_thumb,g_face'
);

Repository Pattern

All services follow the repository pattern with dependency injection tokens:
// src/app/core/interfaces/auth.repository.token.ts
export const AUTH_REPOSITORY = new InjectionToken<AuthRepository>(
  'AUTH_REPOSITORY'
);
This pattern allows you to swap Firebase implementations with other backends (REST API, mock services, etc.) without changing facade or component code.

Build docs developers (and LLMs) love