-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_firestore.js
38 lines (33 loc) · 1007 Bytes
/
common_firestore.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
'use strict';
const Firestore = require('@google-cloud/firestore');
// if process.env.TARGET_PROJECT_ID is defined, it's RCQ CF that tries to reach RQ Firestore
// otherwise, it's RQ reaching its own firestore
const firestore = process.env.TARGET_PROJECT_ID ? new Firestore ({projectId:process.env.TARGET_PROJECT_ID}) : new Firestore ();
firestore.settings({timestampsInSnapshots: true});
async function getQueteurFromFirestore(uid)
{
let queteurPromise = await firestore
.collection('queteurs')
.doc(uid)
.get();
if (queteurPromise.exists)
{
return queteurPromise.data();
}
else
{
throw new functions.https.HttpsError('not-found', "queteur with uid='"+uid+" not found");
}
}
async function updateQueteurFromFirestore(uid, data)
{
return firestore
.collection('queteurs')
.doc(uid)
.update(data);
}
module.exports = {
getQueteurFromFirestore : getQueteurFromFirestore,
updateQueteurFromFirestore:updateQueteurFromFirestore,
firestore:firestore
};