refactor(backend): logger i.p.v. console
This commit is contained in:
parent
30ec73a88d
commit
c14d6c53da
9 changed files with 30 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js';
|
||||
import { ClassDTO } from '../interfaces/class.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllClassesHandler(req: Request, res: Response): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -49,7 +50,7 @@ export async function getClassHandler(req: Request, res: Response): Promise<void
|
|||
|
||||
res.json(cls);
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
getLogger().error('Error fetching learning objects:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Student } from '../entities/users/student.entity.js';
|
|||
import { StudentDTO } from '../interfaces/student.js';
|
||||
import { getStudentRepository } from '../data/repositories.js';
|
||||
import { UserDTO } from '../interfaces/user.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
// TODO: accept arguments (full, ...)
|
||||
// TODO: endpoints
|
||||
|
@ -104,7 +105,7 @@ export async function getStudentClassesHandler(req: Request, res: Response): Pro
|
|||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
getLogger().error('Error fetching learning objects:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
|||
import { Teacher } from '../entities/users/teacher.entity.js';
|
||||
import { TeacherDTO } from '../interfaces/teacher.js';
|
||||
import { getTeacherRepository } from '../data/repositories.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
|
@ -100,7 +101,7 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
|
|||
|
||||
res.status(201).json(classes);
|
||||
} catch (error) {
|
||||
console.error('Error fetching classes by teacher:', error);
|
||||
getLogger().error('Error fetching classes by teacher:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +120,7 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro
|
|||
|
||||
res.status(201).json(students);
|
||||
} catch (error) {
|
||||
console.error('Error fetching students by teacher:', error);
|
||||
getLogger().error('Error fetching students by teacher:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr
|
|||
|
||||
res.status(201).json(questions);
|
||||
} catch (error) {
|
||||
console.error('Error fetching questions by teacher:', error);
|
||||
getLogger().error('Error fetching questions by teacher:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Request, Response } from 'express';
|
|||
import { UserService } from '../services/users.js';
|
||||
import { UserDTO } from '../interfaces/user.js';
|
||||
import { User } from '../entities/users/user.entity.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllUsersHandler<T extends User>(req: Request, res: Response, service: UserService<T>): Promise<void> {
|
||||
try {
|
||||
|
@ -16,7 +17,7 @@ export async function getAllUsersHandler<T extends User>(req: Request, res: Resp
|
|||
|
||||
res.status(201).json(users);
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching users:', error);
|
||||
getLogger().error('❌ Error fetching users:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +42,14 @@ export async function getUserHandler<T extends User>(req: Request, res: Response
|
|||
|
||||
res.status(201).json(user);
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching users:', error);
|
||||
getLogger().error('❌ Error fetching users:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function createUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>, UserClass: new () => T) {
|
||||
try {
|
||||
console.log('req', req);
|
||||
getLogger().debug({ req: req });
|
||||
const userData = req.body as UserDTO;
|
||||
|
||||
if (!userData.username || !userData.firstName || !userData.lastName) {
|
||||
|
@ -61,7 +62,7 @@ export async function createUserHandler<T extends User>(req: Request, res: Respo
|
|||
const newUser = await service.createUser(userData, UserClass);
|
||||
res.status(201).json(newUser);
|
||||
} catch (error) {
|
||||
console.error('❌ Error creating user:', error);
|
||||
getLogger().error('❌ Error creating user:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ export async function deleteUserHandler<T extends User>(req: Request, res: Respo
|
|||
|
||||
res.status(200).json(deletedUser);
|
||||
} catch (error) {
|
||||
console.error('❌ Error deleting user:', error);
|
||||
getLogger().error('❌ Error deleting user:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Assignment } from '../entities/assignments/assignment.entity.js';
|
|||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { languageMap } from '../entities/content/language.js';
|
||||
import { GroupDTO, mapToGroupDTO } from './group.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export interface AssignmentDTO {
|
||||
id: number;
|
||||
|
@ -46,7 +47,7 @@ export function mapToAssignment(assignmentData: AssignmentDTO, cls: Class): Assi
|
|||
assignment.learningPathLanguage = languageMap[assignmentData.language] || FALLBACK_LANG;
|
||||
assignment.within = cls;
|
||||
|
||||
console.log(assignment);
|
||||
getLogger().debug(assignment);
|
||||
|
||||
return assignment;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise<GroupDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -45,7 +46,7 @@ export async function createGroup(groupData: GroupDTO, classid: string, assignme
|
|||
const memberUsernames = (groupData.members as string[]) || []; // TODO check if groupdata.members is a list
|
||||
const members = (await Promise.all([...memberUsernames].map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null);
|
||||
|
||||
console.log(members);
|
||||
getLogger().debug(members);
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
@ -71,7 +72,7 @@ export async function createGroup(groupData: GroupDTO, classid: string, assignme
|
|||
|
||||
return newGroup;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
getLogger().error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -95,8 +96,7 @@ export async function getAllGroups(classId: string, assignmentNumber: number, fu
|
|||
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
||||
|
||||
if (full) {
|
||||
console.log('full');
|
||||
console.log(groups);
|
||||
getLogger().debug({ full: full, groups: groups });
|
||||
return groups.map(mapToGroupDTO);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { DWENGO_API_BASE } from '../config.js';
|
||||
import { fetchWithLogging } from '../util/api-helper.js';
|
||||
import { FilteredLearningObject, LearningObjectMetadata, LearningObjectNode, LearningPathResponse } from '../interfaces/learning-content.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject {
|
||||
return {
|
||||
|
@ -37,7 +38,7 @@ export async function getLearningObjectById(hruid: string, language: string): Pr
|
|||
);
|
||||
|
||||
if (!metadata) {
|
||||
console.error(`⚠️ WARNING: Learning object "${hruid}" not found.`);
|
||||
getLogger().error(`⚠️ WARNING: Learning object "${hruid}" not found.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,7 @@ async function fetchLearningObjects(hruid: string, full: boolean, language: stri
|
|||
const learningPathResponse: LearningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`);
|
||||
|
||||
if (!learningPathResponse.success || !learningPathResponse.data?.length) {
|
||||
console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
||||
getLogger().error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ async function fetchLearningObjects(hruid: string, full: boolean, language: stri
|
|||
objects.filter((obj): obj is FilteredLearningObject => obj !== null)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching learning objects:', error);
|
||||
getLogger().error('❌ Error fetching learning objects:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student
|
|||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
import { UserService } from './users.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
@ -35,7 +36,7 @@ export async function createStudent(userData: StudentDTO): Promise<StudentDTO |
|
|||
|
||||
return mapToStudentDTO(newStudent);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
getLogger().error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +55,7 @@ export async function deleteStudent(username: string): Promise<StudentDTO | null
|
|||
|
||||
return mapToStudentDTO(user);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
getLogger().error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../i
|
|||
import { UserService } from './users.js';
|
||||
import { mapToUser } from '../interfaces/user.js';
|
||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllTeachers(): Promise<TeacherDTO[]> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
|
@ -40,7 +41,7 @@ export async function createTeacher(userData: TeacherDTO): Promise<TeacherDTO |
|
|||
|
||||
return mapToTeacherDTO(newTeacher);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
getLogger().error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ export async function deleteTeacher(username: string): Promise<TeacherDTO | null
|
|||
|
||||
return mapToTeacherDTO(user);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
getLogger().error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue