-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetMyContent.js
More file actions
61 lines (53 loc) · 1.48 KB
/
getMyContent.js
File metadata and controls
61 lines (53 loc) · 1.48 KB
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
52
53
54
55
56
57
58
59
60
61
import { logger } from 'firebase-functions/v2';
import { getFirestore } from 'firebase-admin/firestore';
import { graphicConverter, myContentConverter } from '../converters.js';
import { safelyInitializeApp } from '../firebase.js';
safelyInitializeApp();
const db = getFirestore();
export const myContent = async (uid) => {
const points = [];
const submissions = [];
try {
const snapshot = await db
.collection('submitters')
.doc(uid)
.collection('points')
.withConverter(graphicConverter)
.get();
if (snapshot.empty) {
logger.debug('user points are empty', uid, {
structuredData: true,
});
} else {
snapshot.forEach((doc) => {
const item = doc.data();
points.push(item);
});
}
} catch (error) {
logger.error('error querying points', error, uid, {
structuredData: true,
});
}
try {
let filter = db
.collectionGroup('submissions')
.where('submitted_by.id', '==', uid)
.where('status.user.cancelled', '==', null);
const snapshot = await filter.withConverter(myContentConverter).get();
if (snapshot.empty) {
logger.debug('user submissions are empty', uid, {
structuredData: true,
});
} else {
snapshot.forEach((doc) => {
submissions.push(doc.data());
});
}
} catch (error) {
logger.error('error querying submissions', error, uid, {
structuredData: true,
});
}
return { submissions, points };
};