fix bug addRessource

This commit is contained in:
trochas
2025-12-15 15:42:18 +01:00
parent 5271fe1f54
commit b7eb0be157
5 changed files with 58 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
import { addDoc, arrayUnion, collection, doc, Firestore, getDoc, getDocs, Timestamp, updateDoc, DocumentReference, query, where } from "firebase/firestore";
import { addDoc, arrayUnion, collection, doc, DocumentReference, getDoc, getDocs, query, Timestamp, updateDoc, where } from "firebase/firestore";
import { Chantier, Reservation, Ressources, User } from "../class/class";
import { db } from "../firebase_config";
@@ -40,10 +40,15 @@ export async function getRessources(): Promise<Ressources[]> {
}
//ADD RESSOURCES
export async function addRessources(ressourceData: Omit<Ressources, 'id'>): Promise<string | null> {
export async function addRessources(ressourceData: Ressources): Promise<string | null> {
try {
const colRef = collection(db, "ressources");
const ressourcesRef = await addDoc(colRef, ressourceData);
const ressourcesRef = await addDoc(collection(db, "ressources"), {
name:ressourceData.name,
type:ressourceData.type,
Image: ressourceData.Image,
quantity: ressourceData.quantity,
});
console.log(`Ressource ajoutée avec ID: ${ressourcesRef.id}`);
return ressourcesRef.id;
} catch (err) {
@@ -260,6 +265,10 @@ export async function sendNewChantier(chantier:Chantier): Promise<void> {
}
export async function sendNewReservation(list: Reservation[],chantierId:string): Promise<void> {
list.forEach(reservation => {
console.log("log: " + reservation.ressource.id);
});
const promises = list.map((reservation) =>
addDoc(collection(db,"Reservation"),{
chantier: doc(db, "chantier", chantierId),