Hooked training content to backend, did refactors to training components and record.tsx

This commit is contained in:
Carlos Mesquita
2024-08-01 20:40:31 +01:00
parent a534126c61
commit a71e6632d6
13 changed files with 1243 additions and 821 deletions

View File

@@ -1,7 +1,7 @@
import { sessionOptions } from "@/lib/session";
import axios from "axios";
import {app} from "@/firebase";
import { collection, getDocs, getFirestore, query } from "firebase/firestore";
import { app } from "@/firebase";
import { collection, doc, getDoc, getDocs, getFirestore, query } from "firebase/firestore";
import { withIronSessionApiRoute } from "iron-session/next";
import { NextApiRequest, NextApiResponse } from "next";
@@ -35,16 +35,17 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
async function get(req: NextApiRequest, res: NextApiResponse) {
try {
const q = query(collection(db, "training"));
const snapshot = await getDocs(q);
res.status(200).json(
snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
})),
}))
);
} catch (error) {
console.error('Error fetching data:', error);
res.status(500).json({ message: 'An unexpected error occurred' });
}
}