Skip to content

Commit

Permalink
Update Trofos API endpoints to Trofos production server
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter-sim committed Oct 6, 2024
1 parent a303119 commit 91c7b91
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
37 changes: 35 additions & 2 deletions backend/jobs/trofosJob.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import cron from 'node-cron';
import { Course } from '@models/Course';
import CourseModel from '@models/Course';
import { TROFOS_COURSE_URI, TROFOS_PROJECT_URI } from '../utils/endpoints';
import {
TROFOS_COURSE_URI,
TROFOS_PROJECT_URI,
TROFOS_SPRINT_PATH,
} from '../utils/endpoints';

const fetchAndSaveTrofosData = async () => {
const courses: Course[] = await CourseModel.find();
Expand Down Expand Up @@ -86,13 +90,42 @@ const fetchSingleTrofosProject = async (

const singleTrofosProjectData = await singleTrofosProjectResponse.json();
console.log(singleTrofosProjectData);

await fetchSprintsFromSingleTrofosProject(trofosProjectId, apiKey);
} catch (error) {
console.error('Error in fetching single Trofos project:', error);
}
};

const fetchSprintsFromSingleTrofosProject = async (
trofosProjectId: number,
apiKey: string
) => {
const trofosSprintUri = `${TROFOS_PROJECT_URI}/${trofosProjectId}${TROFOS_SPRINT_PATH}`;

try {
const trofosSprintResponse = await fetch(trofosSprintUri, {
method: 'GET',
headers: {
'x-api-key': apiKey,
Accept: 'application/json',
'Content-Type': 'application/json',
},
});

if (!trofosSprintResponse.ok) {
throw new Error('Network response was not ok');
}

const trofosSprintData = await trofosSprintResponse.json();
console.log(trofosSprintData);
} catch (error) {
console.error('Error in fetching sprints from a Trofos project:', error);
}
};

const setupTrofosJob = () => {
// Schedule the job to run every day at 01:00 hours
// Schedule the job to run every day at 03:00 hours
cron.schedule('0 3 * * *', async () => {
console.log('Running fetchAndSaveTrofosData job:', new Date().toString());
try {
Expand Down
5 changes: 3 additions & 2 deletions backend/utils/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ISSUE_API_PATH = '/rest/agile/1.0/issue';

/*---------------------------------------Trofos---------------------------------------*/
export const TROFOS_COURSE_URI =
'https://trofos.comp.nus.edu.sg/api/external/v1/course';
'https://trofos-production.comp.nus.edu.sg/api/external/v1/course';
export const TROFOS_PROJECT_URI =
'https://trofos.comp.nus.edu.sg/api/external/v1/project';
'https://trofos-production.comp.nus.edu.sg/api/external/v1/project';
export const TROFOS_SPRINT_PATH = '/sprint';

0 comments on commit 91c7b91

Please sign in to comment.