UNPKG

mcp-quiz-server

Version:

🧠 AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.

131 lines (130 loc) • 5.17 kB
"use strict"; /** * @moduleName: Question Entity Model * @version: 1.0.0 * @since: 2025-07-22 * @lastUpdated: 2025-07-22 * @projectSummary: TypeORM entity model for Question with relationship to Quiz * @techStack: TypeORM, TypeScript, Decorators, JSON Column Support * @dependency: typeorm, reflect-metadata * @interModuleDependency: ./Quiz * @requirementsTraceability: * {@link Requirements.REQ_DATA_001} (TypeORM Quiz Schema) * @briefDescription: Question entity with multiple choice options, correct answer tracking, and quiz relationship * @contributors: Jorge the Database Architect * @vulnerabilitiesAssessment: * - Options stored as JSON array for flexibility * - Answer validation through entity methods * - Foreign key constraints for data integrity * - Type safety through TypeScript decorators */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var Question_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.Question = void 0; const typeorm_1 = require("typeorm"); const Quiz_1 = require("./Quiz"); let Question = Question_1 = class Question { // Helper methods isCorrectAnswer(userAnswer) { return this.answer.trim().toLowerCase() === userAnswer.trim().toLowerCase(); } validateOptions() { return this.options.length >= 2 && this.options.includes(this.answer); } toJSON() { return { id: this.id, quizId: this.quizId, question: this.question, options: this.options, answer: this.answer, explanation: this.explanation, order: this.order, type: this.type, points: this.points, createdAt: this.createdAt, updatedAt: this.updatedAt, metadata: this.metadata, }; } // Static factory method for creating questions static create(data) { const question = new Question_1(); question.question = data.question; question.options = data.options; question.answer = data.answer; question.explanation = data.explanation; question.order = data.order || 1; question.type = data.type || 'multiple_choice'; question.points = data.points || 1; return question; } }; exports.Question = Question; __decorate([ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'), __metadata("design:type", String) ], Question.prototype, "id", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'uuid' }), __metadata("design:type", String) ], Question.prototype, "quizId", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'text' }), __metadata("design:type", String) ], Question.prototype, "question", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json' }), __metadata("design:type", Array) ], Question.prototype, "options", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 500 }), __metadata("design:type", String) ], Question.prototype, "answer", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], Question.prototype, "explanation", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'integer', default: 1 }), __metadata("design:type", Number) ], Question.prototype, "order", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 50, default: 'multiple_choice' }), __metadata("design:type", String) ], Question.prototype, "type", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'integer', default: 1 }), __metadata("design:type", Number) ], Question.prototype, "points", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Question.prototype, "metadata", void 0); __decorate([ (0, typeorm_1.CreateDateColumn)(), __metadata("design:type", Date) ], Question.prototype, "createdAt", void 0); __decorate([ (0, typeorm_1.UpdateDateColumn)(), __metadata("design:type", Date) ], Question.prototype, "updatedAt", void 0); __decorate([ (0, typeorm_1.ManyToOne)(() => Quiz_1.Quiz, quiz => quiz.questions, { onDelete: 'CASCADE', }), (0, typeorm_1.JoinColumn)({ name: 'quizId' }), __metadata("design:type", Quiz_1.Quiz) ], Question.prototype, "quiz", void 0); exports.Question = Question = Question_1 = __decorate([ (0, typeorm_1.Entity)('questions') ], Question);