fix: merge + types frontend controller

This commit is contained in:
Gabriellvl 2025-04-02 12:21:04 +02:00
parent 4ca568e738
commit 8ceed7f779
20 changed files with 129 additions and 92 deletions

View file

@ -10,11 +10,11 @@ import {
getTeacherQuestions,
updateClassJoinRequestStatus,
} from '../services/teachers.js';
import { ClassDTO } from '../interfaces/class.js';
import { StudentDTO } from '../interfaces/student.js';
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
import { TeacherDTO } from '../interfaces/teacher.js';
import { requireFields } from './error-helper.js';
import {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher";
import {ClassDTO} from "dwengo-1-common/src/interfaces/class";
import {StudentDTO} from "dwengo-1-common/src/interfaces/student";
import {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question";
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';

View file

@ -16,10 +16,10 @@ export function mapToAnswerDTO(answer: Answer): AnswerDTO {
};
}
export function mapToAnswerId(answer: AnswerDTO): AnswerId {
export function mapToAnswerDTOId(answer: Answer): AnswerId {
return {
author: answer.author.username,
toQuestion: mapToQuestionDTOId(answer.toQuestion),
sequenceNumber: answer.sequenceNumber,
sequenceNumber: answer.sequenceNumber!,
};
}

View file

@ -1,6 +1,7 @@
import { Question } from '../entities/questions/question.entity.js';
import { mapToStudentDTO } from './student.js';
import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question';
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier";
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
return {

View file

@ -1,16 +1,12 @@
import { mapToStudentDTO, StudentDTO } from './student.js';
import { mapToStudentDTO } from './student.js';
import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity.js';
import { getClassJoinRequestRepository } from '../data/repositories.js';
import { Student } from '../entities/users/student.entity.js';
import { Class } from '../entities/classes/class.entity.js';
import {ClassJoinRequestDTO} from "dwengo-1-common/src/interfaces/class-join-request";
export interface StudentRequestDTO {
requester: StudentDTO;
class: string;
status: ClassJoinRequestStatus;
}
export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentRequestDTO {
export function mapToStudentRequestDTO(request: ClassJoinRequest): ClassJoinRequestDTO {
return {
requester: mapToStudentDTO(request.requester),
class: request.class.classId!,

View file

@ -1,11 +1,13 @@
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from '../interfaces/question.js';
import {mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
import { Question } from '../entities/questions/question.entity.js';
import { Answer } from '../entities/questions/answer.entity.js';
import { AnswerDTO, AnswerId, mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js';
import {mapToAnswerDTO, mapToAnswerDTOId} from '../interfaces/answer.js';
import { QuestionRepository } from '../data/questions/question-repository.js';
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
import { mapToStudent } from '../interfaces/student.js';
import {QuestionDTO, QuestionId} from "dwengo-1-common/src/interfaces/question";
import {AnswerDTO, AnswerId} from "dwengo-1-common/src/interfaces/answer";
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
const questionRepository: QuestionRepository = getQuestionRepository();

View file

@ -19,7 +19,7 @@ import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { StudentDTO } from '../../src/interfaces/student.js';
import {StudentDTO} from "dwengo-1-common/src/interfaces/student";
describe('Student controllers', () => {
let req: Partial<Request>;

View file

@ -15,7 +15,8 @@ import {
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { getStudentRequestsHandler } from '../../src/controllers/students.js';
import { TeacherDTO } from '../../src/interfaces/teacher.js';
import {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher";
describe('Teacher controllers', () => {
let req: Partial<Request>;