Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

Commit 91b9eb8

Browse files
authored
Merge pull request #327 from MathSoc/319-replacing-redundant-waterloo-api-logic-in-relation-to-converttermcodetotermname
319 replacing redundant waterloo api logic in relation to converttermcodetotermname
2 parents 4d663ad + 20a2506 commit 91b9eb8

File tree

2 files changed

+1
-66
lines changed

2 files changed

+1
-66
lines changed

server/api/controllers/exam-bank-controller.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ export class ExamBankController {
138138
* Gets an array of every exam currently in the exam list folder
139139
*/
140140
private static async generateExamsList(): Promise<Exam[]> {
141-
await this.validateTerms();
142-
143141
const examFiles: Dirent[] = readdirSync("public/exams", {
144142
withFileTypes: true,
145143
});
@@ -214,26 +212,4 @@ export class ExamBankController {
214212
}
215213
}
216214
}
217-
218-
private static async validateTerms() {
219-
const examFiles: Dirent[] = readdirSync("public/exams", {
220-
withFileTypes: true,
221-
});
222-
223-
let valid = true;
224-
for (const exam of examFiles) {
225-
const parts = exam.name.split("-");
226-
const term = parts[2].padStart(4, "0");
227-
228-
const isValidTerm = TermNameController.validateTerm(term);
229-
if (!isValidTerm) {
230-
valid = false;
231-
break;
232-
}
233-
}
234-
235-
if (!valid) {
236-
await TermNameController.overwriteTermsFile();
237-
}
238-
}
239215
}

server/api/controllers/term-name-controller.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,6 @@ export class TermNameController {
88
static logger = new Logger("Term Name Controller");
99
static termCache = new Map<string, string>(); // cache of termCodes
1010

11-
static async getTermNames(): Promise<Term[]> {
12-
const url = `${tokens.WATERLOO_OPEN_API_BASE_URL}/Terms`;
13-
const response = await fetch(new URL(url), {
14-
method: "GET",
15-
headers: {
16-
"X-API-KEY": tokens.WATERLOO_OPEN_API_KEY as string,
17-
"Content-Type": "application/json",
18-
},
19-
});
20-
21-
const terms: Term[] = await response.json();
22-
return terms;
23-
}
24-
25-
static validateTerm(term: string): boolean {
26-
const terms = this.getTermsFile();
27-
const termCodes = terms.map((item) => item.termCode);
28-
29-
return termCodes.includes(term);
30-
}
31-
3211
static getTermsFile(): Term[] {
3312
try {
3413
const terms = fs.readFileSync("server/data/_hidden/term-list.json");
@@ -38,7 +17,7 @@ export class TermNameController {
3817
}
3918
}
4019

41-
static convertTermCodeToTermName(termCode: string) {
20+
static getTermNameFromTermCode(termCode: string) {
4221
if (this.termCache.has(termCode)) {
4322
return this.termCache.get(termCode); // Return from cache
4423
}
@@ -68,24 +47,4 @@ export class TermNameController {
6847

6948
return termName;
7049
}
71-
72-
static getTermNameFromTermCode(termCode: string) {
73-
const terms = this.getTermsFile();
74-
const target = terms.find((item) => item.termCode === termCode);
75-
return target?.name ?? this.convertTermCodeToTermName(termCode);
76-
}
77-
78-
static async overwriteTermsFile() {
79-
try {
80-
const terms = await this.getTermNames();
81-
const url = "_hidden/term-list";
82-
const fullPath = `server/data/${url}.json`;
83-
84-
fs.writeFileSync(fullPath, JSON.stringify(terms));
85-
this.logger.info("Terms file rewritten");
86-
} catch (err) {
87-
this.logger.error("Could not rewrite terms file.");
88-
this.logger.error(err);
89-
}
90-
}
9150
}

0 commit comments

Comments
 (0)