Spaces:
Sleeping
Sleeping
Download backend/src/services/ugaService.js from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 23 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/src/services/ugaService.js
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/backend/src/services/ugaService.js
-
curl -L -o ugaService.js https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/src/services/ugaService.js
23 kB
| const axios = require('axios'); | |
| const logger = require('../utils/logger'); | |
| const { redisUtils } = require('../utils/redis'); | |
| class UGAService { | |
| constructor() { | |
| this.baseUrls = { | |
| elc: process.env.ELC_API_URL || 'https://elc.uga.edu/api', | |
| athena: process.env.ATHENA_API_URL || 'https://athena.uga.edu/api', | |
| myid: process.env.MYID_API_URL || 'https://myid.uga.edu/api', | |
| directory: process.env.UGA_DIRECTORY_API || 'https://directory.uga.edu/api' | |
| }; | |
| this.cacheTimeout = 300; // 5 minutes | |
| } | |
| // MyID Authentication Service | |
| async authenticateWithMyID(credentials) { | |
| try { | |
| const response = await axios.post(`${this.baseUrls.myid}/authenticate`, { | |
| username: credentials.username, | |
| password: credentials.password | |
| }, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'User-Agent': 'UGA-Chatbot/1.0' | |
| }, | |
| timeout: 10000 | |
| }); | |
| if (response.data.success) { | |
| // Cache user session | |
| await redisUtils.setex( | |
| `auth:${credentials.username}`, | |
| 3600, // 1 hour | |
| response.data.user | |
| ); | |
| return { | |
| success: true, | |
| user: response.data.user, | |
| token: response.data.token | |
| }; | |
| } | |
| return { success: false, error: 'Invalid credentials' }; | |
| } catch (error) { | |
| logger.error('MyID authentication error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Authentication service unavailable' | |
| }; | |
| } | |
| } | |
| // eLC Integration | |
| async getElcCourses(userId, token) { | |
| try { | |
| const cacheKey = `elc:courses:${userId}`; | |
| // Check cache first | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const response = await axios.get(`${this.baseUrls.elc}/courses`, { | |
| headers: { | |
| 'Authorization': `Bearer ${token}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| timeout: 15000 | |
| }); | |
| const courses = response.data; | |
| // Cache for 5 minutes | |
| await redisUtils.setex(cacheKey, this.cacheTimeout, courses); | |
| return { success: true, data: courses }; | |
| } catch (error) { | |
| logger.error('eLC courses fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch course information', | |
| fallback: this.getElcFallbackInfo() | |
| }; | |
| } | |
| } | |
| async getElcAssignments(userId, courseId, token) { | |
| try { | |
| const cacheKey = `elc:assignments:${userId}:${courseId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const response = await axios.get(`${this.baseUrls.elc}/courses/${courseId}/assignments`, { | |
| headers: { | |
| 'Authorization': `Bearer ${token}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| timeout: 15000 | |
| }); | |
| const assignments = response.data; | |
| // Cache for 2 minutes (more frequent updates for assignments) | |
| await redisUtils.setex(cacheKey, 120, assignments); | |
| return { success: true, data: assignments }; | |
| } catch (error) { | |
| logger.error('eLC assignments fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch assignment information' | |
| }; | |
| } | |
| } | |
| // Athena Integration | |
| async getAthenaStudentInfo(userId, token) { | |
| try { | |
| const cacheKey = `athena:student:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const response = await axios.get(`${this.baseUrls.athena}/student/${userId}`, { | |
| headers: { | |
| 'Authorization': `Bearer ${token}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| timeout: 15000 | |
| }); | |
| const studentInfo = { | |
| ...response.data, | |
| // Remove sensitive information | |
| ssn: undefined, | |
| financialDetails: undefined | |
| }; | |
| // Cache for 10 minutes | |
| await redisUtils.setex(cacheKey, 600, studentInfo); | |
| return { success: true, data: studentInfo }; | |
| } catch (error) { | |
| logger.error('Athena student info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch student information', | |
| fallback: this.getAthenaFallbackInfo() | |
| }; | |
| } | |
| } | |
| async getAthenaGrades(userId, semester, token) { | |
| try { | |
| const cacheKey = `athena:grades:${userId}:${semester}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const response = await axios.get(`${this.baseUrls.athena}/grades/${userId}`, { | |
| params: { semester }, | |
| headers: { | |
| 'Authorization': `Bearer ${token}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| timeout: 15000 | |
| }); | |
| const grades = response.data; | |
| // Cache for 5 minutes | |
| await redisUtils.setex(cacheKey, this.cacheTimeout, grades); | |
| return { success: true, data: grades }; | |
| } catch (error) { | |
| logger.error('Athena grades fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch grade information' | |
| }; | |
| } | |
| } | |
| // Campus Services | |
| async getCampusServices() { | |
| try { | |
| const cacheKey = 'campus:services'; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| // Static campus services data (would normally come from UGA API) | |
| const services = { | |
| dining: { | |
| locations: [ | |
| { name: 'The Niche', hours: '7:00 AM - 11:00 PM', location: 'Memorial Hall' }, | |
| { name: 'ECV Dining Commons', hours: '7:00 AM - 10:00 PM', location: 'East Campus Village' }, | |
| { name: 'O-House', hours: '7:00 AM - 12:00 AM', location: 'Oglethorpe House' }, | |
| { name: 'Village Summit', hours: '7:00 AM - 10:00 PM', location: 'Village Summit' } | |
| ] | |
| }, | |
| transportation: { | |
| busRoutes: [ | |
| { name: 'Campus Transit', description: 'Main campus loop' }, | |
| { name: 'Athens Transit', description: 'City-wide service' }, | |
| { name: 'UGA Parking', description: 'Parking deck information' } | |
| ] | |
| }, | |
| libraries: [ | |
| { name: 'Miller Learning Center', hours: '24/7 during semester', services: ['Study spaces', 'Computer labs', 'Printing'] }, | |
| { name: 'Main Library', hours: 'M-F: 7:30 AM - 2:00 AM', services: ['Research assistance', 'Archives', 'Special collections'] }, | |
| { name: 'Science Library', hours: 'M-F: 7:30 AM - 12:00 AM', services: ['STEM resources', 'Group study rooms'] } | |
| ], | |
| recreation: { | |
| ramsey: { | |
| name: 'Ramsey Student Center', | |
| hours: 'M-F: 5:30 AM - 12:00 AM', | |
| facilities: ['Fitness equipment', 'Swimming pool', 'Basketball courts', 'Rock climbing wall'] | |
| } | |
| } | |
| }; | |
| // Cache for 30 minutes | |
| await redisUtils.setex(cacheKey, 1800, services); | |
| return { success: true, data: services }; | |
| } catch (error) { | |
| logger.error('Campus services fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch campus services information' | |
| }; | |
| } | |
| } | |
| // IT Support Information | |
| async getITSupport() { | |
| try { | |
| const cacheKey = 'it:support'; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const support = { | |
| eits: { | |
| phone: '706-542-3106', | |
| email: 'helpdesk@uga.edu', | |
| hours: 'M-F: 8:00 AM - 5:00 PM', | |
| location: 'Boyd GSRC, Room 420', | |
| services: [ | |
| 'MyID account issues', | |
| 'eLC technical support', | |
| 'Athena access problems', | |
| 'Email setup', | |
| 'WiFi connectivity', | |
| 'Software installation' | |
| ] | |
| }, | |
| commonIssues: { | |
| 'MyID Password Reset': 'Visit https://myid.uga.edu or call EITS', | |
| 'ArchPass Setup': 'Download Duo Mobile app and follow setup instructions', | |
| 'eLC Access Issues': 'Clear browser cache or try different browser', | |
| 'Athena Off-Campus': 'Use VPN or contact EITS for alternative access', | |
| 'WiFi Problems': 'Forget and reconnect to UGA-WiFi network' | |
| } | |
| }; | |
| // Cache for 1 hour | |
| await redisUtils.setex(cacheKey, 3600, support); | |
| return { success: true, data: support }; | |
| } catch (error) { | |
| logger.error('IT support fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch IT support information' | |
| }; | |
| } | |
| } | |
| // Academic Calendar | |
| async getAcademicCalendar(year) { | |
| try { | |
| const cacheKey = `calendar:${year}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| // Academic calendar data (would normally come from UGA API) | |
| const calendar = { | |
| fall2024: { | |
| registration: 'March 25 - August 23, 2024', | |
| classes: 'August 19 - December 6, 2024', | |
| finals: 'December 9 - 16, 2024', | |
| breaks: ['November 25-29 (Thanksgiving)'] | |
| }, | |
| spring2025: { | |
| registration: 'October 21, 2024 - January 10, 2025', | |
| classes: 'January 13 - April 25, 2025', | |
| finals: 'April 28 - May 5, 2025', | |
| breaks: ['March 10-14 (Spring Break)'] | |
| }, | |
| summer2025: { | |
| registration: 'February 17 - May 16, 2025', | |
| classes: 'May 19 - August 1, 2025', | |
| finals: 'July 28 - August 1, 2025' | |
| } | |
| }; | |
| // Cache for 1 day | |
| await redisUtils.setex(cacheKey, 86400, calendar); | |
| return { success: true, data: calendar }; | |
| } catch (error) { | |
| logger.error('Academic calendar fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch academic calendar' | |
| }; | |
| } | |
| } | |
| // Student Registration Services | |
| async getRegistrationInfo(userId, token) { | |
| try { | |
| const cacheKey = `registration:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const registrationInfo = { | |
| registrationWindow: { | |
| opens: 'March 25, 2025 at 8:00 AM', | |
| priority: 'Based on credit hours and classification', | |
| location: 'Athena Student Information System' | |
| }, | |
| process: { | |
| steps: [ | |
| 'Log into Athena with your MyID', | |
| 'Navigate to Student Services', | |
| 'Select Course Registration', | |
| 'Search for courses by subject, course number, or keyword', | |
| 'Add courses to your shopping cart', | |
| 'Review schedule for time conflicts', | |
| 'Complete registration' | |
| ] | |
| }, | |
| tips: [ | |
| 'Plan multiple schedules in case courses are full', | |
| 'Use the waitlist feature for closed courses', | |
| 'Check prerequisites before registering', | |
| 'Meet with your academic advisor', | |
| 'Register as soon as your window opens' | |
| ], | |
| importantDates: { | |
| advising: 'March 1-20, 2025', | |
| registration: 'March 25 - August 23, 2025', | |
| addDrop: 'First week of classes', | |
| withdrawalDeadline: 'Mid-semester' | |
| } | |
| }; | |
| // Cache for 30 minutes | |
| await redisUtils.setex(cacheKey, 1800, registrationInfo); | |
| return { success: true, data: registrationInfo }; | |
| } catch (error) { | |
| logger.error('Registration info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch registration information' | |
| }; | |
| } | |
| } | |
| // Financial Aid Services | |
| async getFinancialAidInfo(userId, token) { | |
| try { | |
| const cacheKey = `financial-aid:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const financialAid = { | |
| office: { | |
| location: 'Terrell Hall, Room 220', | |
| phone: '706-542-6147', | |
| email: 'osfa@uga.edu', | |
| hours: 'M-F: 8:00 AM - 5:00 PM' | |
| }, | |
| applications: { | |
| fafsa: { | |
| name: 'Free Application for Federal Student Aid (FAFSA)', | |
| deadline: 'March 1 (priority deadline)', | |
| website: 'https://studentaid.gov/h/apply-for-aid/fafsa', | |
| schoolCode: '001598' | |
| }, | |
| ugaScholarships: { | |
| name: 'UGA Scholarship Application', | |
| deadline: 'January 1', | |
| website: 'https://scholarships.uga.edu' | |
| } | |
| }, | |
| aidTypes: [ | |
| { | |
| type: 'Federal Pell Grant', | |
| description: 'Need-based grant that does not need to be repaid', | |
| maxAmount: '$7,395 per year' | |
| }, | |
| { | |
| type: 'HOPE Scholarship', | |
| description: 'Merit-based scholarship for Georgia residents', | |
| requirements: '3.0 GPA and Georgia residency' | |
| }, | |
| { | |
| type: 'Zell Miller Scholarship', | |
| description: 'Full tuition scholarship for top Georgia students', | |
| requirements: '3.7 GPA and 1200+ SAT or 26+ ACT' | |
| }, | |
| { | |
| type: 'Federal Work-Study', | |
| description: 'Part-time employment program for students', | |
| details: 'On-campus and community service positions' | |
| } | |
| ], | |
| deadlines: { | |
| fafsa: 'March 1 (priority)', | |
| verification: '30 days after notification', | |
| acceptanceResponse: 'May 1 for fall semester' | |
| } | |
| }; | |
| // Cache for 4 hours | |
| await redisUtils.setex(cacheKey, 14400, financialAid); | |
| return { success: true, data: financialAid }; | |
| } catch (error) { | |
| logger.error('Financial aid info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch financial aid information' | |
| }; | |
| } | |
| } | |
| // Housing Services | |
| async getHousingInfo(userId, token) { | |
| try { | |
| const cacheKey = `housing:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const housing = { | |
| office: { | |
| name: 'University Housing', | |
| location: 'Buford Drive', | |
| phone: '706-542-1421', | |
| email: 'housing@uga.edu', | |
| website: 'https://housing.uga.edu' | |
| }, | |
| application: { | |
| deadline: 'May 1 for fall semester', | |
| deposit: '$300 (refundable)', | |
| portal: 'MyHousing portal', | |
| process: [ | |
| 'Submit housing application online', | |
| 'Pay housing deposit', | |
| 'Complete roommate matching (optional)', | |
| 'Receive housing assignment', | |
| 'Complete check-in process' | |
| ] | |
| }, | |
| dormitories: [ | |
| { | |
| name: 'East Campus Village', | |
| type: 'Suite-style', | |
| occupancy: '2-4 students per suite', | |
| amenities: ['Dining hall', 'Fitness center', 'Study lounges'] | |
| }, | |
| { | |
| name: 'Oglethorpe House', | |
| type: 'Traditional', | |
| occupancy: '2 students per room', | |
| amenities: ['Community bathrooms', 'Study areas', 'Laundry'] | |
| }, | |
| { | |
| name: 'Village Summit', | |
| type: 'Apartment-style', | |
| occupancy: '4 students per apartment', | |
| amenities: ['Private bathrooms', 'Kitchen', 'Living area'] | |
| }, | |
| { | |
| name: 'Memorial Hall', | |
| type: 'Traditional', | |
| occupancy: '2-3 students per room', | |
| amenities: ['Historic building', 'Central campus location'] | |
| } | |
| ], | |
| costs: { | |
| traditional: '$5,800 - $6,800 per year', | |
| suite: '$7,200 - $8,200 per year', | |
| apartment: '$8,500 - $9,500 per year' | |
| } | |
| }; | |
| // Cache for 2 hours | |
| await redisUtils.setex(cacheKey, 7200, housing); | |
| return { success: true, data: housing }; | |
| } catch (error) { | |
| logger.error('Housing info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch housing information' | |
| }; | |
| } | |
| } | |
| // Meal Plan Services | |
| async getMealPlanInfo(userId, token) { | |
| try { | |
| const cacheKey = `meal-plans:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const mealPlans = { | |
| office: { | |
| name: 'UGA Dining Services', | |
| phone: '706-542-1381', | |
| email: 'dining@uga.edu', | |
| website: 'https://dining.uga.edu' | |
| }, | |
| plans: [ | |
| { | |
| name: 'Bulldog Plan', | |
| cost: '$2,890 per semester', | |
| meals: 'Unlimited dining hall visits', | |
| flex: '$100 Bulldog Bucks', | |
| bestFor: 'Students who eat 3+ meals daily on campus' | |
| }, | |
| { | |
| name: 'Dawg Plan', | |
| cost: '$2,590 per semester', | |
| meals: '200 meals per semester', | |
| flex: '$200 Bulldog Bucks', | |
| bestFor: 'Students with moderate dining needs' | |
| }, | |
| { | |
| name: 'Pup Plan', | |
| cost: '$2,290 per semester', | |
| meals: '150 meals per semester', | |
| flex: '$300 Bulldog Bucks', | |
| bestFor: 'Students who eat off-campus frequently' | |
| }, | |
| { | |
| name: 'Commuter Plan', | |
| cost: '$1,200 per semester', | |
| meals: '50 meals per semester', | |
| flex: '$400 Bulldog Bucks', | |
| bestFor: 'Commuter students and off-campus residents' | |
| } | |
| ], | |
| locations: [ | |
| { | |
| name: 'The Niche', | |
| type: 'All-you-can-eat dining', | |
| location: 'Memorial Hall', | |
| hours: '7:00 AM - 11:00 PM' | |
| }, | |
| { | |
| name: 'ECV Dining Commons', | |
| type: 'All-you-can-eat dining', | |
| location: 'East Campus Village', | |
| hours: '7:00 AM - 10:00 PM' | |
| }, | |
| { | |
| name: 'Village Summit Food Court', | |
| type: 'Retail dining', | |
| location: 'Village Summit', | |
| hours: '7:00 AM - 12:00 AM' | |
| }, | |
| { | |
| name: 'Bulldog Cafe', | |
| type: 'Coffee and light meals', | |
| location: 'Miller Learning Center', | |
| hours: '7:00 AM - 10:00 PM' | |
| } | |
| ], | |
| bullDogBucks: { | |
| description: 'Flexible spending account for dining', | |
| locations: 'Dining halls, cafes, vending machines', | |
| rollover: 'Up to $100 per semester', | |
| refundable: 'At graduation or withdrawal' | |
| } | |
| }; | |
| // Cache for 2 hours | |
| await redisUtils.setex(cacheKey, 7200, mealPlans); | |
| return { success: true, data: mealPlans }; | |
| } catch (error) { | |
| logger.error('Meal plan info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch meal plan information' | |
| }; | |
| } | |
| } | |
| // Student Accounts and Billing | |
| async getBillingInfo(userId, token) { | |
| try { | |
| const cacheKey = `billing:${userId}`; | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return { success: true, data: cached }; | |
| } | |
| const billing = { | |
| office: { | |
| name: 'Student Accounts', | |
| location: 'Lustrat House', | |
| phone: '706-542-3142', | |
| email: 'bursar@uga.edu', | |
| hours: 'M-F: 8:00 AM - 5:00 PM' | |
| }, | |
| paymentMethods: [ | |
| 'Online via ArchPass portal', | |
| 'Phone: 1-800-407-3864', | |
| 'Mail: Check or money order', | |
| 'In-person: Cash, check, or money order' | |
| ], | |
| paymentPlans: { | |
| semesterPlan: { | |
| description: 'Pay in full by due date', | |
| discount: 'No additional fees' | |
| }, | |
| monthlyPlan: { | |
| description: 'Spread payments over 4-5 months', | |
| fee: '$25 enrollment fee per semester' | |
| } | |
| }, | |
| importantDates: { | |
| fall2024: { | |
| billAvailable: 'July 1, 2024', | |
| paymentDue: 'August 15, 2024' | |
| }, | |
| spring2025: { | |
| billAvailable: 'December 1, 2024', | |
| paymentDue: 'January 10, 2025' | |
| } | |
| }, | |
| tuitionFees: { | |
| inState: { | |
| undergraduate: '$11,180 per year', | |
| graduate: '$11,180 per year' | |
| }, | |
| outOfState: { | |
| undergraduate: '$29,844 per year', | |
| graduate: '$29,844 per year' | |
| }, | |
| additionalFees: '$2,556 per year' | |
| } | |
| }; | |
| // Cache for 4 hours | |
| await redisUtils.setex(cacheKey, 14400, billing); | |
| return { success: true, data: billing }; | |
| } catch (error) { | |
| logger.error('Billing info fetch error:', error.message); | |
| return { | |
| success: false, | |
| error: 'Unable to fetch billing information' | |
| }; | |
| } | |
| } | |
| // Fallback information when APIs are unavailable | |
| getElcFallbackInfo() { | |
| return { | |
| message: 'eLC system is currently unavailable. Here are some helpful tips:', | |
| tips: [ | |
| 'Access eLC at https://elc.uga.edu', | |
| 'Use your MyID credentials to log in', | |
| 'Check your course announcements and assignments', | |
| 'Submit assignments before deadlines', | |
| 'Contact your instructor for course-specific questions' | |
| ] | |
| }; | |
| } | |
| getAthenaFallbackInfo() { | |
| return { | |
| message: 'Athena system is currently unavailable. Here are alternative resources:', | |
| resources: [ | |
| 'Visit Athena at https://athena.uga.edu', | |
| 'Check registration dates on the academic calendar', | |
| 'Contact your advisor for academic planning', | |
| 'Visit the Registrar\'s Office for transcript requests', | |
| 'Call EITS at 706-542-3106 for technical issues' | |
| ] | |
| }; | |
| } | |
| // Utility method to check system status | |
| async getSystemStatus() { | |
| const systems = ['elc', 'athena', 'myid']; | |
| const status = {}; | |
| for (const system of systems) { | |
| try { | |
| await axios.get(`${this.baseUrls[system]}/health`, { timeout: 5000 }); | |
| status[system] = 'operational'; | |
| } catch (error) { | |
| status[system] = 'unavailable'; | |
| } | |
| } | |
| return status; | |
| } | |
| } | |
| module.exports = new UGAService(); |