merge + home

This commit is contained in:
trochas
2025-12-09 14:16:58 +01:00
6 changed files with 314 additions and 368 deletions

View File

@@ -1,155 +1,125 @@
export class Chantier{
id: number;
adresse: string;
etat: string;
contact: string;
chef: Chef;
equipe : Equipier[];
materiel : Materiel[];
dateDep : string;
tempsEst : number;
vehicules : Vehicule[];
anomalies : string[];
urlImg : string;
import { collection, getDocs, Timestamp } from "firebase/firestore";
import { db } from "../firebase_config";
constructor(
id: number,
adresse: string,
etat: string,
contact: string,
chef: Chef,
equipe: Equipier[],
materiel: Materiel[],
dateDep: string,
tempsEst: number,
vehicules: Vehicule[],
anomalies: string[],
urlImg: string
) {
this.id = id;
this.adresse = adresse;
this.etat = etat;
this.contact = contact;
this.chef = chef;
this.equipe = equipe;
this.materiel = materiel;
this.dateDep = dateDep;
this.tempsEst = tempsEst;
this.vehicules = vehicules;
this.anomalies = anomalies;
this.urlImg = urlImg;
}
export type Chantier = {
id: number;
adresse: string;
etat: string;
contact: string;
chef: User;
equipe: User[];
materiel: Ressources[];
dateDep: Date;
tempsEst: number;
vehicules: Ressources[];
anomalies: string[];
};
export async function getChantiers(): Promise<Chantier[]> {
try {
const colRef = collection(db, "chantier");
const snapshot = await getDocs(colRef);
return snapshot.docs.map((doc) => {
const data = doc.data() as any;
return {
...data,
chef: {
...data.chef,
allocation: data.chef?.allocation?.map(convertReservation) || [],
},
equipe:
data.equipe?.map((u: any) => ({
...u,
allocation: u.allocation?.map(convertReservation) || [],
})) || [],
materiel:
data.materiel?.map((m: any) => ({
...m,
allocation: m.allocation?.map(convertReservation) || [],
})) || [],
vehicules:
data.vehicules?.map((v: any) => ({
...v,
allocation: v.allocation?.map(convertReservation) || [],
})) || [],
anomalies: data.anomalies || [],
} as Chantier;
});
} catch (err) {
console.error("Firestore Chantiers Error:", err);
return [];
}
}
export abstract class Equipier{
id: number;
nom: string;
prenom: string;
allocation: Reservation[];
export type User = {
id: string;
name: string;
last_name: string;
allocation: Reservation[];
role: string;
qualifications: string;
};
constructor(id: number, nom:string, prenom:string, allocation: Reservation[]){
this.id = id;
this.nom = nom;
this.prenom = prenom;
this.allocation = allocation;
}
export async function getUsers(): Promise<User[]> {
try {
const colRef = collection(db, "user");
const snapshot = await getDocs(colRef);
return snapshot.docs.map((doc) => {
const data = doc.data();
return {
...data,
allocation: data.allocation?.map(convertReservation) || [],
} as User;
});
} catch (err) {
console.error("Firestore Users Error:", err);
return [];
}
}
export class Chef extends Equipier{
constructor(id: number, nom:string, prenom:string, allocation: Reservation[]){
super(id,nom,prenom,allocation);
}
export type Ressources = {
id: number;
name: string;
type: string;
Image: string;
quantity: number;
available_quantity: number;
allocation: Reservation[];
};
export async function getRessources(): Promise<Ressources[]> {
try {
const colRef = collection(db, "ressources");
const snapshot = await getDocs(colRef);
return snapshot.docs.map((doc) => {
const data = doc.data();
return {
...data,
allocation: data.allocation?.map(convertReservation) || [],
} as Ressources;
});
} catch (err) {
console.error("Firestore Ressources Error:", err);
return [];
}
}
export class Ouvrier extends Equipier{
qualification : string;
export type Reservation = {
id: string;
dateChantier: Date;
dateFin: Date;
};
constructor(id: number, nom:string, prenom:string, allocation: Reservation[], qualification: string){
super(id,nom,prenom,allocation);
this.qualification=qualification;
}
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),
};
}
export class ResponsableChantier extends Equipier{
constructor(id: number, nom:string, prenom:string, allocation: Reservation[]){
super(id,nom,prenom,allocation);
}
}
export class Materiel {
id: number;
nom: string;
prenom: string;
type: string;
allocation: Reservation[];
constructor(
id: number,
nom: string,
prenom: string,
type: string,
allocation: Reservation[]
) {
this.id = id;
this.nom = nom;
this.prenom = prenom;
this.type = type;
this.allocation = allocation;
}
}
export class Reservation {
id: string;
dateChantier: Date;
dateFin: Date;
duree: number;
constructor(
id: string,
dateChantier: Date,
dateFin: Date,
duree: number
) {
this.id = id;
this.dateChantier = dateChantier;
this.dateFin = dateFin;
this.duree = duree;
}
}
export class Vehicule {
id: number;
nom: string;
type: string;
allocation: Reservation[];
constructor(
id: number,
nom: string,
type: string,
allocation: Reservation[]
) {
this.id = id;
this.nom = nom;
this.type = type;
this.allocation = allocation;
}
}
export const exempleChantier = new Chantier(
1,
"Rennes",
"en cours",
"contact",
new Chef(1,"Chyeef","YEE",[]),
[],
[],
"01/01/25",
10,
[],
["YEE"],
"https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=69392bb2&is=6937da32&hm=dcc09e76d3dca89d2418947b46efbd38673b9dc559027724b2e51d493b173bc9&"
)