All files / src/utils firestore-helpers.js

100% Statements 7/7
100% Branches 2/2
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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            4x             2x 2x               6x 7x     4x  
/**
 * Shared Firestore helper functions.
 *
 * Extracted from users.js, reports.js, banners.js, config.js, etc. to eliminate duplication.
 */
 
const { db } = require('./firebase');
 
/**
 * Get a single Firestore document by path.
 * Returns { id, ...data } or null if the document doesn't exist.
 */
async function getDoc(path) {
  const snap = await db.doc(path).get();
  return snap.exists ? { id: snap.id, ...snap.data() } : null;
}
 
/**
 * Execute a Firestore query reference and return all matching documents
 * as an array of { id, ...data } objects.
 */
async function queryDocs(ref) {
  const snap = await ref.get();
  return snap.docs.map((d) => ({ id: d.id, ...d.data() }));
}
 
module.exports = { getDoc, queryDocs };