From 3f5604aa6bfcd279f284b93fd8a3eae545b80e70 Mon Sep 17 00:00:00 2001 From: mukeshs Date: Wed, 5 Nov 2025 15:56:08 +0530 Subject: [PATCH] Team award update --- src/lib/facultyData.ts | 56 +++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/lib/facultyData.ts b/src/lib/facultyData.ts index 50ebff6..77498a1 100644 --- a/src/lib/facultyData.ts +++ b/src/lib/facultyData.ts @@ -55,12 +55,20 @@ export class FacultyService { private static baseUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'; + // ✅ FIX: Add cache busting to all fetch calls static async getAllFaculty(): Promise { try { - const response = await fetch(`${this.baseUrl}/professor?size=100`, { + // ✅ ADD: Cache busting with timestamp + const timestamp = new Date().getTime(); + const response = await fetch(`${this.baseUrl}/professor?size=100&_t=${timestamp}`, { + // ✅ ADD: Disable caching + cache: 'no-store', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache, no-store, must-revalidate', + 'Pragma': 'no-cache', + 'Expires': '0' }, }); @@ -91,12 +99,20 @@ export class FacultyService { } } + // ✅ FIX: Add cache busting to professor fetch static async getFacultyByProfessorId(professorId: string): Promise { try { - const response = await fetch(`${this.baseUrl}/professor/${professorId}`, { + // ✅ ADD: Cache busting with timestamp + const timestamp = new Date().getTime(); + const response = await fetch(`${this.baseUrl}/professor/${professorId}?_t=${timestamp}`, { + // ✅ ADD: Disable caching + cache: 'no-store', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache, no-store, must-revalidate', + 'Pragma': 'no-cache', + 'Expires': '0' }, }); @@ -105,7 +121,16 @@ export class FacultyService { } const professor = await response.json(); + + // ✅ DEBUG: Log the awards received from backend + console.log('Awards received from backend:', professor.awards?.length || 0); + console.log('Awards data:', professor.awards); + const transformed = this.transformProfessorsToTeamMembers([professor]); + + // ✅ DEBUG: Log transformed awards + console.log('Awards after transformation:', transformed[0]?.awards?.length || 0); + return transformed[0] || null; } catch (error) { console.error('Error fetching professor by ID:', error); @@ -160,6 +185,19 @@ export class FacultyService { } } + // ✅ FIX: Don't add default awards if backend returns awards + // Only use fallback awards if backend returns empty/null array + const hasBackendAwards = prof.awards && Array.isArray(prof.awards) && prof.awards.length > 0; + + const awards = hasBackendAwards + ? prof.awards.map((award: any) => ({ + title: award.title, + year: award.year, + description: award.description || '', + image: award.imageUrl || '/images/award-icon.png' + })) + : []; // ✅ IMPORTANT: Return empty array, not default award + return { id: index + 1, // Generate sequential ID for UI professorId: prof.professorId, @@ -187,19 +225,7 @@ export class FacultyService { { name: 'Research', level: 85 }, { name: 'Teaching', level: 88 } ], - awards: prof.awards?.map((award: any) => ({ - title: award.title, - year: award.year, - description: award.description, - image: award.imageUrl || '/images/award-icon.png' - })) || [ - { - title: 'Excellence in Medical Practice', - year: new Date().getFullYear().toString(), - description: 'Recognized for outstanding contribution to medical practice and patient care.', - image: '/images/award-icon.png' - } - ], + awards: awards, // ✅ Use the properly handled awards status: prof.status, department: prof.department, officeLocation: prof.officeLocation,