active-db.ts

import { SYSTEM_STATE } from '../../utility/constants/values';

export async function setActiveDb(context, activeDbId) {
  const { firestore, envmt } = context;
  const document = {
    id: activeDbId
  };
  const collectionName = `${envmt}-${SYSTEM_STATE}`;
  const docRef = firestore.collection(collectionName).doc(`${envmt}-active-db`);
  await docRef.set(document);

  return getActiveDb(context);
}

export async function getActiveDb(context) {
  const { firestore, envmt } = context;
  const docRef = firestore.collection(`${envmt}-${SYSTEM_STATE}`).doc(`${envmt}-active-db`);

  const snapshot = await docRef.get();
  return await snapshot.data();
}