@@ -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