feat: add, delete student route met user logic + .js in files
This commit is contained in:
parent
e0a5596994
commit
ecad27ea4d
29 changed files with 301 additions and 159 deletions
|
@ -1,6 +1,5 @@
|
|||
import { Assignment } from "../entities/assignments/assignment.entity";
|
||||
import { Class } from "../entities/classes/class.entity";
|
||||
import { GroupDTO, mapToGroupDTO } from "./groups";
|
||||
import { Assignment } from "../entities/assignments/assignment.entity.js";
|
||||
import { GroupDTO, mapToGroupDTO } from "./groups.js";
|
||||
|
||||
export interface AssignmentDTO {
|
||||
id: number,
|
||||
|
@ -34,4 +33,4 @@ export function mapToAssignmentDTO(assignment: Assignment): AssignmentDTO {
|
|||
language: assignment.learningPathLanguage,
|
||||
// groups: assignment.groups.map(mapToGroupDTO),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Class } from "../entities/classes/class.entity";
|
||||
import { Class } from "../entities/classes/class.entity.js";
|
||||
|
||||
export interface ClassDTO {
|
||||
id: string;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Group } from "../entities/assignments/group.entity";
|
||||
import { AssignmentDTO, mapToAssignmentDTO } from "./assignments";
|
||||
import { mapToStudentDTO, StudentDTO } from "./students";
|
||||
import { Group } from "../entities/assignments/group.entity.js";
|
||||
import { AssignmentDTO, mapToAssignmentDTO } from "./assignments.js";
|
||||
import { mapToStudentDTO, StudentDTO } from "./students.js";
|
||||
|
||||
export interface GroupDTO {
|
||||
assignment: number | AssignmentDTO,
|
||||
|
@ -10,7 +10,7 @@ export interface GroupDTO {
|
|||
|
||||
export function mapToGroupDTO(group: Group): GroupDTO {
|
||||
return {
|
||||
assignment: mapToAssignmentDTO(group.assignment, group.assignment.within),
|
||||
assignment: mapToAssignmentDTO(group.assignment), // ERROR: , group.assignment.within),
|
||||
groupNumber: group.groupNumber,
|
||||
members: group.members.map(mapToStudentDTO),
|
||||
}
|
||||
|
@ -22,4 +22,4 @@ export function mapToGroupDTOId(group: Group): GroupDTO {
|
|||
groupNumber: group.groupNumber,
|
||||
members: group.members.map(member => member.username),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Student } from "../entities/users/student.entity";
|
||||
import { Student } from "../entities/users/student.entity.js";
|
||||
|
||||
export interface StudentDTO {
|
||||
id: string;
|
||||
|
@ -20,4 +20,13 @@ export function mapToStudentDTO(student: Student): StudentDTO {
|
|||
firstName: student.firstName,
|
||||
lastName: student.lastName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function mapToStudent(studentData: StudentDTO): Student {
|
||||
const student = new Student();
|
||||
student.username = studentData.username;
|
||||
student.firstName = studentData.firstName;
|
||||
student.lastName = studentData.lastName;
|
||||
|
||||
return student;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TeacherInvitation } from "../entities/classes/teacher-invitation.entity";
|
||||
import { ClassDTO, mapToClassDTO } from "./classes";
|
||||
import { mapToTeacherDTO, TeacherDTO } from "./teacher";
|
||||
import { TeacherInvitation } from "../entities/classes/teacher-invitation.entity.js";
|
||||
import { ClassDTO, mapToClassDTO } from "./classes.js";
|
||||
import { mapToTeacherDTO, TeacherDTO } from "./teacher.js";
|
||||
|
||||
export interface TeacherInvitationDTO {
|
||||
sender: string | TeacherDTO,
|
||||
|
@ -22,4 +22,4 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea
|
|||
receiver: invitation.receiver.username,
|
||||
class: invitation.class.classId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Teacher } from "../entities/users/teacher.entity";
|
||||
import { Teacher } from "../entities/users/teacher.entity.js";
|
||||
|
||||
export interface TeacherDTO {
|
||||
id: string;
|
||||
|
@ -20,4 +20,4 @@ export function mapToTeacherDTO(teacher: Teacher): TeacherDTO {
|
|||
firstName: teacher.firstName,
|
||||
lastName: teacher.lastName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
30
backend/src/interfaces/user.ts
Normal file
30
backend/src/interfaces/user.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { User } from "../entities/users/user.entity.js";
|
||||
|
||||
export interface UserDTO {
|
||||
id?: string,
|
||||
username: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
endpoints?: {
|
||||
self: string;
|
||||
classes: string;
|
||||
questions: string;
|
||||
invitations: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function mapToUserDTO(user: User): UserDTO {
|
||||
return {
|
||||
id: user.username,
|
||||
username: user.username,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapToUser<T extends User>(userData: UserDTO, userInstance: T): T {
|
||||
userInstance.username = userData.username;
|
||||
userInstance.firstName = userData.firstName;
|
||||
userInstance.lastName = userData.lastName;
|
||||
return userInstance;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue