Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Chengming-Li committed Apr 5, 2024
1 parent bc75ecb commit 02f774d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions backend/src/scripts/update-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SIS_SECTION_URL = 'https://gateway.api.berkeley.edu/sis/v1/classes/section

const semToTermId = (s: SemesterType) => {
// term-id is computed by dropping the century digit of the year, then adding the term code
const termMap: { [key: string] : number} = {'Fall': 8, 'Spring': 2, 'Summer': 5}
const termMap: { [key: string]: number } = { 'Fall': 8, 'Spring': 2, 'Summer': 5 }
return `${Math.floor(s.year / 1000)}${s.year % 100}${termMap[s.term]}`
}

Expand All @@ -31,21 +31,21 @@ const queryPages = async <T>(url: string, params: any, headers: any, field: stri
let resp: AxiosResponse<SISResponse<T>>;

try {
resp = await axios.get(url, { params: { 'page-number': page, ...params}, headers });
resp = await axios.get(url, { params: { 'page-number': page, ...params }, headers });
} catch (err) {
if (axios.isAxiosError(err) && err.response?.status === 404) {
break;
} else {
console.log(`Unexpected err querying SIS API. Error: ${err}.`)

if (retries > 0) {
retries--;
console.log(`Retrying...`)
continue;
} else {
console.log(`Too many errors querying SIS API for courses. Terminating update...`)
throw err;
}
}
}
}

Expand All @@ -71,7 +71,7 @@ const updateCourses = async () => {
const courses = await queryPages<CourseType>(SIS_COURSE_URL, params, headers, 'courses');

console.log("Updating database with new course data...")

const bulkOps = courses.map(c => ({
replaceOne: {
filter: { classDisplayName: c.classDisplayName },
Expand All @@ -95,7 +95,7 @@ const updateClasses = async () => {

const activeSemesters = await SemesterModel.find({ active: true }).lean();
const classes: ClassType[] = [];

for (const s of activeSemesters) {
console.log(`Updating classses for ${s.term} ${s.year}...`)

Expand Down Expand Up @@ -132,7 +132,7 @@ const updateSections = async () => {

const activeSemesters = await SemesterModel.find({ active: true }).lean();
const sections: SectionType[] = [];

for (const s of activeSemesters) {
console.log(`Updating sections for ${s.term} ${s.year}...`)

Expand Down Expand Up @@ -180,4 +180,4 @@ const updateSections = async () => {
}

process.exit(0);
})();
})();

0 comments on commit 02f774d

Please sign in to comment.