File Extension Image for pack.js pack.js
878 Chars | 38 Lines | 0.88 kb | Text File Parent Directory
import { db } from './firebase'
import { getDocs, collection, query, where } from 'firebase/firestore'

async function getMyPacks(user) {
	let packs = []
	const userPacks = await getDocs(collection(db, 'packs', user, 'packs'))
	userPacks.forEach((doc) => {
		packs.push(doc.data())
	})

	return packs
}

async function getUsersPacks(user) {
	let packs = []
	const userPacks = await getDocs(
		query(collection(db, 'packs', user, 'packs'), where('published', '==', true))
	)
	userPacks.forEach((doc) => {
		packs.push(doc.data())
	})

	return packs
}

async function getPacks(user) {
	let packs = []
	const userPacks = await getDocs(
		query(collection(db, 'packs', user, 'packs'), where('published', '==', true))
	)
	userPacks.forEach((doc) => {
		packs.push(doc.data())
	})

	return packs
}

export { getMyPacks, getUsersPacks, getPacks }