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.
128 lines (127 loc) • 5.51 kB
JavaScript
;
/**
* @moduleName: Quiz Entity Model - Database Schema Definition
* @version: 1.0.0
* @since: 2025-07-22
* @lastUpdated: 2025-07-24
* @projectSummary: MCP Quiz Server - TypeORM entity model for Quiz with relationships to questions and results
* @techStack: TypeORM, TypeScript, Decorators, Entity-Relationship Model, SQLite
* @dependency: typeorm, reflect-metadata
* @interModuleDependency: Question entity, QuizResult entity, database repositories
* @requirementsTraceability:
* {@link Requirements.REQ_DATA_001} (TypeORM Quiz Schema)
* @briefDescription: Core Quiz entity with one-to-many relationships to questions and quiz results, supporting metadata, audit fields, categories, difficulty levels, and time limits
* @methods: Entity properties with TypeORM decorators, validation constraints, relationship mappings
* @contributors: Jorge the Database Architect, GitHub Copilot
* @examples: const quiz = new Quiz(); quiz.title = "TypeScript Quiz"; quiz.difficulty = "medium";
* @vulnerabilitiesAssessment: Input validation through TypeORM decorators, SQL injection prevention via ORM, audit trail with timestamps, relationship integrity enforced at database level
*/
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Quiz = void 0;
const typeorm_1 = require("typeorm");
const Question_1 = require("./Question");
const QuizResult_1 = require("./QuizResult");
let Quiz = class Quiz {
// Virtual properties
get questionCount() {
var _a;
return ((_a = this.questions) === null || _a === void 0 ? void 0 : _a.length) || 0;
}
get averageScore() {
var _a;
if (!((_a = this.results) === null || _a === void 0 ? void 0 : _a.length))
return 0;
const totalScore = this.results.reduce((sum, result) => sum + result.score, 0);
return Math.round((totalScore / this.results.length) * 100) / 100;
}
// Helper methods
toJSON() {
return {
id: this.id,
title: this.title,
description: this.description,
category: this.category,
difficulty: this.difficulty,
timeLimit: this.timeLimit,
isActive: this.isActive,
totalAttempts: this.totalAttempts,
questionCount: this.questionCount,
averageScore: this.averageScore,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
questions: this.questions,
metadata: this.metadata,
};
}
};
exports.Quiz = Quiz;
__decorate([
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
__metadata("design:type", String)
], Quiz.prototype, "id", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'varchar', length: 255 }),
__metadata("design:type", String)
], Quiz.prototype, "title", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
__metadata("design:type", String)
], Quiz.prototype, "description", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'varchar', length: 100, default: 'general' }),
__metadata("design:type", String)
], Quiz.prototype, "category", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'varchar', length: 50, default: 'medium' }),
__metadata("design:type", String)
], Quiz.prototype, "difficulty", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'integer', default: 10 }),
__metadata("design:type", Number)
], Quiz.prototype, "timeLimit", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'boolean', default: true }),
__metadata("design:type", Boolean)
], Quiz.prototype, "isActive", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'integer', default: 0 }),
__metadata("design:type", Number)
], Quiz.prototype, "totalAttempts", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'json', nullable: true }),
__metadata("design:type", Object)
], Quiz.prototype, "metadata", void 0);
__decorate([
(0, typeorm_1.CreateDateColumn)(),
__metadata("design:type", Date)
], Quiz.prototype, "createdAt", void 0);
__decorate([
(0, typeorm_1.UpdateDateColumn)(),
__metadata("design:type", Date)
], Quiz.prototype, "updatedAt", void 0);
__decorate([
(0, typeorm_1.OneToMany)(() => Question_1.Question, question => question.quiz, {
cascade: true,
eager: false,
}),
__metadata("design:type", Array)
], Quiz.prototype, "questions", void 0);
__decorate([
(0, typeorm_1.OneToMany)(() => QuizResult_1.QuizResult, result => result.quiz, {
cascade: false,
eager: false,
}),
__metadata("design:type", Array)
], Quiz.prototype, "results", void 0);
exports.Quiz = Quiz = __decorate([
(0, typeorm_1.Entity)('quizzes')
], Quiz);