Przeglądaj źródła

(fix) ajouter un vehicule à sa compagnie

Brin AMONKONAN 1 rok temu
rodzic
commit
d8880eb051

+ 2 - 2
app_transport_front/index.html

@@ -4,7 +4,7 @@
     <meta charset="UTF-8">
     <link rel="icon" href="/favicon.ico">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Transport App</title>
+    <title>DabidjanApp</title>
     <link rel="icon" type="image/png" href="/assets/images/logo.png" />
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
   </head>
@@ -18,7 +18,7 @@
     <meta charset="UTF-8">
     <link rel="icon" href="/favicon.ico">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Transport App</title>
+    <title>DabidjanApp</title>
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
     <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
   </head>

+ 2 - 2
app_transport_front/src/components/Sidebar.vue

@@ -5,7 +5,7 @@
         <!-- <img src="/assets/images/logo.png" alt="Logo" /> -->
         <router-link to="/" class="menu-item" :class="{ active: currentRoute === '/dashboard' }">
         <span v-if="useUserCompanyStore().name">{{ useUserCompanyStore().name  }}</span>
-        <span v-else>Transport App</span>
+        <span v-else>DabidjanApp</span>
         </router-link>
       </div>
     </div>
@@ -77,7 +77,7 @@
 
 <script setup lang="ts">
 import { Role } from '@/Enum/Role'
-import { useUserCompanyStore } from '@/stores/userCompanyStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 import { useUserStore } from '@/stores/useUserStore'
 import { computed, onBeforeMount } from 'vue'
 import { useRoute } from 'vue-router'

+ 26 - 26
app_transport_front/src/components/VehicleModal.vue

@@ -29,7 +29,7 @@
         <div class="form-row">
           <div class="form-group">
             <label>Immatriculation <span class="required">*</span></label>
-            <input type="text" v-model="formData.licensePlate" required>
+            <input type="text" v-model="formData.immatriculation" required>
           </div>
           <div class="form-group">
             <label>Année <span class="required">*</span></label>
@@ -65,7 +65,7 @@
         <div class="form-row">
           <div class="form-group">
             <label>Capacité</label>
-            <input type="number" v-model="formData.capacity">
+            <input type="number" v-model="formData.number_places">
           </div>
           <div class="form-group">
             <label>Couleur</label>
@@ -101,7 +101,7 @@
 
 <script setup lang="ts">
 import { Role } from '@/Enum/Role'
-import { useUserCompanyStore } from '@/stores/userCompanyStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 import { useUserStore } from '@/stores/useUserStore'
 import { ref, watch, defineProps, defineEmits } from 'vue'
 
@@ -119,11 +119,11 @@ interface VehicleData {
   id: number | null
   brand: string
   model: string
-  licensePlate: string
+  immatriculation: string
   year: number
   type: string
   companyId: number | string
-  capacity: number | null
+  number_places: number | null
   color: string
   status: string
   image: string | null
@@ -152,17 +152,36 @@ const formData = ref<VehicleData>({
   id: null,
   brand: '',
   model: '',
-  licensePlate: '',
+  immatriculation: '',
   year: new Date().getFullYear(),
   type: 'van',
   companyId: companyAuth.id ?? 0,
-  capacity: null,
+  number_places: 0,
   color: '',
   status: 'active',
   image: null,
   notes: ''
 })
 
+const resetForm = () => {
+  if (!props.vehicle) {
+    formData.value = {
+      id: null,
+      brand: '',
+      model: '',
+      immatriculation: '',
+      year: new Date().getFullYear(),
+      type: 'van',
+      companyId: '',
+      number_places: null,
+      color: '',
+      status: 'active',
+      image: null,
+      notes: ''
+    }
+  }
+}
+
 // Observer les changements de props.vehicle pour mettre à jour le formulaire
 watch(() => props.vehicle, (newVehicle) => {
   if (newVehicle) {
@@ -186,25 +205,6 @@ watch(() => props.show, (newShow) => {
   }
 })
 
-const resetForm = () => {
-  if (!props.vehicle) {
-    formData.value = {
-      id: null,
-      brand: '',
-      model: '',
-      licensePlate: '',
-      year: new Date().getFullYear(),
-      type: 'van',
-      companyId: '',
-      capacity: null,
-      color: '',
-      status: 'active',
-      image: null,
-      notes: ''
-    }
-  }
-}
-
 const close = () => {
   emit('close')
 }

+ 1 - 1
app_transport_front/src/main.ts

@@ -37,7 +37,7 @@ app.config.errorHandler = (err, instance, info) => {
 }
 
 // Propriétés globales
-app.config.globalProperties.$appName = 'Transport App'
+app.config.globalProperties.$appName = 'DabidjanApp'
 app.config.globalProperties.$appVersion = '1.0.0'
 
 // Montage de l'application

+ 0 - 0
app_transport_front/src/stores/userCompanyStore.ts → app_transport_front/src/stores/useCompanyStore.ts


+ 1 - 0
app_transport_front/src/stores/useUserStore.ts

@@ -34,6 +34,7 @@ export const useUserStore = defineStore('user', {
       this.name = data.name
       this.otherName = data.otherName
       this.companyId = data.companyId || null
+      console.log('companyId:', data)
     },
     clearUser() {
       this.$reset()

+ 2 - 5
app_transport_front/src/stores/useVehiculeStore.ts

@@ -11,12 +11,12 @@ export interface Vehicule {
   model: string
   companyId: number
   driverId: number
-  //status?: string
+  status?: string
 }
 
 export const useVehiculeStore = defineStore('vehicule', () => {
   const vehicules = ref<Vehicule[]>([])
-  const isLoading = ref(false)
+  const isLoading = ref<boolean>(false)
   const error = ref<string | null>(null)
 
   // Récupérer tous les véhicules
@@ -71,9 +71,6 @@ export const useVehiculeStore = defineStore('vehicule', () => {
       
       const data = await response.json()
       
-      // Ajouter le nouveau véhicule à la liste
-      vehicules.value.push(data.data)
-      
       return data.data
     } catch (err: any) {
       error.value = err.message || 'Une erreur est survenue lors de la création du véhicule'

+ 1 - 1
app_transport_front/src/views/CompanySetupView.vue

@@ -34,7 +34,7 @@
 
 <script setup lang="ts">
 import router from '@/router'
-import { useUserCompanyStore } from '@/stores/userCompanyStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 import { useUserStore } from '@/stores/useUserStore'
 import { ref } from 'vue'
 const authUser = useUserStore()

+ 2 - 2
app_transport_front/src/views/HomeView.vue

@@ -36,7 +36,7 @@
                 <div class="left-content show-up header-text">
                   <div class="row">
                     <div class="col-lg-12">
-                      <h2>Transport App Dev</h2>
+                      <h2>DabidjanApp Dev</h2>
                       <p>Réservez vos trajets en toute simplicité avec notre application de transport moderne et intuitive.</p>
                     </div>
                     <div class="col-lg-12">
@@ -299,7 +299,7 @@
       <div class="container">
         <div class="row">
           <div class="col-lg-12">
-            <p>Copyright © 2023 Transport App Dev. Tous droits réservés.</p>
+            <p>Copyright © 2023 DabidjanApp Dev. Tous droits réservés.</p>
           </div>
         </div>
       </div>

+ 1 - 1
app_transport_front/src/views/LoginView.vue

@@ -53,7 +53,7 @@ import { Role } from '@/Enum/Role'
 import { ref, computed } from 'vue'
 import { useRouter } from 'vue-router'
 import { useUserStore } from '@/stores/useUserStore'
-import { useUserCompanyStore } from '@/stores/userCompanyStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 
 const router = useRouter()
 const email = ref('')

+ 1 - 1
app_transport_front/src/views/StationCompanyView.vue

@@ -182,7 +182,7 @@ import PaginationComponent from '@/components/PaginationComponent.vue'
 import { useUserStore } from '@/stores/useUserStore'
 import { useStationStore } from '@/stores/useStationStore'
 import { Role } from '@/Enum/Role'
-import { useUserCompanyStore } from '@/stores/userCompanyStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 
 const userStore = useUserStore()
 const stationStore = useStationStore()

+ 41 - 38
app_transport_front/src/views/VehicleView.vue

@@ -239,10 +239,11 @@ import Sidebar from '@/components/Sidebar.vue'
 import TopBar from '@/components/TopBar.vue'
 import VehicleModal from '@/components/VehicleModal.vue'
 import { useUserStore } from '@/stores/useUserStore'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 import { Role } from '@/Enum/Role'
 import { useVehiculeStore, Vehicule } from '@/stores/useVehiculeStore'
 import VehiculeService from '@/services/VehiculeService'
-import CompanyService from '@/services/CompanyService'
+//import CompanyService from '@/services/CompanyService'
 import type { Vehicle, Company } from '@/types'
 
 // Variables réactives pour les données
@@ -266,27 +267,27 @@ const typeFilter = ref('')
 const statusFilter = ref('')
 
 // États pour les modals
-const showAddForm = ref(false)
-const editingVehicle = ref(null)
-const deletingVehicle = ref(null)
-const viewingVehicle = ref(null)
+const showAddForm = ref<boolean>(false)
+const editingVehicle = ref<Vehicle | null>(null)
+const deletingVehicle = ref<Vehicle | null>(null)
+const viewingVehicle = ref<Vehicle | null>(null)
 
 // Formulaire
 const formData = ref({
   id: null,
   brand: '',
   model: '',
-  licensePlate: '',
+  number_places: 0,
   year: new Date().getFullYear(),
   type: 'van',
   companyId: '',
-  capacity: null,
+  immatriculation: '',
   color: '',
   status: 'active',
   image: null,
   notes: ''
 })
-const vehicleStore = useVehiculeStore()
+ useVehiculeStore().fetchVehicles()
 
 // Fonctions pour charger les données
 const loadVehicles = async () => {
@@ -300,7 +301,8 @@ const loadVehicles = async () => {
       result = await VehiculeService.getVehicles(pagination.value.page, pagination.value.limit)
     } else {
       // Récupérer l'ID de l'entreprise de l'utilisateur connecté
-      const companyId = userStore.companyId || 1 // Fallback temporaire
+      const companyId = useUserCompanyStore().id
+      console.log('ID de l\'entreprise:',companyId)
       result = await VehiculeService.getVehiclesByCompany(companyId, pagination.value.page, pagination.value.limit)
       console.log('Véhicules de l\'entreprise:', result)
     }
@@ -314,31 +316,32 @@ const loadVehicles = async () => {
   }
 }
 
-const loadCompanies = async () => {
-  try {
-    const result = await CompanyService.getCompanies(1, 100) // Charger toutes les entreprises
-    companies.value = result.companies
-  } catch (error) {
-    console.error('Erreur lors du chargement des entreprises:', error)
-  }
-}
+// const loadCompanies = async () => {
+//   try {
+//     const result = await CompanyService.getCompanies(1, 100) // Charger toutes les entreprises
+//     companies.value = result.companies
+//   } catch (error) {
+//     console.error('Erreur lors du chargement des entreprises:', error)
+//   }
+// }
+
+const createNewVehicle = async (vehicule: Vehicle) => {
 
-const createNewVehicle = async (vehicule) => {
   try {
     // Transformation des données pour correspondre au format attendu par le backend
     const vehiculeData: Vehicule = {
-      number_places: vehicule.capacity || 0,
+      number_places: vehicule.number_places || 0,
       color: vehicule.color || '',
       type: vehicule.type || '',
-      immatriculation: vehicule.licensePlate || '',
+      immatriculation: vehicule.immatriculation || '',
       model: `${vehicule.model}` || '',
-      companyId: vehicule.companyId || userStore.companyId || 1,
+      companyId: useUserCompanyStore().id,
       driverId: 0
     }
     
     console.log('Données envoyées au backend:', vehiculeData)
     
-    const newVehicle = await vehicleStore.createVehicle(vehiculeData)
+    const newVehicle = await useVehiculeStore().createVehicle(vehiculeData)
     
     console.log('Véhicule créé avec succès:', newVehicle)
     // Recharger la liste après création
@@ -377,32 +380,32 @@ const getCompanyName = (companyId) => {
   return company ? company.name : 'Inconnue'
 }
 
-const getVehicleTypeName = (type) => {
+const getVehicleTypeName = (type: string) => {
   const types = {
     car: 'Voiture',
     van: 'Fourgon',
     bus: 'Bus',
     truck: 'Camion'
   }
-  return types[type] || type
+  return types[type as keyof typeof types] || type
 }
 
-const getStatusName = (status) => {
+const getStatusName = (status: string) => {
   const statuses = {
     active: 'Actif',
     inactive: 'Inactif',
     maintenance: 'En maintenance'
   }
-  return statuses[status] || status
+  return statuses[status as keyof typeof statuses] || status
 }
 
-const getStatusClass = (status) => {
+const getStatusClass = (status: string) => {
   const classes = {
     active: 'active',
     inactive: 'inactive',
     maintenance: 'maintenance'
   }
-  return classes[status] || ''
+  return classes[status as keyof typeof classes] || ''
 }
 
 // Statistiques fictives
@@ -422,17 +425,17 @@ const getVehicleMaintenanceCount = (vehicleId) => {
 }
 
 // Méthodes pour les actions
-const viewVehicle = (vehicle) => {
+const viewVehicle = (vehicle: Vehicle) => {
   viewingVehicle.value = { ...vehicle }
 }
 
-const editVehicle = (vehicle) => {
+const editVehicle = (vehicle: Vehicle) => {
   editingVehicle.value = vehicle
   formData.value = { ...vehicle }
   viewingVehicle.value = null
 }
 
-const confirmDelete = (vehicle) => {
+const confirmDelete = (vehicle: Vehicle) => {
   deletingVehicle.value = vehicle
 }
 
@@ -443,11 +446,11 @@ const closeForm = () => {
     id: null,
     brand: '',
     model: '',
-    licensePlate: '',
+    immatriculation: '',
     year: new Date().getFullYear(),
     type: 'van',
     companyId: '',
-    capacity: null,
+    number_places: 0,
     color: '',
     status: 'active',
     image: null,
@@ -455,15 +458,15 @@ const closeForm = () => {
   }
 }
 
-const saveVehicle = async (vehicleData) => {
+const saveVehicle = async (vehicleData: Vehicle) => {
   if (editingVehicle.value) {
     // Mise à jour d'un véhicule existant
     try {
       const vehiculeData: Partial<Vehicle> = {
-        number_places: vehicleData.capacity || 0,
+        number_places: vehicleData.number_places || 0,
         color: vehicleData.color || '',
         type: vehicleData.type || '',
-        immatriculation: vehicleData.licensePlate || '',
+        immatriculation: vehicleData.immatriculation || '',
         model: vehicleData.model || '',
         companyId: vehicleData.companyId || userStore.companyId || 1,
         status: vehicleData.status || 'active'
@@ -497,7 +500,7 @@ const deleteVehicle = async () => {
 onMounted(async () => {
   await Promise.all([
     loadVehicles(),
-    loadCompanies()
+    useVehiculeStore().fetchVehicles()
   ])
 })
 
@@ -512,7 +515,7 @@ watch(() => pagination.value.page, () => {
 })
 
 // Méthodes pour les événements du TopBar
-const handleSearch = (query) => {
+const handleSearch = (query: string) => {
   searchQuery.value = query
 }
 

+ 1 - 1
app_transport_front/vite.config.ts

@@ -18,7 +18,7 @@ export default defineConfig({
   },
   resolve: {
     alias: {
-      '@': path.resolve(__dirname, 'src'),
+      '@': path.resolve(__dirname, './src'),
     },
   },
 })

+ 3 - 3
node_app/src/main.ts

@@ -20,8 +20,8 @@ async function bootstrap() {
 
   // swagger document
   const config = new DocumentBuilder()
-    .setTitle('Transport app')
-    .setDescription('The Transport API description')
+    .setTitle('DabidjanApp')
+    .setDescription('DabidjanApp API description')
     .setVersion('1.0')
     .addTag('Transport')
     .addServer('/api')
@@ -55,7 +55,7 @@ async function bootstrap() {
   );
 
   app.enableCors({
-    origin: 'http://localhost:5173', // ou '*' en développement
+    origin: '*', // ou '*' en développement
     methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
     allowedHeaders: ['Content-Type', 'Authorization'],
     credentials: true, // si tu utilises les cookies ou des sessions