Team award update
This commit is contained in:
@ -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<TeamMember[]> {
|
||||
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<TeamMember | null> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user