From bc566c4f7fb6850c60dbd05ae87c969c13c4cebb Mon Sep 17 00:00:00 2001 From: tuanvu Date: Thu, 11 Dec 2025 21:19:11 +0100 Subject: [PATCH] change and delete anomaly --- README.md | 4 +- components/chantierSummary.tsx | 3 -- services/ressourcesService.ts | 72 ++++++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b45824f..01cee85 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,7 @@ Lien du git : gitlab2.istic.univ-rennes1.fr/trochas/mmm-projet Différentes commandes a effectuer pour lancer le projet: -npm install firebase -npm install react-native-maps npx expo install react-native-maps@1.9.0 -npm install react-native-maps @react-navigation/native @react-navigation/bottom-tabs react-native-safe-area-context react-native-screens +npm install react-native-maps @react-navigation/native @react-navigation/bottom-tabs react-native-safe-area-context react-native-screens firebase npx expo start \ No newline at end of file diff --git a/components/chantierSummary.tsx b/components/chantierSummary.tsx index 66ced7d..f09870e 100644 --- a/components/chantierSummary.tsx +++ b/components/chantierSummary.tsx @@ -4,7 +4,6 @@ import React from 'react'; import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { ThemedText } from './themed-text'; - type Props = { data: { chantier:Chantier|null; @@ -13,8 +12,6 @@ type Props = { }; export default function ChantierSummary({data,style , ...otherProps }: Props) { - - return( {data.chantier ? ( diff --git a/services/ressourcesService.ts b/services/ressourcesService.ts index 36ae527..2a32e8d 100644 --- a/services/ressourcesService.ts +++ b/services/ressourcesService.ts @@ -2,6 +2,7 @@ import { addDoc, collection, doc, getDoc, getDocs, Timestamp, updateDoc } from " import { Chantier, Reservation, Ressources, User } from "../class/class"; import { db } from "../firebase_config"; +///////////////////////////////////USER///////////////////////////////////// export async function getUsers(): Promise { try { const colRef = collection(db, "user"); @@ -18,7 +19,7 @@ export async function getUsers(): Promise { return []; } } - +///////////////////////////////////RESSOURCE//////////////////////////////// export async function getRessources(): Promise { try { const colRef = collection(db, "ressources"); @@ -35,7 +36,7 @@ export async function getRessources(): Promise { return []; } } - +///////////////////////////////////CHANTIER///////////////////////////////// export async function getChantiers(): Promise { const snap = await getDocs(collection(db, "chantier")); const chantiers: Chantier[] = []; @@ -72,16 +73,7 @@ export async function getChantiers(): Promise { return chantiers; } -function convertReservation(res: any): Reservation { - return { - id: res.id, - dateChantier: - res.dateChantier instanceof Timestamp ? res.dateChantier.toDate() : new Date(res.dateChantier), - dateFin: - res.dateFin instanceof Timestamp ? res.dateFin.toDate() : new Date(res.dateFin), - }; -} - +//CHANGE CHANTIER STATUS export async function changeChantierStatus(chantierId: string, newStatus: string): Promise { try { const chantierRef = doc(db, "chantier", chantierId); @@ -92,6 +84,7 @@ export async function changeChantierStatus(chantierId: string, newStatus: string } } +//ADD CHANTIER export async function addChantier(chantierData: Omit): Promise { try { const colRef = collection(db, "chantier"); @@ -102,4 +95,57 @@ export async function addChantier(chantierData: Omit): Promise { + 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"); + } + } catch (err) { + console.error("Error", err); + } +} + +//CHANGE CHANTIER ANOMALIE STATUS +export async function deleteAnomalie(chantierId: string, anomalie_String: string): Promise { + 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.filter((anomalie: any) => anomalie.description !== anomalie_String); + await updateDoc(chantierRef, { anomalies: updatedAnomalies }); + console.log(`Anomalie deleted`); + } else { + console.error("Chantier not found"); + } + } catch (err) { + console.error("Error", err); + } +} + +function convertReservation(res: any): Reservation { + return { + id: res.id, + dateChantier: + res.dateChantier instanceof Timestamp ? res.dateChantier.toDate() : new Date(res.dateChantier), + dateFin: + res.dateFin instanceof Timestamp ? res.dateFin.toDate() : new Date(res.dateFin), + }; +}