import {app} from "@/firebase";
import {Code} from "@/interfaces/user";
import {collection, getDocs, getFirestore, query, where} from "firebase/firestore";

const db = getFirestore(app);

export const getUserCodes = async (id: string): Promise<Code[]> => {
	const codeDocs = await getDocs(query(collection(db, "codes"), where("creator", "==", id)));
	return codeDocs.docs.map((x) => ({...(x.data() as Code), id})) as Code[];
};
