Skip to content
Snippets Groups Projects
Commit 279f94c8 authored by Bálint Sándor's avatar Bálint Sándor
Browse files

Started to work on fetch functions

parent 8e74f2dc
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
allow read, write: if true;
}
}
}
\ No newline at end of file
import { Placement } from "./Placement";
export interface Event {
placement: Placement; //The Placement the event relates to
relatedBelongings: string[]; //The belongings related to the event
wasHandedIn: boolean; //The direction of transaction
}
export interface Placement {
active: boolean; //Whether the Placement is still active
barcode: string; //The barcode the person used to hand in their belongings
person: string; //The person's name
placementNumber: string; //The placement number on the fogas
belongings: string[]; //The persons's belongings
}
......@@ -9,6 +9,7 @@ import React, { useEffect, useState } from "react";
import { useAuthState } from "react-firebase-hooks/auth";
import { useHistory } from "react-router";
import { auth, db, logout } from "../config/firebase-config";
import { getAllPlacements } from "../queries/getAllPlacements";
function Dashboard() {
const [user, loading, error] = useAuthState(auth);
......@@ -33,9 +34,14 @@ function Dashboard() {
};
useEffect(() => {
const fetchData = async () => {
const data = await getAllPlacements();
console.log(data);
};
if (loading) return;
if (!user) return history.replace("/");
fetchUserName();
fetchData();
}, [user, loading]);
return (
......
import { Placement } from "./../data/Placement";
import { collection, query, getDocs } from "firebase/firestore";
import { db } from "../config/firebase-config";
export const getAllPlacements = async () => {
const documentSnapshot = await getDocs(query(collection(db, "placements")));
const data: any = [];
documentSnapshot.forEach((doc) => {
const id = doc.id;
const placement = { id, ...doc.data() };
data.push(placement);
});
return data;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment