Hooked training content to backend, did refactors to training components and record.tsx
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user