-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_db.js
More file actions
59 lines (48 loc) · 1.83 KB
/
check_db.js
File metadata and controls
59 lines (48 loc) · 1.83 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
// Check database script
const admin = require('./backend/node_modules/firebase-admin');
const serviceAccount = require('./backend/firebase-credentials.json');
// Initialize Firebase Admin
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
}
const db = admin.firestore();
async function checkChildProfiles() {
try {
console.log('Checking child profiles in Firebase...');
// Get all child profiles
const profilesSnapshot = await db.collection('childProfiles').get();
console.log(`Found ${profilesSnapshot.size} child profiles in the database.`);
if (profilesSnapshot.size > 0) {
profilesSnapshot.forEach((doc, index) => {
const data = doc.data();
console.log(`\nProfile ${index + 1}:`);
console.log(` ID: ${doc.id}`);
console.log(` Name: "${data.name}"`);
console.log(` Age: ${data.age}`);
console.log(` Parent UID: ${data.parentUid}`);
console.log(` Created: ${data.createdAt}`);
});
}
// Get parent document to check childProfileIds
console.log('\nChecking parent documents...');
const parentsSnapshot = await db.collection('users').where('role', '==', 'parent').get();
console.log(`Found ${parentsSnapshot.size} parent users.`);
parentsSnapshot.forEach((doc, index) => {
const data = doc.data();
console.log(`\nParent ${index + 1}:`);
console.log(` ID: ${doc.id}`);
console.log(` Name: ${data.name}`);
console.log(` UID: ${data.uid}`);
console.log(` Child Profile IDs: ${JSON.stringify(data.childProfileIds || [])}`);
});
} catch (error) {
console.error('Error checking profiles:', error);
} finally {
// Exit process to avoid hanging
process.exit(0);
}
}
// Run the function
checkChildProfiles();