fix: Vervang console met logger
This commit is contained in:
		
							parent
							
								
									86dadeae81
								
							
						
					
					
						commit
						8f5b625cc3
					
				
					 4 changed files with 25 additions and 6 deletions
				
			
		|  | @ -8,4 +8,14 @@ export default [ | ||||||
|             globals: globals.node, |             globals: globals.node, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|  | 
 | ||||||
|  |     { | ||||||
|  |         files: [ 'tests/**/*.ts'], | ||||||
|  |         languageOptions: { | ||||||
|  |             globals: globals.node | ||||||
|  |         }, | ||||||
|  |         rules: { | ||||||
|  |             'no-console': 'off' | ||||||
|  |         } | ||||||
|  |     } | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
|  | @ -7,6 +7,9 @@ import { getUrlStringForLearningObject } from '../../util/links'; | ||||||
| import processingService from './processing/processing-service'; | import processingService from './processing/processing-service'; | ||||||
| import { NotFoundError } from '@mikro-orm/core'; | import { NotFoundError } from '@mikro-orm/core'; | ||||||
| import learningObjectService from './learning-object-service'; | import learningObjectService from './learning-object-service'; | ||||||
|  | import {getLogger, Logger} from "../../logging/initalize"; | ||||||
|  | 
 | ||||||
|  | const logger: Logger = getLogger(); | ||||||
| 
 | 
 | ||||||
| function convertLearningObject(learningObject: LearningObject | null): FilteredLearningObject | null { | function convertLearningObject(learningObject: LearningObject | null): FilteredLearningObject | null { | ||||||
|     if (!learningObject) { |     if (!learningObject) { | ||||||
|  | @ -100,7 +103,7 @@ const databaseLearningObjectProvider: LearningObjectProvider = { | ||||||
|                     version: it.version, |                     version: it.version, | ||||||
|                 }); |                 }); | ||||||
|                 if (learningObject === null) { |                 if (learningObject === null) { | ||||||
|                     console.log(`WARN: Learning object corresponding with node ${it} not found!`); |                     logger.warn(`WARN: Learning object corresponding with node ${it} not found!`); | ||||||
|                 } |                 } | ||||||
|                 return learningObject; |                 return learningObject; | ||||||
|             }) |             }) | ||||||
|  |  | ||||||
|  | @ -10,6 +10,9 @@ import { | ||||||
| } from '../../interfaces/learning-content.js'; | } from '../../interfaces/learning-content.js'; | ||||||
| import dwengoApiLearningPathProvider from '../learning-paths/dwengo-api-learning-path-provider.js'; | import dwengoApiLearningPathProvider from '../learning-paths/dwengo-api-learning-path-provider.js'; | ||||||
| import { LearningObjectProvider } from './learning-object-provider'; | import { LearningObjectProvider } from './learning-object-provider'; | ||||||
|  | import {getLogger, Logger} from "../../logging/initalize"; | ||||||
|  | 
 | ||||||
|  | const logger: Logger = getLogger(); | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Helper function to convert the learning object metadata retrieved from the API to a FilteredLearningObject which |  * Helper function to convert the learning object metadata retrieved from the API to a FilteredLearningObject which | ||||||
|  | @ -52,7 +55,7 @@ async function fetchLearningObjects(learningPathId: LearningPathIdentifier, full | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         if (!learningPathResponse.success || !learningPathResponse.data?.length) { |         if (!learningPathResponse.success || !learningPathResponse.data?.length) { | ||||||
|             console.error(`⚠️ WARNING: Learning path "${learningPathId.hruid}" exists but contains no learning objects.`); |             logger.warn(`⚠️ WARNING: Learning path "${learningPathId.hruid}" exists but contains no learning objects.`); | ||||||
|             return []; |             return []; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -71,7 +74,7 @@ async function fetchLearningObjects(learningPathId: LearningPathIdentifier, full | ||||||
|             ) |             ) | ||||||
|         ).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null)); |         ).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null)); | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|         console.error('❌ Error fetching learning objects:', error); |         logger.error('❌ Error fetching learning objects:', error); | ||||||
|         return []; |         return []; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -91,7 +94,7 @@ const dwengoApiLearningObjectProvider: LearningObjectProvider = { | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         if (!metadata || typeof metadata !== 'object') { |         if (!metadata || typeof metadata !== 'object') { | ||||||
|             console.error(`⚠️ WARNING: Learning object "${id.hruid}" not found.`); |             logger.warn(`⚠️ WARNING: Learning object "${id.hruid}" not found.`); | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -123,7 +126,7 @@ const dwengoApiLearningObjectProvider: LearningObjectProvider = { | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         if (!html) { |         if (!html) { | ||||||
|             console.error(`⚠️ WARNING: Learning object "${id.hruid}" not found.`); |             logger.warn(`⚠️ WARNING: Learning object "${id.hruid}" not found.`); | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,9 @@ import { fetchWithLogging } from '../../util/apiHelper.js'; | ||||||
| import { DWENGO_API_BASE } from '../../config.js'; | import { DWENGO_API_BASE } from '../../config.js'; | ||||||
| import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content.js'; | import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content.js'; | ||||||
| import { LearningPathProvider } from './learning-path-provider'; | import { LearningPathProvider } from './learning-path-provider'; | ||||||
|  | import {getLogger, Logger} from "../../logging/initalize"; | ||||||
|  | 
 | ||||||
|  | const logger: Logger = getLogger(); | ||||||
| 
 | 
 | ||||||
| const dwengoApiLearningPathProvider: LearningPathProvider = { | const dwengoApiLearningPathProvider: LearningPathProvider = { | ||||||
|     async fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> { |     async fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> { | ||||||
|  | @ -20,7 +23,7 @@ const dwengoApiLearningPathProvider: LearningPathProvider = { | ||||||
|         const learningPaths = await fetchWithLogging<LearningPath[]>(apiUrl, `Learning paths for ${source}`, { params }); |         const learningPaths = await fetchWithLogging<LearningPath[]>(apiUrl, `Learning paths for ${source}`, { params }); | ||||||
| 
 | 
 | ||||||
|         if (!learningPaths || learningPaths.length === 0) { |         if (!learningPaths || learningPaths.length === 0) { | ||||||
|             console.error(`⚠️ WARNING: No learning paths found for ${source}.`); |             logger.warn(`⚠️ WARNING: No learning paths found for ${source}.`); | ||||||
|             return { |             return { | ||||||
|                 success: false, |                 success: false, | ||||||
|                 source, |                 source, | ||||||
|  |  | ||||||
		Reference in a new issue