bulltrackers-module 1.0.993 → 1.0.994
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -27,6 +27,59 @@ function getTutorialProgressRef(db, cid) {
|
|
|
27
27
|
.doc('progress');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
async function getDerivedCompletions(db, cid) {
|
|
31
|
+
const completed = new Set();
|
|
32
|
+
const userDocRef = db.collection('SignedInUsers').doc(String(cid));
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const userDoc = await userDocRef.get();
|
|
36
|
+
if (userDoc.exists) {
|
|
37
|
+
completed.add('account_create');
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
// Non-fatal; ignore and continue.
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const verificationRef = userDocRef.collection('verification').doc('data');
|
|
45
|
+
const verificationSnap = await verificationRef.get();
|
|
46
|
+
if (verificationSnap.exists) {
|
|
47
|
+
const vData = verificationSnap.data() || {};
|
|
48
|
+
if (vData.etoroCID || vData.etoroUsername || vData.accountSetupComplete) {
|
|
49
|
+
completed.add('account_link_etoro');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// Non-fatal; ignore and continue.
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const subSnap = await userDocRef
|
|
58
|
+
.collection('alert_subscriptions')
|
|
59
|
+
.limit(1)
|
|
60
|
+
.get();
|
|
61
|
+
if (!subSnap.empty) {
|
|
62
|
+
completed.add('alerts_create_threshold');
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// Non-fatal; ignore and continue.
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const alertsSnap = await userDocRef
|
|
70
|
+
.collection('alerts')
|
|
71
|
+
.limit(1)
|
|
72
|
+
.get();
|
|
73
|
+
if (!alertsSnap.empty) {
|
|
74
|
+
completed.add('alerts_receive_notification');
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// Non-fatal; ignore and continue.
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return completed;
|
|
81
|
+
}
|
|
82
|
+
|
|
30
83
|
async function getTutorialConfig(req) {
|
|
31
84
|
const config = (req.config && req.config.tutorial) || {};
|
|
32
85
|
return {
|
|
@@ -40,15 +93,31 @@ router.get('/progress', requireVerifiedUser, async (req, res, next) => {
|
|
|
40
93
|
const { db } = req.services;
|
|
41
94
|
const cid = req.targetUserId;
|
|
42
95
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
96
|
+
const ref = getTutorialProgressRef(db, cid);
|
|
97
|
+
const doc = await ref.get();
|
|
98
|
+
const data = doc.exists ? doc.data() || {} : {};
|
|
99
|
+
|
|
100
|
+
const persistedCompleted = new Set(
|
|
101
|
+
Array.isArray(data.completedTaskIds) ? data.completedTaskIds : []
|
|
102
|
+
);
|
|
103
|
+
const derivedCompleted = await getDerivedCompletions(db, cid);
|
|
104
|
+
const mergedCompleted = Array.from(
|
|
105
|
+
new Set([...persistedCompleted, ...derivedCompleted])
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (mergedCompleted.length !== persistedCompleted.size) {
|
|
109
|
+
await ref.set(
|
|
110
|
+
{
|
|
111
|
+
completedTaskIds: mergedCompleted,
|
|
112
|
+
},
|
|
113
|
+
{ merge: true }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
45
116
|
|
|
46
117
|
res.json({
|
|
47
118
|
success: true,
|
|
48
119
|
data: {
|
|
49
|
-
completedTaskIds:
|
|
50
|
-
? data.completedTaskIds
|
|
51
|
-
: [],
|
|
120
|
+
completedTaskIds: mergedCompleted,
|
|
52
121
|
explicitlyDismissedTaskIds: Array.isArray(
|
|
53
122
|
data.explicitlyDismissedTaskIds
|
|
54
123
|
)
|