1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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<Office[]> {
const snapshot = await getDocs(collection(db, 'offices'));
return snapshot.docs.map((item) => mapOffice(item.id, item.data()));
},
async getById(id: string): Promise<Office | null> {
const snapshot = await getDoc(doc(db, 'offices', id));
if (!snapshot.exists()) {
return null;
}
return mapOffice(snapshot.id, snapshot.data());
},
};
|