test firebase
This commit is contained in:
21
services/ressourcesService.ts
Normal file
21
services/ressourcesService.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { collection, getDocs } from "firebase/firestore";
|
||||
import { db } from "../firebase_config";
|
||||
|
||||
export type Ressource = {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
Image: string;
|
||||
};
|
||||
|
||||
export async function getRessources(): Promise<Ressource[]> {
|
||||
try {
|
||||
const ressourcesCol = collection(db, "ressources");
|
||||
const snapshot = await getDocs(ressourcesCol);
|
||||
const list = snapshot.docs.map((doc) => doc.data() as Ressource);
|
||||
return list;
|
||||
} catch (err) {
|
||||
console.log("Firestore Error:", err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user