import { collection, doc, getDoc, getDocs } from 'firebase/firestore'; import { db } from '@/shared/lib/firebase/config'; import { Office } from '@/features/offices/types'; function mapOffice(id: string, data: any): Office { return { id, name: data.name ?? '', location: data.location ?? '', capacity: data.capacity ?? 0, description: data.description ?? '', }; } export const officesService = { async getAll(): Promise { const snapshot = await getDocs(collection(db, 'offices')); return snapshot.docs.map((item) => mapOffice(item.id, item.data())); }, async getById(id: string): Promise { const snapshot = await getDoc(doc(db, 'offices', id)); if (!snapshot.exists()) { return null; } return mapOffice(snapshot.id, snapshot.data()); }, };