From cd0c6a469b63f901faba1e2bd65281640f5747ce Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Mon, 30 Sep 2024 11:49:15 -0400 Subject: [PATCH] Simpler quiz domain object (no db logic) --- server/models/quiz.ts | 70 +++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/server/models/quiz.ts b/server/models/quiz.ts index 36a99f5..c3024e8 100644 --- a/server/models/quiz.ts +++ b/server/models/quiz.ts @@ -1,58 +1,50 @@ import { ObjectId } from 'mongodb'; -import QuizRepository from '../repositories/quizRepository'; +import { Folder } from './folder'; +import { User } from './user'; export class Quiz { - private repository: QuizRepository; - folderId: string; - userId: string; - title: string; - content: string; - created_at: Date; - updated_at: Date; + public created_at: Date; + public updated_at: Date; - constructor(folderId: string, userId: string, title: string, content: string, repository?: QuizRepository) { - this.repository = repository || new QuizRepository(); - this.folderId = folderId; - this.userId = userId; + constructor(public folder: Folder, public user: User, public title: string, public content: string, public _id?: ObjectId) { + this.folder = folder; + this.user = user; this.title = title; this.content = content; this.created_at = new Date(); this.updated_at = new Date(); } - async create(): Promise { - return await this.repository.createQuiz(this); - } - async getOwner(quizId: string): Promise { - return await this.repository.getOwner(quizId); - } + // async getOwner(quizId: string): Promise { + // return await this.repository.getOwner(quizId); + // } - async getContent(quizId: string): Promise { - return await this.repository.getContent(quizId); - } + // async getContent(quizId: string): Promise { + // return await this.repository.getContent(quizId); + // } - async delete(quizId: string): Promise { - return await this.repository.delete(quizId); - } + // async delete(quizId: string): Promise { + // return await this.repository.delete(quizId); + // } - async deleteQuizzes(folderId: string): Promise { - return await this.repository.deleteQuizzes(folderId); - } + // async deleteQuizzes(folderId: string): Promise { + // return await this.repository.deleteQuizzes(folderId); + // } - async update(quizId: string, updateData: Partial): Promise { - return await this.repository.update(quizId, updateData); - } + // async update(quizId: string, updateData: Partial): Promise { + // return await this.repository.update(quizId, updateData); + // } - async move(quizId: string, newFolderId: string): Promise { - return await this.repository.move(quizId, newFolderId); - } + // async move(quizId: string, newFolderId: string): Promise { + // return await this.repository.move(quizId, newFolderId); + // } - async duplicate(quizId: string): Promise { - return await this.repository.duplicate(quizId); - } + // async duplicate(quizId: string): Promise { + // return await this.repository.duplicate(quizId); + // } - async quizExists(title: string, userId: string): Promise { - return await this.repository.quizExists(title, userId); - } + // async quizExists(title: string, userId: string): Promise { + // return await this.repository.quizExists(title, userId); + // } }