recommendations.ts

import {
  RECOMMENDATION_MAX_SIZE,
  POPULAR,
  TRENDING,
  LATEST,
  LENGTHY,
  MARVELOUS,
  MULTISTARRER
} from '../../utility/constants/values';

async function getCollectionData(context, category) {
  const { firestore, envmt, activeDbId } = context;
  const rows = [];
  const snapshot = await firestore
    .collection(`${envmt}-${category}-${activeDbId}`)
    .orderBy('weight', 'desc')
    // Fetch all
    //.limit(RECOMMENDATION_MAX_SIZE)
    .get();

  snapshot.forEach((doc) => {
    const video = doc.data();
    rows.push(video);
  });

  return rows;
}

export async function getRecommendations(context) {
  const [popular, trending, latest, lengthy, marvelous, multistarrer] = await Promise.all([
    getCollectionData(context, POPULAR),
    getCollectionData(context, TRENDING),
    getCollectionData(context, LATEST),
    getCollectionData(context, LENGTHY),
    getCollectionData(context, MARVELOUS),
    getCollectionData(context, MULTISTARRER)
  ]);

  return {
    popular,
    trending,
    latest,
    lengthy,
    marvelous,
    multistarrer
  };
}