change and delete anomaly
This commit is contained in:
@@ -13,9 +13,7 @@ Lien du git : gitlab2.istic.univ-rennes1.fr/trochas/mmm-projet
|
|||||||
|
|
||||||
Différentes commandes a effectuer pour lancer le 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
|
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
|
npx expo start
|
||||||
@@ -4,7 +4,6 @@ import React from 'react';
|
|||||||
import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
||||||
import { ThemedText } from './themed-text';
|
import { ThemedText } from './themed-text';
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: {
|
data: {
|
||||||
chantier:Chantier|null;
|
chantier:Chantier|null;
|
||||||
@@ -13,8 +12,6 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function ChantierSummary({data,style , ...otherProps }: Props) {
|
export default function ChantierSummary({data,style , ...otherProps }: Props) {
|
||||||
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<View style={style}>
|
<View style={style}>
|
||||||
{data.chantier ? (
|
{data.chantier ? (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { addDoc, collection, doc, getDoc, getDocs, Timestamp, updateDoc } from "
|
|||||||
import { Chantier, Reservation, Ressources, User } from "../class/class";
|
import { Chantier, Reservation, Ressources, User } from "../class/class";
|
||||||
import { db } from "../firebase_config";
|
import { db } from "../firebase_config";
|
||||||
|
|
||||||
|
///////////////////////////////////USER/////////////////////////////////////
|
||||||
export async function getUsers(): Promise<User[]> {
|
export async function getUsers(): Promise<User[]> {
|
||||||
try {
|
try {
|
||||||
const colRef = collection(db, "user");
|
const colRef = collection(db, "user");
|
||||||
@@ -18,7 +19,7 @@ export async function getUsers(): Promise<User[]> {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
///////////////////////////////////RESSOURCE////////////////////////////////
|
||||||
export async function getRessources(): Promise<Ressources[]> {
|
export async function getRessources(): Promise<Ressources[]> {
|
||||||
try {
|
try {
|
||||||
const colRef = collection(db, "ressources");
|
const colRef = collection(db, "ressources");
|
||||||
@@ -35,7 +36,7 @@ export async function getRessources(): Promise<Ressources[]> {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
///////////////////////////////////CHANTIER/////////////////////////////////
|
||||||
export async function getChantiers(): Promise<Chantier[]> {
|
export async function getChantiers(): Promise<Chantier[]> {
|
||||||
const snap = await getDocs(collection(db, "chantier"));
|
const snap = await getDocs(collection(db, "chantier"));
|
||||||
const chantiers: Chantier[] = [];
|
const chantiers: Chantier[] = [];
|
||||||
@@ -72,16 +73,7 @@ export async function getChantiers(): Promise<Chantier[]> {
|
|||||||
return chantiers;
|
return chantiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertReservation(res: any): Reservation {
|
//CHANGE CHANTIER STATUS
|
||||||
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),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function changeChantierStatus(chantierId: string, newStatus: string): Promise<void> {
|
export async function changeChantierStatus(chantierId: string, newStatus: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const chantierRef = doc(db, "chantier", chantierId);
|
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<Chantier, 'id'>): Promise<string | null> {
|
export async function addChantier(chantierData: Omit<Chantier, 'id'>): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const colRef = collection(db, "chantier");
|
const colRef = collection(db, "chantier");
|
||||||
@@ -102,4 +95,57 @@ export async function addChantier(chantierData: Omit<Chantier, 'id'>): Promise<s
|
|||||||
console.error("Error adding:", err);
|
console.error("Error adding:", err);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CHANGE CHANTIER ANOMALIE STATUS
|
||||||
|
export async function changeAnomalieStatus(chantierId: string, anomalie_String: string, newStatus: 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");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHANGE CHANTIER ANOMALIE STATUS
|
||||||
|
export async function deleteAnomalie(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.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),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user