@octo-cyber/quiz-engine 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/controllers/attempt.controller.d.ts +3 -0
  2. package/dist/controllers/attempt.controller.d.ts.map +1 -0
  3. package/dist/controllers/attempt.controller.js +83 -0
  4. package/dist/controllers/attempt.controller.js.map +1 -0
  5. package/dist/controllers/category.controller.d.ts +3 -0
  6. package/dist/controllers/category.controller.d.ts.map +1 -0
  7. package/dist/controllers/category.controller.js +38 -0
  8. package/dist/controllers/category.controller.js.map +1 -0
  9. package/dist/controllers/exam.controller.d.ts +3 -0
  10. package/dist/controllers/exam.controller.d.ts.map +1 -0
  11. package/dist/controllers/exam.controller.js +48 -0
  12. package/dist/controllers/exam.controller.js.map +1 -0
  13. package/dist/controllers/index.d.ts +7 -0
  14. package/dist/controllers/index.d.ts.map +1 -0
  15. package/dist/controllers/index.js +16 -0
  16. package/dist/controllers/index.js.map +1 -0
  17. package/dist/controllers/paper.controller.d.ts +3 -0
  18. package/dist/controllers/paper.controller.d.ts.map +1 -0
  19. package/dist/controllers/paper.controller.js +70 -0
  20. package/dist/controllers/paper.controller.js.map +1 -0
  21. package/dist/controllers/question.controller.d.ts +3 -0
  22. package/dist/controllers/question.controller.d.ts.map +1 -0
  23. package/dist/controllers/question.controller.js +59 -0
  24. package/dist/controllers/question.controller.js.map +1 -0
  25. package/dist/controllers/statistics.controller.d.ts +3 -0
  26. package/dist/controllers/statistics.controller.d.ts.map +1 -0
  27. package/dist/controllers/statistics.controller.js +37 -0
  28. package/dist/controllers/statistics.controller.js.map +1 -0
  29. package/dist/entities/index.d.ts +24 -0
  30. package/dist/entities/index.d.ts.map +1 -0
  31. package/dist/entities/index.js +43 -0
  32. package/dist/entities/index.js.map +1 -0
  33. package/dist/entities/quiz-answer.entity.d.ts +19 -0
  34. package/dist/entities/quiz-answer.entity.d.ts.map +1 -0
  35. package/dist/entities/quiz-answer.entity.js +81 -0
  36. package/dist/entities/quiz-answer.entity.js.map +1 -0
  37. package/dist/entities/quiz-attempt.entity.d.ts +17 -0
  38. package/dist/entities/quiz-attempt.entity.d.ts.map +1 -0
  39. package/dist/entities/quiz-attempt.entity.js +80 -0
  40. package/dist/entities/quiz-attempt.entity.js.map +1 -0
  41. package/dist/entities/quiz-category.entity.d.ts +10 -0
  42. package/dist/entities/quiz-category.entity.d.ts.map +1 -0
  43. package/dist/entities/quiz-category.entity.js +55 -0
  44. package/dist/entities/quiz-category.entity.js.map +1 -0
  45. package/dist/entities/quiz-exam.entity.d.ts +25 -0
  46. package/dist/entities/quiz-exam.entity.d.ts.map +1 -0
  47. package/dist/entities/quiz-exam.entity.js +99 -0
  48. package/dist/entities/quiz-exam.entity.js.map +1 -0
  49. package/dist/entities/quiz-paper-question.entity.d.ts +12 -0
  50. package/dist/entities/quiz-paper-question.entity.d.ts.map +1 -0
  51. package/dist/entities/quiz-paper-question.entity.js +58 -0
  52. package/dist/entities/quiz-paper-question.entity.js.map +1 -0
  53. package/dist/entities/quiz-paper.entity.d.ts +18 -0
  54. package/dist/entities/quiz-paper.entity.d.ts.map +1 -0
  55. package/dist/entities/quiz-paper.entity.js +75 -0
  56. package/dist/entities/quiz-paper.entity.js.map +1 -0
  57. package/dist/entities/quiz-question.entity.d.ts +28 -0
  58. package/dist/entities/quiz-question.entity.d.ts.map +1 -0
  59. package/dist/entities/quiz-question.entity.js +107 -0
  60. package/dist/entities/quiz-question.entity.js.map +1 -0
  61. package/dist/index.d.ts +27 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +66 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/quiz-engine.module.d.ts +8 -0
  66. package/dist/quiz-engine.module.d.ts.map +1 -0
  67. package/dist/quiz-engine.module.js +45 -0
  68. package/dist/quiz-engine.module.js.map +1 -0
  69. package/dist/schemas/attempt.schema.d.ts +47 -0
  70. package/dist/schemas/attempt.schema.d.ts.map +1 -0
  71. package/dist/schemas/attempt.schema.js +19 -0
  72. package/dist/schemas/attempt.schema.js.map +1 -0
  73. package/dist/schemas/category.schema.d.ts +36 -0
  74. package/dist/schemas/category.schema.d.ts.map +1 -0
  75. package/dist/schemas/category.schema.js +12 -0
  76. package/dist/schemas/category.schema.js.map +1 -0
  77. package/dist/schemas/exam.schema.d.ts +70 -0
  78. package/dist/schemas/exam.schema.d.ts.map +1 -0
  79. package/dist/schemas/exam.schema.js +20 -0
  80. package/dist/schemas/exam.schema.js.map +1 -0
  81. package/dist/schemas/paper.schema.d.ts +71 -0
  82. package/dist/schemas/paper.schema.d.ts.map +1 -0
  83. package/dist/schemas/paper.schema.js +26 -0
  84. package/dist/schemas/paper.schema.js.map +1 -0
  85. package/dist/schemas/question.schema.d.ts +147 -0
  86. package/dist/schemas/question.schema.d.ts.map +1 -0
  87. package/dist/schemas/question.schema.js +32 -0
  88. package/dist/schemas/question.schema.js.map +1 -0
  89. package/dist/services/attempt.service.d.ts +33 -0
  90. package/dist/services/attempt.service.d.ts.map +1 -0
  91. package/dist/services/attempt.service.js +197 -0
  92. package/dist/services/attempt.service.js.map +1 -0
  93. package/dist/services/category.service.d.ts +14 -0
  94. package/dist/services/category.service.d.ts.map +1 -0
  95. package/dist/services/category.service.js +74 -0
  96. package/dist/services/category.service.js.map +1 -0
  97. package/dist/services/exam.service.d.ts +17 -0
  98. package/dist/services/exam.service.d.ts.map +1 -0
  99. package/dist/services/exam.service.js +92 -0
  100. package/dist/services/exam.service.js.map +1 -0
  101. package/dist/services/grade.service.d.ts +16 -0
  102. package/dist/services/grade.service.d.ts.map +1 -0
  103. package/dist/services/grade.service.js +75 -0
  104. package/dist/services/grade.service.js.map +1 -0
  105. package/dist/services/index.d.ts +8 -0
  106. package/dist/services/index.d.ts.map +1 -0
  107. package/dist/services/index.js +18 -0
  108. package/dist/services/index.js.map +1 -0
  109. package/dist/services/paper.service.d.ts +32 -0
  110. package/dist/services/paper.service.d.ts.map +1 -0
  111. package/dist/services/paper.service.js +157 -0
  112. package/dist/services/paper.service.js.map +1 -0
  113. package/dist/services/question.service.d.ts +30 -0
  114. package/dist/services/question.service.d.ts.map +1 -0
  115. package/dist/services/question.service.js +155 -0
  116. package/dist/services/question.service.js.map +1 -0
  117. package/dist/services/statistics.service.d.ts +43 -0
  118. package/dist/services/statistics.service.d.ts.map +1 -0
  119. package/dist/services/statistics.service.js +134 -0
  120. package/dist/services/statistics.service.js.map +1 -0
  121. package/package.json +85 -0
  122. package/web/index.ts +51 -0
  123. package/web/manifest.ts +36 -0
  124. package/web/messages/en-US.json +143 -0
  125. package/web/messages/zh-CN.json +143 -0
  126. package/web/pages/ExamRoomPage.tsx +289 -0
  127. package/web/pages/ExamsPage.tsx +248 -0
  128. package/web/pages/PapersPage.tsx +202 -0
  129. package/web/pages/QuestionBankPage.tsx +263 -0
  130. package/web/pages/StatisticsPage.tsx +178 -0
  131. package/web/services/attempt-service.ts +53 -0
  132. package/web/services/category-service.ts +26 -0
  133. package/web/services/exam-service.ts +31 -0
  134. package/web/services/paper-service.ts +50 -0
  135. package/web/services/question-service.ts +36 -0
  136. package/web/services/statistics-service.ts +28 -0
  137. package/web/stores/quiz-store.ts +31 -0
  138. package/web/types/quiz.ts +166 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exam.service.js","sourceRoot":"","sources":["../../src/services/exam.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,yEAA2D;AAIpD,IAAM,WAAW,GAAjB,MAAM,WAAW;IACd,IAAI,CAAwB;IAC5B,WAAW,GAAG,KAAK,CAAC;IAE5B,UAAU;QACR,MAAM,EAAE,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,8BAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAA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AAE,CAAC;YAC7B,QAA+C,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3G,CAAC;QACD,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;QACpD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,QAAQ;YAAE,MAAM,eAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QACzD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,gBAAS,CAAC,GAAG,CAAC,oBAAa,CAAC,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;CACF,CAAA;AA5EY,kCAAW;sBAAX,WAAW;IADvB,IAAA,cAAO,GAAE;GACG,WAAW,CA4EvB"}
@@ -0,0 +1,16 @@
1
+ import { QuizAnswer } from '../entities/quiz-answer.entity.js';
2
+ import { QuizAttempt } from '../entities/quiz-attempt.entity.js';
3
+ import type { GradeAnswerDto } from '../schemas/attempt.schema.js';
4
+ export declare class GradeService {
5
+ private answerRepo;
6
+ private attemptRepo;
7
+ private initialized;
8
+ initialize(): void;
9
+ private ensureInitialized;
10
+ /** 批改单道主观题 */
11
+ gradeAnswer(answerId: string, graderId: string, dto: GradeAnswerDto): Promise<QuizAnswer>;
12
+ /** 提交阅卷完成,将 attempt 标记为 GRADED */
13
+ finalizeGrading(attemptId: string): Promise<QuizAttempt>;
14
+ private recalcAttemptScore;
15
+ }
16
+ //# sourceMappingURL=grade.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grade.service.d.ts","sourceRoot":"","sources":["../../src/services/grade.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,qBACa,YAAY;IACvB,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IAAI;IAOlB,OAAO,CAAC,iBAAiB;IAQzB,cAAc;IACR,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAiB/F,kCAAkC;IAC5B,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAchD,kBAAkB;CAKjC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.GradeService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_answer_entity_js_1 = require("../entities/quiz-answer.entity.js");
12
+ const quiz_attempt_entity_js_1 = require("../entities/quiz-attempt.entity.js");
13
+ let GradeService = class GradeService {
14
+ answerRepo;
15
+ attemptRepo;
16
+ initialized = false;
17
+ initialize() {
18
+ const db = core_1.Container.get(core_1.DatabaseService);
19
+ this.answerRepo = db.getRepository(quiz_answer_entity_js_1.QuizAnswer);
20
+ this.attemptRepo = db.getRepository(quiz_attempt_entity_js_1.QuizAttempt);
21
+ this.initialized = true;
22
+ }
23
+ ensureInitialized() {
24
+ if (!this.initialized) {
25
+ try {
26
+ this.initialize();
27
+ }
28
+ catch {
29
+ throw new core_1.AppError('GradeService not initialized', 500);
30
+ }
31
+ }
32
+ }
33
+ /** 批改单道主观题 */
34
+ async gradeAnswer(answerId, graderId, dto) {
35
+ this.ensureInitialized();
36
+ const answer = await this.answerRepo.findOne({ where: { id: answerId } });
37
+ if (!answer)
38
+ throw core_1.AppError.notFound('Answer not found');
39
+ answer.score = dto.score;
40
+ answer.feedback = dto.feedback ?? null;
41
+ answer.gradedBy = graderId;
42
+ answer.gradedAt = new Date();
43
+ answer.isCorrect = dto.score > 0;
44
+ const saved = await this.answerRepo.save(answer);
45
+ await this.recalcAttemptScore(answer.attemptId);
46
+ core_1.Container.get(core_1.LoggerService).info(`[GradeService] Graded answer ${answerId} by ${graderId}`);
47
+ return saved;
48
+ }
49
+ /** 提交阅卷完成,将 attempt 标记为 GRADED */
50
+ async finalizeGrading(attemptId) {
51
+ this.ensureInitialized();
52
+ const attempt = await this.attemptRepo.findOne({ where: { id: attemptId } });
53
+ if (!attempt)
54
+ throw core_1.AppError.notFound('Attempt not found');
55
+ if (attempt.status !== 'SUBMITTED') {
56
+ throw core_1.AppError.badRequest('Attempt is not in submitted state');
57
+ }
58
+ await this.recalcAttemptScore(attemptId);
59
+ const updated = await this.attemptRepo.findOne({ where: { id: attemptId } });
60
+ if (!updated)
61
+ throw core_1.AppError.notFound('Attempt not found');
62
+ updated.status = 'GRADED';
63
+ return this.attemptRepo.save(updated);
64
+ }
65
+ async recalcAttemptScore(attemptId) {
66
+ const answers = await this.answerRepo.find({ where: { attemptId } });
67
+ const total = answers.reduce((sum, a) => sum + a.score, 0);
68
+ await this.attemptRepo.update(attemptId, { totalScore: total });
69
+ }
70
+ };
71
+ exports.GradeService = GradeService;
72
+ exports.GradeService = GradeService = __decorate([
73
+ (0, core_1.Service)()
74
+ ], GradeService);
75
+ //# sourceMappingURL=grade.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grade.service.js","sourceRoot":"","sources":["../../src/services/grade.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,6EAA+D;AAC/D,+EAAiE;AAI1D,IAAM,YAAY,GAAlB,MAAM,YAAY;IACf,UAAU,CAA0B;IACpC,WAAW,CAA2B;IACtC,WAAW,GAAG,KAAK,CAAC;IAE5B,UAAU;QACR,MAAM,EAAE,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,kCAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,aAAa,CAAC,oCAAW,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC;gBAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC;gBAChC,MAAM,IAAI,eAAQ,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED,cAAc;IACd,KAAK,CAAC,WAAW,CAAC,QAAgB,EAAE,QAAgB,EAAE,GAAmB;QACvE,IAAI,CAAC,iBAAiB,EAAE,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C;QACjE,CAAC;QACD,MAAM,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,OAAO;YAAE,MAAM,eAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC3D,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,SAAiB;QAChD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3D,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC;CACF,CAAA;AA1DY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,cAAO,GAAE;GACG,YAAY,CA0DxB"}
@@ -0,0 +1,8 @@
1
+ export { CategoryService } from './category.service.js';
2
+ export { QuestionService } from './question.service.js';
3
+ export { PaperService } from './paper.service.js';
4
+ export { ExamService } from './exam.service.js';
5
+ export { AttemptService } from './attempt.service.js';
6
+ export { GradeService } from './grade.service.js';
7
+ export { StatisticsService } from './statistics.service.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatisticsService = exports.GradeService = exports.AttemptService = exports.ExamService = exports.PaperService = exports.QuestionService = exports.CategoryService = void 0;
4
+ var category_service_js_1 = require("./category.service.js");
5
+ Object.defineProperty(exports, "CategoryService", { enumerable: true, get: function () { return category_service_js_1.CategoryService; } });
6
+ var question_service_js_1 = require("./question.service.js");
7
+ Object.defineProperty(exports, "QuestionService", { enumerable: true, get: function () { return question_service_js_1.QuestionService; } });
8
+ var paper_service_js_1 = require("./paper.service.js");
9
+ Object.defineProperty(exports, "PaperService", { enumerable: true, get: function () { return paper_service_js_1.PaperService; } });
10
+ var exam_service_js_1 = require("./exam.service.js");
11
+ Object.defineProperty(exports, "ExamService", { enumerable: true, get: function () { return exam_service_js_1.ExamService; } });
12
+ var attempt_service_js_1 = require("./attempt.service.js");
13
+ Object.defineProperty(exports, "AttemptService", { enumerable: true, get: function () { return attempt_service_js_1.AttemptService; } });
14
+ var grade_service_js_1 = require("./grade.service.js");
15
+ Object.defineProperty(exports, "GradeService", { enumerable: true, get: function () { return grade_service_js_1.GradeService; } });
16
+ var statistics_service_js_1 = require("./statistics.service.js");
17
+ Object.defineProperty(exports, "StatisticsService", { enumerable: true, get: function () { return statistics_service_js_1.StatisticsService; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAA/C,sHAAA,eAAe,OAAA;AACxB,6DAAwD;AAA/C,sHAAA,eAAe,OAAA;AACxB,uDAAkD;AAAzC,gHAAA,YAAY,OAAA;AACrB,qDAAgD;AAAvC,8GAAA,WAAW,OAAA;AACpB,2DAAsD;AAA7C,oHAAA,cAAc,OAAA;AACvB,uDAAkD;AAAzC,gHAAA,YAAY,OAAA;AACrB,iEAA4D;AAAnD,0HAAA,iBAAiB,OAAA"}
@@ -0,0 +1,32 @@
1
+ import { QuizPaper } from '../entities/quiz-paper.entity.js';
2
+ import { QuizPaperQuestion } from '../entities/quiz-paper-question.entity.js';
3
+ import { QuizQuestion } from '../entities/quiz-question.entity.js';
4
+ import type { CreatePaperDto, UpdatePaperDto, AddQuestionDto, UpdatePaperQuestionDto } from '../schemas/paper.schema.js';
5
+ export interface PaperWithQuestions {
6
+ paper: QuizPaper;
7
+ questions: Array<QuizPaperQuestion & {
8
+ questionDetail: QuizQuestion;
9
+ }>;
10
+ }
11
+ export declare class PaperService {
12
+ private repo;
13
+ private pqRepo;
14
+ private questionRepo;
15
+ private initialized;
16
+ initialize(): void;
17
+ private ensureInitialized;
18
+ findAll(page: number, pageSize: number): Promise<{
19
+ items: QuizPaper[];
20
+ total: number;
21
+ }>;
22
+ findById(id: string): Promise<QuizPaper>;
23
+ findWithQuestions(id: string): Promise<PaperWithQuestions>;
24
+ create(dto: CreatePaperDto, userId?: string): Promise<QuizPaper>;
25
+ update(id: string, dto: UpdatePaperDto): Promise<QuizPaper>;
26
+ delete(id: string): Promise<void>;
27
+ addQuestion(paperId: string, dto: AddQuestionDto): Promise<QuizPaperQuestion>;
28
+ updateQuestion(paperId: string, questionId: string, dto: UpdatePaperQuestionDto): Promise<QuizPaperQuestion>;
29
+ removeQuestion(paperId: string, questionId: string): Promise<void>;
30
+ private recalcTotalScore;
31
+ }
32
+ //# sourceMappingURL=pa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AAG,OAAO,CAAC,IAAI,CAAC;IASjC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAuB7E,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAU5G,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAQ1D,gBAAgB;CAK/B"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PaperService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_paper_entity_js_1 = require("../entities/quiz-paper.entity.js");
12
+ const quiz_paper_question_entity_js_1 = require("../entities/quiz-paper-question.entity.js");
13
+ const quiz_question_entity_js_1 = require("../entities/quiz-question.entity.js");
14
+ let PaperService = class PaperService {
15
+ repo;
16
+ pqRepo;
17
+ questionRepo;
18
+ initialized = false;
19
+ initialize() {
20
+ const db = core_1.Container.get(core_1.DatabaseService);
21
+ this.repo = db.getRepository(quiz_paper_entity_js_1.QuizPaper);
22
+ this.pqRepo = db.getRepository(quiz_paper_question_entity_js_1.QuizPaperQuestion);
23
+ this.questionRepo = db.getRepository(quiz_question_entity_js_1.QuizQuestion);
24
+ this.initialized = true;
25
+ }
26
+ ensureInitialized() {
27
+ if (!this.initialized) {
28
+ try {
29
+ this.initialize();
30
+ }
31
+ catch {
32
+ throw new core_1.AppError('PaperService not initialized', 500);
33
+ }
34
+ }
35
+ }
36
+ async findAll(page, pageSize) {
37
+ this.ensureInitialized();
38
+ const [items, total] = await this.repo.findAndCount({
39
+ order: { createdAt: 'DESC' },
40
+ skip: (page - 1) * pageSize,
41
+ take: pageSize,
42
+ });
43
+ return { items, total };
44
+ }
45
+ async findById(id) {
46
+ this.ensureInitialized();
47
+ const entity = await this.repo.findOne({ where: { id } });
48
+ if (!entity)
49
+ throw core_1.AppError.notFound('Paper not found');
50
+ return entity;
51
+ }
52
+ async findWithQuestions(id) {
53
+ this.ensureInitialized();
54
+ const paper = await this.repo.findOne({ where: { id } });
55
+ if (!paper)
56
+ throw core_1.AppError.notFound('Paper not found');
57
+ const pqs = await this.pqRepo.find({
58
+ where: { paperId: id },
59
+ order: { sortOrder: 'ASC' },
60
+ });
61
+ const qIds = pqs.map((pq) => pq.questionId);
62
+ const questionMap = new Map();
63
+ if (qIds.length > 0) {
64
+ const questions = await this.questionRepo.createQueryBuilder('q')
65
+ .where('q.id IN (:...ids)', { ids: qIds })
66
+ .getMany();
67
+ questions.forEach((q) => questionMap.set(q.id, q));
68
+ }
69
+ const questions = pqs.map((pq) => ({
70
+ ...pq,
71
+ questionDetail: questionMap.get(pq.questionId),
72
+ }));
73
+ return { paper, questions };
74
+ }
75
+ async create(dto, userId) {
76
+ this.ensureInitialized();
77
+ const entity = this.repo.create({
78
+ title: dto.title,
79
+ description: dto.description ?? null,
80
+ passingScore: dto.passingScore ?? 60,
81
+ timeLimit: dto.timeLimit ?? 0,
82
+ createdBy: userId ?? null,
83
+ });
84
+ const saved = await this.repo.save(entity);
85
+ core_1.Container.get(core_1.LoggerService).info(`[PaperService] Created paper: ${saved.id}`);
86
+ return saved;
87
+ }
88
+ async update(id, dto) {
89
+ this.ensureInitialized();
90
+ const existing = await this.repo.findOne({ where: { id } });
91
+ if (!existing)
92
+ throw core_1.AppError.notFound('Paper not found');
93
+ Object.assign(existing, dto);
94
+ return this.repo.save(existing);
95
+ }
96
+ async delete(id) {
97
+ this.ensureInitialized();
98
+ const existing = await this.repo.findOne({ where: { id } });
99
+ if (!existing)
100
+ throw core_1.AppError.notFound('Paper not found');
101
+ await this.pqRepo.delete({ paperId: id });
102
+ await this.repo.remove(existing);
103
+ core_1.Container.get(core_1.LoggerService).info(`[PaperService] Deleted paper: ${id}`);
104
+ }
105
+ async addQuestion(paperId, dto) {
106
+ this.ensureInitialized();
107
+ const paper = await this.repo.findOne({ where: { id: paperId } });
108
+ if (!paper)
109
+ throw core_1.AppError.notFound('Paper not found');
110
+ const question = await this.questionRepo.findOne({ where: { id: dto.questionId } });
111
+ if (!question)
112
+ throw core_1.AppError.notFound('Question not found');
113
+ const existing = await this.pqRepo.findOne({ where: { paperId, questionId: dto.questionId } });
114
+ if (existing)
115
+ throw core_1.AppError.badRequest('Question already in paper');
116
+ const count = await this.pqRepo.count({ where: { paperId } });
117
+ const pq = this.pqRepo.create({
118
+ paperId,
119
+ questionId: dto.questionId,
120
+ score: dto.score ?? question.defaultScore,
121
+ sortOrder: dto.sortOrder ?? count,
122
+ sectionTitle: dto.sectionTitle ?? null,
123
+ });
124
+ const saved = await this.pqRepo.save(pq);
125
+ await this.recalcTotalScore(paperId);
126
+ return saved;
127
+ }
128
+ async updateQuestion(paperId, questionId, dto) {
129
+ this.ensureInitialized();
130
+ const pq = await this.pqRepo.findOne({ where: { paperId, questionId } });
131
+ if (!pq)
132
+ throw core_1.AppError.notFound('Paper question not found');
133
+ Object.assign(pq, dto);
134
+ const saved = await this.pqRepo.save(pq);
135
+ if (dto.score !== undefined)
136
+ await this.recalcTotalScore(paperId);
137
+ return saved;
138
+ }
139
+ async removeQuestion(paperId, questionId) {
140
+ this.ensureInitialized();
141
+ const pq = await this.pqRepo.findOne({ where: { paperId, questionId } });
142
+ if (!pq)
143
+ throw core_1.AppError.notFound('Paper question not found');
144
+ await this.pqRepo.remove(pq);
145
+ await this.recalcTotalScore(paperId);
146
+ }
147
+ async recalcTotalScore(paperId) {
148
+ const questions = await this.pqRepo.find({ where: { paperId } });
149
+ const total = questions.reduce((sum, q) => sum + q.score, 0);
150
+ await this.repo.update(paperId, { totalScore: total });
151
+ }
152
+ };
153
+ exports.PaperService = PaperService;
154
+ exports.PaperService = PaperService = __decorate([
155
+ (0, core_1.Service)()
156
+ ], PaperService);
157
+ //# sourceMappingURL=paper.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paper.service.js","sourceRoot":"","sources":["../../src/services/paper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,2EAA6D;AAC7D,6FAA8E;AAC9E,iFAAmE;AAc5D,IAAM,YAAY,GAAlB,MAAM,YAAY;IACf,IAAI,CAAyB;IAC7B,MAAM,CAAiC;IACvC,YAAY,CAA4B;IACxC,WAAW,GAAG,KAAK,CAAC;IAE5B,UAAU;QACR,MAAM,EAAE,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,gCAAS,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,aAAa,CAAC,iDAAiB,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,aAAa,CAAC,sCAAY,CAAC,CAAC;QACnD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC;gBAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC;gBAChC,MAAM,IAAI,eAAQ,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,C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AAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;CACF,CAAA;AA/IY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,cAAO,GAAE;GACG,YAAY,CA+IxB"}
@@ -0,0 +1,30 @@
1
+ import { QuizQuestion } from '../entities/quiz-question.entity.js';
2
+ import type { CreateQuestionDto, UpdateQuestionDto, SmartGenerateDto } from '../schemas/question.schema.js';
3
+ export declare class QuestionService {
4
+ private repo;
5
+ private paperQRepo;
6
+ private paperRepo;
7
+ private initialized;
8
+ initialize(): void;
9
+ private ensureInitialized;
10
+ findAll(page: number, pageSize: number, filters: {
11
+ categoryId?: string;
12
+ type?: string;
13
+ difficulty?: number;
14
+ search?: string;
15
+ }): Promise<{
16
+ items: QuizQuestion[];
17
+ total: number;
18
+ }>;
19
+ findById(id: string): Promise<QuizQuestion>;
20
+ create(dto: CreateQuestionDto, userId?: string): Promise<QuizQuestion>;
21
+ update(id: string, dto: UpdateQuestionDto): Promise<QuizQuestion>;
22
+ delete(id: string): Promise<void>;
23
+ /** 智能组卷:根据规则从题库随机抽题添加到试卷 */
24
+ smartGenerate(dto: SmartGenerateDto): Promise<{
25
+ added: number;
26
+ }>;
27
+ private sampleRandom;
28
+ recalcPaperTotalScore(paperId: string): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=question.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.service.d.ts","sourceRoot":"","sources":["../../src/services/question.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAGnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAE5G,qBACa,eAAe;IAC1B,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IAAI;IAQlB,OAAO,CAAC,iBAAiB;IAQnB,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACpF,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAc9C,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO3C,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAmBtE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAkBjE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvC,4BAA4B;IACtB,aAAa,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAqCtE,OAAO,CAAC,YAAY;IAKd,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM5D"}
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.QuestionService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_question_entity_js_1 = require("../entities/quiz-question.entity.js");
12
+ const quiz_paper_question_entity_js_1 = require("../entities/quiz-paper-question.entity.js");
13
+ const quiz_paper_entity_js_1 = require("../entities/quiz-paper.entity.js");
14
+ let QuestionService = class QuestionService {
15
+ repo;
16
+ paperQRepo;
17
+ paperRepo;
18
+ initialized = false;
19
+ initialize() {
20
+ const db = core_1.Container.get(core_1.DatabaseService);
21
+ this.repo = db.getRepository(quiz_question_entity_js_1.QuizQuestion);
22
+ this.paperQRepo = db.getRepository(quiz_paper_question_entity_js_1.QuizPaperQuestion);
23
+ this.paperRepo = db.getRepository(quiz_paper_entity_js_1.QuizPaper);
24
+ this.initialized = true;
25
+ }
26
+ ensureInitialized() {
27
+ if (!this.initialized) {
28
+ try {
29
+ this.initialize();
30
+ }
31
+ catch {
32
+ throw new core_1.AppError('QuestionService not initialized', 500);
33
+ }
34
+ }
35
+ }
36
+ async findAll(page, pageSize, filters) {
37
+ this.ensureInitialized();
38
+ const qb = this.repo.createQueryBuilder('q').orderBy('q.createdAt', 'DESC');
39
+ if (filters.categoryId)
40
+ qb.andWhere('q.categoryId = :cid', { cid: filters.categoryId });
41
+ if (filters.type)
42
+ qb.andWhere('q.type = :type', { type: filters.type });
43
+ if (filters.difficulty)
44
+ qb.andWhere('q.difficulty = :d', { d: filters.difficulty });
45
+ if (filters.search) {
46
+ qb.andWhere('q.content LIKE :s', { s: `%${filters.search}%` });
47
+ }
48
+ qb.skip((page - 1) * pageSize).take(pageSize);
49
+ const [items, total] = await qb.getManyAndCount();
50
+ return { items, total };
51
+ }
52
+ async findById(id) {
53
+ this.ensureInitialized();
54
+ const entity = await this.repo.findOne({ where: { id } });
55
+ if (!entity)
56
+ throw core_1.AppError.notFound('Question not found');
57
+ return entity;
58
+ }
59
+ async create(dto, userId) {
60
+ this.ensureInitialized();
61
+ const entity = this.repo.create({
62
+ categoryId: dto.categoryId ?? null,
63
+ type: dto.type,
64
+ content: dto.content,
65
+ options: dto.options ? JSON.stringify(dto.options) : null,
66
+ correctAnswer: dto.correctAnswer ? JSON.stringify(dto.correctAnswer) : null,
67
+ explanation: dto.explanation ?? null,
68
+ difficulty: dto.difficulty ?? 3,
69
+ tags: dto.tags ? JSON.stringify(dto.tags) : null,
70
+ defaultScore: dto.defaultScore ?? 1,
71
+ createdBy: userId ?? null,
72
+ });
73
+ const saved = await this.repo.save(entity);
74
+ core_1.Container.get(core_1.LoggerService).info(`[QuestionService] Created question: ${saved.id}`);
75
+ return saved;
76
+ }
77
+ async update(id, dto) {
78
+ this.ensureInitialized();
79
+ const existing = await this.repo.findOne({ where: { id } });
80
+ if (!existing)
81
+ throw core_1.AppError.notFound('Question not found');
82
+ if (dto.options !== undefined) {
83
+ existing['options'] = dto.options ? JSON.stringify(dto.options) : null;
84
+ }
85
+ if (dto.correctAnswer !== undefined) {
86
+ existing['correctAnswer'] = dto.correctAnswer ? JSON.stringify(dto.correctAnswer) : null;
87
+ }
88
+ if (dto.tags !== undefined) {
89
+ existing['tags'] = dto.tags ? JSON.stringify(dto.tags) : null;
90
+ }
91
+ const { options: _o, correctAnswer: _c, tags: _t, ...rest } = dto;
92
+ Object.assign(existing, rest);
93
+ return this.repo.save(existing);
94
+ }
95
+ async delete(id) {
96
+ this.ensureInitialized();
97
+ const existing = await this.repo.findOne({ where: { id } });
98
+ if (!existing)
99
+ throw core_1.AppError.notFound('Question not found');
100
+ await this.repo.remove(existing);
101
+ core_1.Container.get(core_1.LoggerService).info(`[QuestionService] Deleted question: ${id}`);
102
+ }
103
+ /** 智能组卷:根据规则从题库随机抽题添加到试卷 */
104
+ async smartGenerate(dto) {
105
+ this.ensureInitialized();
106
+ const paper = await this.paperRepo.findOne({ where: { id: dto.paperId } });
107
+ if (!paper)
108
+ throw core_1.AppError.notFound('Paper not found');
109
+ const existing = await this.paperQRepo.find({ where: { paperId: dto.paperId } });
110
+ const usedQuestionIds = new Set(existing.map((pq) => pq.questionId));
111
+ let sortOrder = existing.length;
112
+ let added = 0;
113
+ for (const rule of dto.rules) {
114
+ const qb = this.repo.createQueryBuilder('q');
115
+ if (rule.categoryId)
116
+ qb.andWhere('q.categoryId = :cid', { cid: rule.categoryId });
117
+ if (rule.type)
118
+ qb.andWhere('q.type = :t', { t: rule.type });
119
+ if (rule.difficulty)
120
+ qb.andWhere('q.difficulty = :d', { d: rule.difficulty });
121
+ const candidates = await qb.getMany();
122
+ const available = candidates.filter((q) => !usedQuestionIds.has(q.id));
123
+ const selected = this.sampleRandom(available, rule.count);
124
+ for (const q of selected) {
125
+ const pq = this.paperQRepo.create({
126
+ paperId: dto.paperId,
127
+ questionId: q.id,
128
+ score: rule.scorePerQuestion ?? q.defaultScore,
129
+ sortOrder: sortOrder++,
130
+ });
131
+ await this.paperQRepo.save(pq);
132
+ usedQuestionIds.add(q.id);
133
+ added++;
134
+ }
135
+ }
136
+ await this.recalcPaperTotalScore(dto.paperId);
137
+ core_1.Container.get(core_1.LoggerService).info(`[QuestionService] Smart generate added ${added} questions to paper ${dto.paperId}`);
138
+ return { added };
139
+ }
140
+ sampleRandom(arr, n) {
141
+ const shuffled = [...arr].sort(() => Math.random() - 0.5);
142
+ return shuffled.slice(0, Math.min(n, shuffled.length));
143
+ }
144
+ async recalcPaperTotalScore(paperId) {
145
+ this.ensureInitialized();
146
+ const questions = await this.paperQRepo.find({ where: { paperId } });
147
+ const total = questions.reduce((sum, q) => sum + q.score, 0);
148
+ await this.paperRepo.update(paperId, { totalScore: total });
149
+ }
150
+ };
151
+ exports.QuestionService = QuestionService;
152
+ exports.QuestionService = QuestionService = __decorate([
153
+ (0, core_1.Service)()
154
+ ], QuestionService);
155
+ //# sourceMappingURL=question.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.service.js","sourceRoot":"","sources":["../../src/services/question.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,iFAAmE;AACnE,6FAA8E;AAC9E,2EAA6D;AAItD,IAAM,eAAe,GAArB,MAAM,eAAe;IAClB,IAAI,CAA4B;IAChC,UAAU,CAAiC;IAC3C,SAAS,CAAyB;IAClC,WAAW,GAAG,KAAK,CAAC;IAE5B,UAAU;QACR,MAAM,EAAE,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,sCAAY,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,iDAAiB,CAAC,CAAC;QACtD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC,aAAa,CAAC,gCAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC;gBAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC;gBAChC,MAAM,IAAI,eAAQ,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAAY,EACZ,QAAgB,EAChB,OAAqF;QAErF,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAC5E,IAAI,OAAO,CAAC,UAAU;YAAE,EAAE,CAAC,QAAQ,CAAC,qBAAqB,EAAE,EA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IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAC1D,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,OAAe;QACzC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF,CAAA;AA7IY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,cAAO,GAAE;GACG,eAAe,CA6I3B"}
@@ -0,0 +1,43 @@
1
+ import { QuizAttempt } from '../entities/quiz-attempt.entity.js';
2
+ export interface ExamStats {
3
+ examId: string;
4
+ title: string;
5
+ totalAttempts: number;
6
+ submittedAttempts: number;
7
+ gradedAttempts: number;
8
+ averageScore: number;
9
+ highestScore: number;
10
+ lowestScore: number;
11
+ passRate: number;
12
+ scoreDistribution: Array<{
13
+ range: string;
14
+ count: number;
15
+ }>;
16
+ }
17
+ export interface UserStats {
18
+ userId: string;
19
+ totalAttempts: number;
20
+ averageScore: number;
21
+ highestScore: number;
22
+ passCount: number;
23
+ passRate: number;
24
+ recentAttempts: QuizAttempt[];
25
+ }
26
+ export declare class StatisticsService {
27
+ private attemptRepo;
28
+ private answerRepo;
29
+ private examRepo;
30
+ private paperRepo;
31
+ private initialized;
32
+ initialize(): void;
33
+ private ensureInitialized;
34
+ getExamStats(examId: string): Promise<ExamStats>;
35
+ getUserStats(userId: string): Promise<UserStats>;
36
+ getRanking(examId: string, limit?: number): Promise<Array<{
37
+ userId: string;
38
+ score: number;
39
+ rank: number;
40
+ }>>;
41
+ private buildScoreDistribution;
42
+ }
43
+ //# sourceMappingURL=statistics.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statistics.service.d.ts","sourceRoot":"","sources":["../../src/services/statistics.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAKjE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,WAAW,EAAE,CAAC;CAC/B;AAED,qBACa,iBAAiB;IAC5B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IA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