Skip to content

Commit e2e327c

Browse files
committed
set-points script
1 parent 575b50b commit e2e327c

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"get-pg-meta-json": "grunt build && node scripts/get-pg-meta-json.js",
2020
"get-tts-results": "node scripts/get-tts-results.js",
2121
"update-results": "node scripts/update-results.js",
22+
"set-points": "node scripts/set-points.js",
2223
"start-marsh": "grunt build && concurrently \"grunt concurrent\" \"GOOGLE_APPLICATION_CREDENTIALS=private/service-account.json firebase serve --project prod\""
2324
},
2425
"devDependencies": {

scripts/set-points.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const fb = require('firebase-admin');
4+
const downloadUsers = require('./utils/downloadUsers');
5+
6+
7+
// ---------------------
8+
const EMAIL = 'foobar@email.com'
9+
const PG = '7-31-testing-tankards';
10+
const POINTS = 16;
11+
// ---------------------
12+
13+
14+
15+
16+
17+
const userDb = fb.firestore().collection('users');
18+
async function updatePoints() {
19+
await downloadUsers();
20+
21+
console.log('\n\n\n\n');
22+
23+
const file = path.join(__dirname, `../private/tmp-users.json`);
24+
const accounts = JSON.parse(fs.readFileSync(file)).users;
25+
26+
const userId = accounts.find(a => a.email.toLowerCase() === EMAIL.toLowerCase()).localId;
27+
28+
if(!userId) {
29+
console.log('ERROR: User not found by email');
30+
process.exit();
31+
}
32+
33+
const liveDoc = (await userDb.doc(userId).get()).data();
34+
35+
if(!liveDoc) {
36+
console.log('ERROR: User not found by id');
37+
process.exit();
38+
}
39+
40+
const answers = liveDoc.answers?.[PG];
41+
42+
if (!answers || !answers.submitted) {
43+
console.log('ERROR: User has not submitted answers for this pg');
44+
process.exit();
45+
}
46+
47+
if (!answers.total || answers.total < POINTS) {
48+
console.log('ERROR: Number of points to set is greater than total possible points');
49+
process.exit();
50+
}
51+
52+
const score = Math.round(100 * POINTS / answers.total);
53+
54+
console.log(`Setting points for ${liveDoc.first} ${liveDoc.last} to ${POINTS} (${score}%)\n\n\n\n`);
55+
56+
await userDb.doc(userId).set({answers: {[PG]: { points: POINTS, score }}}, {merge: true});
57+
}
58+
59+
updatePoints().then(() => process.exit());

0 commit comments

Comments
 (0)