-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.utils.js
51 lines (37 loc) · 1.03 KB
/
firebase.utils.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import admin from 'firebase-admin';
import './env.js';
admin.initializeApp({
credential: admin.credential.cert(JSON.parse(process.env.FIREBASE_ADMIN_SDK_PRIVATE_KEY))
});
export const db = admin.firestore();
const catalogue = db.collection('product-catalogue');
export const getCatalogue = async () => {
const snapshot = await catalogue.get();
if (!snapshot) return;
const collectionsArray = snapshot.docs.map(doc => {
return {
id: doc.id,
...doc.data()
}
});
return collectionsArray;
};
export const getItems = async (sectionId) => {
const snapshot = await catalogue.doc(sectionId).collection('items').get();
if (!snapshot) return;
const itemsArray = snapshot.docs.map(doc => {
return {
id: doc.id,
...doc.data()
}
});
return itemsArray;
}
export const getSection = async (id) => {
const doc = await catalogue.doc(id).get();
return {
id: doc.id,
...doc.data()
}
}
export default admin;