Merge remote-tracking branch 'origin/feat/teacher-invitation' into feat/teacher-invitation
# Conflicts: # backend/tests/controllers/teacher-invitations.test.ts
This commit is contained in:
		
						commit
						9017b75ce1
					
				
					 8 changed files with 45 additions and 48 deletions
				
			
		|  | @ -1,12 +1,6 @@ | ||||||
| import { Request, Response } from 'express'; | import { Request, Response } from 'express'; | ||||||
| import { requireFields } from './error-helper'; | import { requireFields } from './error-helper'; | ||||||
| import { | import { createInvitation, deleteInvitation, getAllInvitations, getInvitation, updateInvitation } from '../services/teacher-invitations'; | ||||||
|     createInvitation, |  | ||||||
|     deleteInvitation, |  | ||||||
|     getAllInvitations, |  | ||||||
|     getInvitation, |  | ||||||
|     updateInvitation |  | ||||||
| } from '../services/teacher-invitations'; |  | ||||||
| import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
| 
 | 
 | ||||||
| export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> { | export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> { | ||||||
|  | @ -62,7 +56,9 @@ export async function deleteInvitationHandler(req: Request, res: Response): Prom | ||||||
|     requireFields({ sender, receiver, classId }); |     requireFields({ sender, receiver, classId }); | ||||||
| 
 | 
 | ||||||
|     const data: TeacherInvitationData = { |     const data: TeacherInvitationData = { | ||||||
|         sender, receiver, class: classId |         sender, | ||||||
|  |         receiver, | ||||||
|  |         class: classId, | ||||||
|     }; |     }; | ||||||
|     const invitation = await deleteInvitation(data); |     const invitation = await deleteInvitation(data); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import {DwengoEntityRepository} from '../dwengo-entity-repository.js'; | ||||||
| import { Class } from '../../entities/classes/class.entity.js'; | import { Class } from '../../entities/classes/class.entity.js'; | ||||||
| import { TeacherInvitation } from '../../entities/classes/teacher-invitation.entity.js'; | import { TeacherInvitation } from '../../entities/classes/teacher-invitation.entity.js'; | ||||||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||||
| import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherInvitation> { | export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherInvitation> { | ||||||
|     public async findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> { |     public async findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import {Entity, Enum, ManyToOne} from '@mikro-orm/core'; | ||||||
| import { Teacher } from '../users/teacher.entity.js'; | import { Teacher } from '../users/teacher.entity.js'; | ||||||
| import { Class } from './class.entity.js'; | import { Class } from './class.entity.js'; | ||||||
| import { TeacherInvitationRepository } from '../../data/classes/teacher-invitation-repository.js'; | import { TeacherInvitationRepository } from '../../data/classes/teacher-invitation-repository.js'; | ||||||
| import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Invitation of a teacher into a class (in order to teach it). |  * Invitation of a teacher into a class (in order to teach it). | ||||||
|  |  | ||||||
|  | @ -4,14 +4,14 @@ import {TeacherInvitationDTO} from '@dwengo-1/common/interfaces/teacher-invitati | ||||||
| import { getTeacherInvitationRepository } from '../data/repositories'; | import { getTeacherInvitationRepository } from '../data/repositories'; | ||||||
| import { Teacher } from '../entities/users/teacher.entity'; | import { Teacher } from '../entities/users/teacher.entity'; | ||||||
| import { Class } from '../entities/classes/class.entity'; | import { Class } from '../entities/classes/class.entity'; | ||||||
| import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||||
|     return { |     return { | ||||||
|         sender: mapToUserDTO(invitation.sender), |         sender: mapToUserDTO(invitation.sender), | ||||||
|         receiver: mapToUserDTO(invitation.receiver), |         receiver: mapToUserDTO(invitation.receiver), | ||||||
|         classId: invitation.class.classId!, |         classId: invitation.class.classId!, | ||||||
|         status: invitation.status |         status: invitation.status, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -20,7 +20,7 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea | ||||||
|         sender: invitation.sender.username, |         sender: invitation.sender.username, | ||||||
|         receiver: invitation.receiver.username, |         receiver: invitation.receiver.username, | ||||||
|         classId: invitation.class.classId!, |         classId: invitation.class.classId!, | ||||||
|         status: invitation.status |         status: invitation.status, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,8 +2,9 @@ import express from 'express'; | ||||||
| import { | import { | ||||||
|     createInvitationHandler, |     createInvitationHandler, | ||||||
|     deleteInvitationHandler, |     deleteInvitationHandler, | ||||||
|     getAllInvitationsHandler, getInvitationHandler, |     getAllInvitationsHandler, | ||||||
|     updateInvitationHandler |     getInvitationHandler, | ||||||
|  |     updateInvitationHandler, | ||||||
| } from '../controllers/teacher-invitations'; | } from '../controllers/teacher-invitations'; | ||||||
| 
 | 
 | ||||||
| const router = express.Router({ mergeParams: true }); | const router = express.Router({ mergeParams: true }); | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import {TeacherInvitationData, TeacherInvitationDTO} from '@dwengo-1/common/inte | ||||||
| import { ConflictException } from '../exceptions/conflict-exception'; | import { ConflictException } from '../exceptions/conflict-exception'; | ||||||
| import { NotFoundException } from '../exceptions/not-found-exception'; | import { NotFoundException } from '../exceptions/not-found-exception'; | ||||||
| import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity'; | import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity'; | ||||||
| import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| export async function getAllInvitations(username: string, sent: boolean): Promise<TeacherInvitationDTO[]> { | export async function getAllInvitations(username: string, sent: boolean): Promise<TeacherInvitationDTO[]> { | ||||||
|     const teacher = await fetchTeacher(username); |     const teacher = await fetchTeacher(username); | ||||||
|  |  | ||||||
|  | @ -2,35 +2,35 @@ import {EntityManager} from '@mikro-orm/core'; | ||||||
| import { TeacherInvitation } from '../../../src/entities/classes/teacher-invitation.entity'; | import { TeacherInvitation } from '../../../src/entities/classes/teacher-invitation.entity'; | ||||||
| import { Teacher } from '../../../src/entities/users/teacher.entity'; | import { Teacher } from '../../../src/entities/users/teacher.entity'; | ||||||
| import { Class } from '../../../src/entities/classes/class.entity'; | import { Class } from '../../../src/entities/classes/class.entity'; | ||||||
| import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| export function makeTestTeacherInvitations(em: EntityManager, teachers: Teacher[], classes: Class[]): TeacherInvitation[] { | export function makeTestTeacherInvitations(em: EntityManager, teachers: Teacher[], classes: Class[]): TeacherInvitation[] { | ||||||
|     const teacherInvitation01 = em.create(TeacherInvitation, { |     const teacherInvitation01 = em.create(TeacherInvitation, { | ||||||
|         sender: teachers[1], |         sender: teachers[1], | ||||||
|         receiver: teachers[0], |         receiver: teachers[0], | ||||||
|         class: classes[1], |         class: classes[1], | ||||||
|         status: ClassStatus.Open |         status: ClassStatus.Open, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const teacherInvitation02 = em.create(TeacherInvitation, { |     const teacherInvitation02 = em.create(TeacherInvitation, { | ||||||
|         sender: teachers[1], |         sender: teachers[1], | ||||||
|         receiver: teachers[2], |         receiver: teachers[2], | ||||||
|         class: classes[1], |         class: classes[1], | ||||||
|         status: ClassStatus.Open |         status: ClassStatus.Open, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const teacherInvitation03 = em.create(TeacherInvitation, { |     const teacherInvitation03 = em.create(TeacherInvitation, { | ||||||
|         sender: teachers[2], |         sender: teachers[2], | ||||||
|         receiver: teachers[0], |         receiver: teachers[0], | ||||||
|         class: classes[2], |         class: classes[2], | ||||||
|         status: ClassStatus.Open |         status: ClassStatus.Open, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const teacherInvitation04 = em.create(TeacherInvitation, { |     const teacherInvitation04 = em.create(TeacherInvitation, { | ||||||
|         sender: teachers[0], |         sender: teachers[0], | ||||||
|         receiver: teachers[1], |         receiver: teachers[1], | ||||||
|         class: classes[0], |         class: classes[0], | ||||||
|         status: ClassStatus.Open |         status: ClassStatus.Open, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return [teacherInvitation01, teacherInvitation02, teacherInvitation03, teacherInvitation04]; |     return [teacherInvitation01, teacherInvitation02, teacherInvitation03, teacherInvitation04]; | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { UserDTO } from './user'; | import { UserDTO } from './user'; | ||||||
| import {ClassStatus} from "../util/class-join-request"; | import { ClassStatus } from '../util/class-join-request'; | ||||||
| 
 | 
 | ||||||
| export interface TeacherInvitationDTO { | export interface TeacherInvitationDTO { | ||||||
|     sender: string | UserDTO; |     sender: string | UserDTO; | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl