fini fontionnalité de anomalie, ptet changer styles
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { addDoc, collection, doc, getDoc, getDocs, Timestamp, updateDoc } from "firebase/firestore";
|
||||
import { addDoc, arrayUnion, collection, doc, getDoc, getDocs, Timestamp, updateDoc } from "firebase/firestore";
|
||||
import { Chantier, Reservation, Ressources, User } from "../class/class";
|
||||
import { db } from "../firebase_config";
|
||||
|
||||
@@ -78,7 +78,7 @@ export async function changeChantierStatus(chantierId: string, newStatus: string
|
||||
try {
|
||||
const chantierRef = doc(db, "chantier", chantierId);
|
||||
await updateDoc(chantierRef, { etat: newStatus });
|
||||
console.log(`Chantier ${chantierId} status updated to ${newStatus}`);
|
||||
console.log("Chantier ${chantierId} status updated to ${newStatus}");
|
||||
} catch (err) {
|
||||
console.error("Error", err);
|
||||
}
|
||||
@@ -98,30 +98,19 @@ export async function addChantier(chantierData: Omit<Chantier, 'id'>): Promise<s
|
||||
}
|
||||
|
||||
//CHANGE CHANTIER ANOMALIE STATUS
|
||||
export async function changeAnomalieStatus(chantierId: string, anomalie_String: string, newStatus: string): Promise<void> {
|
||||
export async function addAnomalie(chantierId: string, anomalie_String: string): Promise<void> {
|
||||
try {
|
||||
const chantierRef = doc(db, "chantier", chantierId);
|
||||
const chantierSnap = await getDoc(chantierRef);
|
||||
if (chantierSnap.exists()) {
|
||||
const chantierData = chantierSnap.data();
|
||||
const anomalies = chantierData.anomalies || [];
|
||||
const updatedAnomalies = anomalies.map((anomalie: any) => {
|
||||
if (anomalie.description === anomalie_String) {
|
||||
return { ...anomalie, status: newStatus };
|
||||
}
|
||||
return anomalie;
|
||||
});
|
||||
await updateDoc(chantierRef, { anomalies: updatedAnomalies });
|
||||
console.log(`Anomalie status updated to ${newStatus}`);
|
||||
} else {
|
||||
console.error("Chantier not found");
|
||||
}
|
||||
await updateDoc(chantierRef, {
|
||||
anomalies: arrayUnion(anomalie_String)
|
||||
});
|
||||
console.log("Anomalie added");
|
||||
} catch (err) {
|
||||
console.error("Error", err);
|
||||
console.error("Error adding anomalie:", err);
|
||||
}
|
||||
}
|
||||
|
||||
//CHANGE CHANTIER ANOMALIE STATUS
|
||||
//DELETE CHANTIER ANOMALIE STATUS
|
||||
export async function deleteAnomalie(chantierId: string, anomalie_String: string): Promise<void> {
|
||||
try {
|
||||
const chantierRef = doc(db, "chantier", chantierId);
|
||||
@@ -129,9 +118,10 @@ export async function deleteAnomalie(chantierId: string, anomalie_String: string
|
||||
if (chantierSnap.exists()) {
|
||||
const chantierData = chantierSnap.data();
|
||||
const anomalies = chantierData.anomalies || [];
|
||||
const updatedAnomalies = anomalies.filter((anomalie: any) => anomalie.description !== anomalie_String);
|
||||
//Filtage
|
||||
const updatedAnomalies = anomalies.filter((anomaly: string) => anomaly !== anomalie_String);
|
||||
await updateDoc(chantierRef, { anomalies: updatedAnomalies });
|
||||
console.log(`Anomalie deleted`);
|
||||
console.log("Anomalie deleted");
|
||||
} else {
|
||||
console.error("Chantier not found");
|
||||
}
|
||||
@@ -148,4 +138,4 @@ function convertReservation(res: any): Reservation {
|
||||
dateFin:
|
||||
res.dateFin instanceof Timestamp ? res.dateFin.toDate() : new Date(res.dateFin),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user