refactor(common): Question
This commit is contained in:
		
							parent
							
								
									d6b79dcced
								
							
						
					
					
						commit
						70a31a292c
					
				
					 6 changed files with 21 additions and 19 deletions
				
			
		|  | @ -1,9 +1,9 @@ | ||||||
| import { Request, Response } from 'express'; | import { Request, Response } from 'express'; | ||||||
| import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js'; | import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js'; | ||||||
| import { QuestionDTO, QuestionId } from '../interfaces/question.js'; |  | ||||||
| import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; | import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||||
| import { Language } from '../entities/content/language.js'; | import { Language } from '../entities/content/language.js'; | ||||||
|  | import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||||
| 
 | 
 | ||||||
| function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { | function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { | ||||||
|     const { hruid, version } = req.params; |     const { hruid, version } = req.params; | ||||||
|  |  | ||||||
|  | @ -1,15 +1,6 @@ | ||||||
| import { Question } from '../entities/questions/question.entity.js'; | import { Question } from '../entities/questions/question.entity.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; |  | ||||||
| import { mapToStudentDTO } from './student.js'; | import { mapToStudentDTO } from './student.js'; | ||||||
| import { StudentDTO } from 'dwengo-1-common/src/interfaces/student'; | import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||||
| 
 |  | ||||||
| export interface QuestionDTO { |  | ||||||
|     learningObjectIdentifier: LearningObjectIdentifier; |  | ||||||
|     sequenceNumber?: number; |  | ||||||
|     author: StudentDTO; |  | ||||||
|     timestamp?: string; |  | ||||||
|     content: string; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Convert a Question entity to a DTO format. |  * Convert a Question entity to a DTO format. | ||||||
|  | @ -30,11 +21,6 @@ export function mapToQuestionDTO(question: Question): QuestionDTO { | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface QuestionId { |  | ||||||
|     learningObjectIdentifier: LearningObjectIdentifier; |  | ||||||
|     sequenceNumber: number; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function mapToQuestionId(question: QuestionDTO): QuestionId { | export function mapToQuestionId(question: QuestionDTO): QuestionId { | ||||||
|     return { |     return { | ||||||
|         learningObjectIdentifier: question.learningObjectIdentifier, |         learningObjectIdentifier: question.learningObjectIdentifier, | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js'; | import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | import { mapToQuestionDTO, mapToQuestionId } from '../interfaces/question.js'; | ||||||
| import { Question } from '../entities/questions/question.entity.js'; | import { Question } from '../entities/questions/question.entity.js'; | ||||||
| import { Answer } from '../entities/questions/answer.entity.js'; | import { Answer } from '../entities/questions/answer.entity.js'; | ||||||
| import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js'; | import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js'; | ||||||
|  | @ -8,6 +8,7 @@ import { LearningObjectIdentifier } from '../entities/content/learning-object-id | ||||||
| import { mapToUser } from '../interfaces/user.js'; | import { mapToUser } from '../interfaces/user.js'; | ||||||
| import { Student } from '../entities/users/student.entity.js'; | import { Student } from '../entities/users/student.entity.js'; | ||||||
| import { mapToStudent } from '../interfaces/student.js'; | import { mapToStudent } from '../interfaces/student.js'; | ||||||
|  | import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||||
| 
 | 
 | ||||||
| export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { | export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { | ||||||
|     const questionRepository: QuestionRepository = getQuestionRepository(); |     const questionRepository: QuestionRepository = getQuestionRepository(); | ||||||
|  |  | ||||||
|  | @ -1,11 +1,12 @@ | ||||||
| import { getClassRepository, getLearningObjectRepository, getQuestionRepository, getTeacherRepository } from '../data/repositories.js'; | import { getClassRepository, getLearningObjectRepository, getQuestionRepository, getTeacherRepository } from '../data/repositories.js'; | ||||||
| import { mapToClassDTO } from '../interfaces/class.js'; | import { mapToClassDTO } from '../interfaces/class.js'; | ||||||
| import { getClassStudents } from './classes.js'; | import { getClassStudents } from './classes.js'; | ||||||
| import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; | import { mapToQuestionDTO, mapToQuestionId } from '../interfaces/question.js'; | ||||||
| import { mapToTeacher, mapToTeacherDTO } from '../interfaces/teacher.js'; | import { mapToTeacher, mapToTeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | import { ClassDTO } from 'dwengo-1-common/src/interfaces/class'; | ||||||
| import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher'; | import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher'; | ||||||
| import { StudentDTO } from 'dwengo-1-common/src/interfaces/student'; | import { StudentDTO } from 'dwengo-1-common/src/interfaces/student'; | ||||||
|  | import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | ||||||
|     const teacherRepository = getTeacherRepository(); |     const teacherRepository = getTeacherRepository(); | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								common/src/interfaces/answer.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								common/src/interfaces/answer.d.ts
									
										
									
									
										vendored
									
									
								
							|  | @ -1,5 +1,5 @@ | ||||||
| import { QuestionDTO } from 'dwengo-1-backend/src/interfaces/question.js'; |  | ||||||
| import { UserDTO } from './user'; | import { UserDTO } from './user'; | ||||||
|  | import { QuestionDTO } from './question'; | ||||||
| 
 | 
 | ||||||
| export interface AnswerDTO { | export interface AnswerDTO { | ||||||
|     author: UserDTO; |     author: UserDTO; | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								common/src/interfaces/question.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								common/src/interfaces/question.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | import { StudentDTO } from './student'; | ||||||
|  | 
 | ||||||
|  | export interface QuestionDTO { | ||||||
|  |     learningObjectIdentifier: LearningObjectIdentifier; | ||||||
|  |     sequenceNumber?: number; | ||||||
|  |     author: StudentDTO; | ||||||
|  |     timestamp?: string; | ||||||
|  |     content: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface QuestionId { | ||||||
|  |     learningObjectIdentifier: LearningObjectIdentifier; | ||||||
|  |     sequenceNumber: number; | ||||||
|  | } | ||||||
		Reference in a new issue