Jelajahi Sumber

(fix) station et compagnie

Brin AMONKONAN 1 tahun lalu
induk
melakukan
0019949770

+ 6 - 13
app_transport_front/src/components/EmployeeModal.vue

@@ -184,6 +184,7 @@ import { Role, RoleLabel } from '@/Enum/Role'
 import type { User } from '@/types/index'
 import UserService from '@/services/UserService'
 import { useToast } from '@/composables/useToast'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 
 // Props
 interface Props {
@@ -294,10 +295,10 @@ const resetForm = () => {
 const loadEmployeeData = () => {
   if (props.editingEmployee) {
     formData.value = {
-      firstName: props.editingEmployee.firstName || '',
-      lastName: props.editingEmployee.lastName || '',
+      firstName: props.editingEmployee.name || '',
+      lastName: props.editingEmployee.otherName || '',
       email: props.editingEmployee.email || '',
-      phone: props.editingEmployee.phone || '',
+      phone: props.editingEmployee.telephone || '',
       role: props.editingEmployee.role || '' as Role | '',
       password: '', // Ne pas pré-remplir le mot de passe
       address: props.editingEmployee.address || '',
@@ -353,14 +354,6 @@ const saveEmployee = async () => {
         return
       }
       
-      // Récupérer l'ID de l'entreprise depuis le token JWT décodé
-      const companyId = userStore.decodedCompanyId || userStore.companyId
-      
-      if (!companyId) {
-        error('Aucune entreprise associée à votre compte')
-        return
-      }
-      
       // Créer d'abord l'utilisateur sans rôle (comme dans ManagerModal)
       const { role, ...createDataSansRole } = {
         name: formData.value.lastName.trim(),
@@ -370,11 +363,11 @@ const saveEmployee = async () => {
         address: formData.value.address.trim(),
         password: formData.value.password.trim(),
         role: formData.value.role as Role,
-        companyId: parseInt(companyId) // Ajouter l'ID de l'entreprise
+        companyId: useUserCompanyStore().id
       }
       
       // Créer l'utilisateur sans le rôle
-      const newEmployee = await UserService.createUser(createDataSansRole as User)
+      const newEmployee = await UserService.createUser(createDataSansRole)
       
       if (newEmployee && newEmployee.id) {
         // Assigner le rôle après création

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

@@ -38,7 +38,7 @@
           <span>Parc automobile</span>
         </router-link>
         <!-- Nouvelles entrées pour les stations -->
-        <router-link v-if="userRole === Role.Admin || userRole === Role.Manager" to="/stations" class="menu-item" :class="{ active: currentRoute === '/stations' }">
+        <router-link v-if="userRole === Role.Admin" to="/stations" class="menu-item" :class="{ active: currentRoute === '/stations' }">
           <i class="fas fa-map-marker-alt"></i>
           <span>Stations</span>
         </router-link>

+ 1 - 1
app_transport_front/src/router/index.ts

@@ -59,7 +59,7 @@ const routes: Array<RouteRecordRaw> = [
     path: '/stations',
     name: 'stations',
     component: () => import('../views/StationView.vue'),
-    meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager] }
+    meta: { requiresAuth: true, roles: [Role.Admin] }
   },
   {
     path: '/station-companies',

+ 13 - 0
app_transport_front/src/services/StationCompanyService.ts

@@ -40,6 +40,19 @@ export default {
     }
   },
 
+  async getStationCompaniesByCompanyId(companyId: number): Promise<StationCompany[] | null> {
+    try {
+      const response = await authenticatedFetch(`${API_URL}/station-companies/company/${companyId}`)
+      if (!response.ok) {
+        throw new Error('Erreur lors de la récupération des relations station-entreprise')
+      }
+      return await response.json()
+    } catch (error) {
+      console.error('Erreur:', error)
+      return null
+    }
+  },
+
   async getStationCompany(id: number): Promise<StationCompany | null> {
     try {
       const response = await authenticatedFetch(`${API_URL}/station-companies/${id}`)

+ 2 - 1
app_transport_front/src/services/VehiculeService.ts

@@ -80,7 +80,8 @@ export default {
   async deleteVehicle(id: number): Promise<boolean> {
     try {
       const response = await authenticatedFetch(`${API_URL}/vehicles/${id}`, {
-        method: 'DELETE'
+        method: 'DELETE',
+        body: JSON.stringify({ id: id })
       })
       return response.ok
     } catch (error) {

+ 2 - 8
app_transport_front/src/views/EmployeeView.vue

@@ -240,6 +240,7 @@ import UserService from '@/services/UserService'
 import CompanyService from '@/services/CompanyService'
 import type { User } from '@/types/index'
 import { Role, RoleLabel } from '@/Enum/Role'
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
 
 interface Employee extends User {
   firstName?: string
@@ -338,15 +339,8 @@ const formatDate = (dateString?: string): string => {
 const loadEmployees = async (page: number = 1) => {
   try {
     loading.value = true
-    const userStore = useUserStore()
     
-    // Vérifier si l'utilisateur a une entreprise associée
-    if (!userStore.companyId) {
-      error('Aucune entreprise associée à votre compte')
-      return
-    }
-    
-    const result = await CompanyService.getCompanyEmployees(parseInt(userStore.companyId), page, pagination.value.limit)
+    const result = await CompanyService.getCompanyEmployees(useUserCompanyStore().id, page, pagination.value.limit)
     
     employees.value = result.employees.map(user => ({
       ...user,

+ 39 - 43
app_transport_front/src/views/StationCompanyView.vue

@@ -67,7 +67,7 @@
                 </tr>
               </thead>
               <tbody>
-                <tr v-for="relation in displayedRelations" :key="relation.id" class="hover:bg-gray-50">
+                <tr v-for="relation in stationCompanies" :key="relation.id" class="hover:bg-gray-50">
                   <td class="py-3 px-4 border-b border-gray-200">{{ relation.id }}</td>
                   <td class="py-3 px-4 border-b border-gray-200">{{ getStationName(relation.stationId) }}</td>
                   <td class="py-3 px-4 border-b border-gray-200">{{ getCompanyName(relation.companyId) }}</td>
@@ -144,8 +144,8 @@
                   </select>
                </div>
                <div class="mb-4">
-                 <label class="block text-sm font-medium text-gray-700 mb-2">Chef de Station</label>
-                 <select v-model="formData.stationChiefId" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
+                 <label class="block text-sm font-medium text-gray-700 mb-2">Chef de Station <span class="text-red-500">*</span></label>
+                 <select v-model="formData.stationChiefId" required class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                    <option value="">Sélectionner un chef de station</option>
                    <option v-for="employee in employees" :key="employee.id" :value="employee.id">
                      {{ employee.name || `${employee.firstName} ${employee.lastName}` }}
@@ -186,7 +186,7 @@ import { useUserCompanyStore } from '@/stores/useCompanyStore'
 
 const userStore = useUserStore()
 const stationStore = useStationStore()
-const loading = ref(false)
+const loading = ref<boolean>(false)
 const stationCompanies = ref<StationCompany[]>([])
 const companies = ref<Company[]>([])
 const employees = ref<any[]>([])
@@ -220,10 +220,6 @@ const isCompanyFieldDisabled = computed(() => {
   return !isAdmin.value
 })
 
-// Computed pour les relations affichées (directement depuis le backend)
-const displayedRelations = computed(() => {
-  return stationCompanies.value
-})
 
 onMounted(async () => {
   await loadData()
@@ -239,7 +235,7 @@ watch([searchQuery, stationFilter], () => {
   }
   searchTimeout = setTimeout(() => {
     pagination.value.page = 1
-    loadStationCompanies()
+    //loadStationCompanies()
   }, 300)
 })
 
@@ -254,25 +250,25 @@ watch(() => formData.companyId, async (newCompanyId) => {
   formData.stationChiefId = undefined
 })
 
-const loadStationCompanies = async () => {
-  loading.value = true
-  try {
-    const searchParam = searchQuery.value.trim() || undefined
-    const stationParam = stationFilter.value || undefined
-    const response = await StationCompanyService.getStationCompanies(
-      pagination.value.page, 
-      pagination.value.limit, 
-      searchParam, 
-      stationParam
-    )
-    stationCompanies.value = response.stationCompanies
-    pagination.value = response.pagination
-  } catch (error) {
-    console.error('Erreur lors du chargement des relations:', error)
-  } finally {
-    loading.value = false
-  }
-}
+// const loadStationCompanies = async () => {
+//   loading.value = true
+//   try {
+//     const searchParam = searchQuery.value.trim() || undefined
+//     const stationParam = stationFilter.value || undefined
+//     const response = await StationCompanyService.getStationCompanies(
+//       pagination.value.page, 
+//       pagination.value.limit, 
+//       searchParam, 
+//       stationParam
+//     )
+//     stationCompanies.value = response.stationCompanies
+//     pagination.value = response.pagination
+//   } catch (error) {
+//     console.error('Erreur lors du chargement des relations:', error)
+//   } finally {
+//     loading.value = false
+//   }
+// }
 
 const loadEmployees = async (companyId: number) => {
   try {
@@ -286,24 +282,24 @@ const loadEmployees = async (companyId: number) => {
 
 const loadData = async () => {
   loading.value = true
+  console.log('seUserCompanyStore().id:',useUserCompanyStore().id)
   try {
-    const searchParam = searchQuery.value.trim() || undefined
-    const stationParam = stationFilter.value || undefined
-    const [relationsResponse, companiesResponse] = await Promise.all([
-      StationCompanyService.getStationCompanies(
-        pagination.value.page, 
-        pagination.value.limit, 
-        searchParam, 
-        stationParam
-      ),
-      CompanyService.getCompanies()
-    ])
+
+    const relationsResponse = await StationCompanyService.getStationCompaniesByCompanyId(useUserCompanyStore().id)
+    
+    console.log('relationsResponse:', relationsResponse?.data)
     // Charger les stations via le store
     await stationStore.fetchStations()
     
-    stationCompanies.value = relationsResponse.stationCompanies
-    pagination.value = relationsResponse.pagination
-    companies.value = companiesResponse.companies
+    stationCompanies.value = relationsResponse?.data as StationCompany[]
+    //TODO:: géré la pagination dans le back
+    pagination.value = {
+      total: 10, 
+      page: 1,
+      limit: 10,
+      totalPages: 1
+    } //relationsResponse.pagination
+    //companies.value = companiesResponse.companies
   } catch (error) {
     console.error('Erreur lors du chargement des données:', error)
   } finally {
@@ -408,7 +404,7 @@ const handleUserMenu = () => {
 // Méthode de gestion du changement de page
 const handlePageChange = async (page: number) => {
   pagination.value.page = page
-  await loadStationCompanies()
+  //await loadStationCompanies()
 }
 
 // onBeforeMount supprimé pour éviter les doubles chargements