@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,147 @@
1
+ import { z } from 'zod';
2
+ export declare const QuestionOptionSchema: z.ZodObject<{
3
+ key: z.ZodString;
4
+ text: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ text?: string;
7
+ key?: string;
8
+ }, {
9
+ text?: string;
10
+ key?: string;
11
+ }>;
12
+ export declare const CreateQuestionSchema: z.ZodObject<{
13
+ categoryId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
+ type: z.ZodEnum<["SINGLE_CHOICE", "MULTIPLE_CHOICE", "TRUE_FALSE", "FILL_BLANK", "ESSAY"]>;
15
+ content: z.ZodString;
16
+ options: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
17
+ key: z.ZodString;
18
+ text: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ text?: string;
21
+ key?: string;
22
+ }, {
23
+ text?: string;
24
+ key?: string;
25
+ }>, "many">>>;
26
+ correctAnswer: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>>;
27
+ explanation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ difficulty: z.ZodDefault<z.ZodNumber>;
29
+ tags: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
30
+ defaultScore: z.ZodDefault<z.ZodNumber>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
33
+ categoryId?: string;
34
+ content?: string;
35
+ options?: {
36
+ text?: string;
37
+ key?: string;
38
+ }[];
39
+ correctAnswer?: string | string[];
40
+ explanation?: string;
41
+ difficulty?: number;
42
+ tags?: string[];
43
+ defaultScore?: number;
44
+ }, {
45
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
46
+ categoryId?: string;
47
+ content?: string;
48
+ options?: {
49
+ text?: string;
50
+ key?: string;
51
+ }[];
52
+ correctAnswer?: string | string[];
53
+ explanation?: string;
54
+ difficulty?: number;
55
+ tags?: string[];
56
+ defaultScore?: number;
57
+ }>;
58
+ export declare const UpdateQuestionSchema: z.ZodObject<{
59
+ categoryId: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
60
+ type: z.ZodOptional<z.ZodEnum<["SINGLE_CHOICE", "MULTIPLE_CHOICE", "TRUE_FALSE", "FILL_BLANK", "ESSAY"]>>;
61
+ content: z.ZodOptional<z.ZodString>;
62
+ options: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
63
+ key: z.ZodString;
64
+ text: z.ZodString;
65
+ }, "strip", z.ZodTypeAny, {
66
+ text?: string;
67
+ key?: string;
68
+ }, {
69
+ text?: string;
70
+ key?: string;
71
+ }>, "many">>>>;
72
+ correctAnswer: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>>>;
73
+ explanation: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
74
+ difficulty: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
75
+ tags: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>>;
76
+ defaultScore: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
79
+ categoryId?: string;
80
+ content?: string;
81
+ options?: {
82
+ text?: string;
83
+ key?: string;
84
+ }[];
85
+ correctAnswer?: string | string[];
86
+ explanation?: string;
87
+ difficulty?: number;
88
+ tags?: string[];
89
+ defaultScore?: number;
90
+ }, {
91
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
92
+ categoryId?: string;
93
+ content?: string;
94
+ options?: {
95
+ text?: string;
96
+ key?: string;
97
+ }[];
98
+ correctAnswer?: string | string[];
99
+ explanation?: string;
100
+ difficulty?: number;
101
+ tags?: string[];
102
+ defaultScore?: number;
103
+ }>;
104
+ export declare const SmartGenerateSchema: z.ZodObject<{
105
+ paperId: z.ZodString;
106
+ rules: z.ZodArray<z.ZodObject<{
107
+ categoryId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
108
+ type: z.ZodOptional<z.ZodEnum<["SINGLE_CHOICE", "MULTIPLE_CHOICE", "TRUE_FALSE", "FILL_BLANK", "ESSAY"]>>;
109
+ difficulty: z.ZodOptional<z.ZodNumber>;
110
+ count: z.ZodNumber;
111
+ scorePerQuestion: z.ZodOptional<z.ZodNumber>;
112
+ }, "strip", z.ZodTypeAny, {
113
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
114
+ categoryId?: string;
115
+ difficulty?: number;
116
+ count?: number;
117
+ scorePerQuestion?: number;
118
+ }, {
119
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
120
+ categoryId?: string;
121
+ difficulty?: number;
122
+ count?: number;
123
+ scorePerQuestion?: number;
124
+ }>, "many">;
125
+ }, "strip", z.ZodTypeAny, {
126
+ paperId?: string;
127
+ rules?: {
128
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
129
+ categoryId?: string;
130
+ difficulty?: number;
131
+ count?: number;
132
+ scorePerQuestion?: number;
133
+ }[];
134
+ }, {
135
+ paperId?: string;
136
+ rules?: {
137
+ type?: "SINGLE_CHOICE" | "MULTIPLE_CHOICE" | "TRUE_FALSE" | "FILL_BLANK" | "ESSAY";
138
+ categoryId?: string;
139
+ difficulty?: number;
140
+ count?: number;
141
+ scorePerQuestion?: number;
142
+ }[];
143
+ }>;
144
+ export type CreateQuestionDto = z.infer<typeof CreateQuestionSchema>;
145
+ export type UpdateQuestionDto = z.infer<typeof UpdateQuestionSchema>;
146
+ export type SmartGenerateDto = z.infer<typeof SmartGenerateSchema>;
147
+ //# sourceMappingURL=question.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/question.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,oBAAoB;;;;;;;;;EAG/B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU/B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAiC,CAAC;AAEnE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS9B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACrE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACrE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartGenerateSchema = exports.UpdateQuestionSchema = exports.CreateQuestionSchema = exports.QuestionOptionSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const quiz_question_entity_js_1 = require("../entities/quiz-question.entity.js");
6
+ exports.QuestionOptionSchema = zod_1.z.object({
7
+ key: zod_1.z.string().min(1).max(8),
8
+ text: zod_1.z.string().min(1),
9
+ });
10
+ exports.CreateQuestionSchema = zod_1.z.object({
11
+ categoryId: zod_1.z.string().uuid().nullable().optional(),
12
+ type: zod_1.z.enum(quiz_question_entity_js_1.QUESTION_TYPES),
13
+ content: zod_1.z.string().min(1),
14
+ options: zod_1.z.array(exports.QuestionOptionSchema).nullable().optional(),
15
+ correctAnswer: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).nullable().optional(),
16
+ explanation: zod_1.z.string().nullable().optional(),
17
+ difficulty: zod_1.z.number().int().min(1).max(5).default(3),
18
+ tags: zod_1.z.array(zod_1.z.string()).nullable().optional(),
19
+ defaultScore: zod_1.z.number().min(0).default(1),
20
+ });
21
+ exports.UpdateQuestionSchema = exports.CreateQuestionSchema.partial();
22
+ exports.SmartGenerateSchema = zod_1.z.object({
23
+ paperId: zod_1.z.string().uuid(),
24
+ rules: zod_1.z.array(zod_1.z.object({
25
+ categoryId: zod_1.z.string().uuid().nullable().optional(),
26
+ type: zod_1.z.enum(quiz_question_entity_js_1.QUESTION_TYPES).optional(),
27
+ difficulty: zod_1.z.number().int().min(1).max(5).optional(),
28
+ count: zod_1.z.number().int().min(1).max(100),
29
+ scorePerQuestion: zod_1.z.number().min(0).optional(),
30
+ })).min(1),
31
+ });
32
+ //# sourceMappingURL=question.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.schema.js","sourceRoot":"","sources":["../../src/schemas/question.schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iFAAqE;AAExD,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACxB,CAAC,CAAC;AAEU,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACnD,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,wCAAc,CAAC;IAC5B,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,4BAAoB,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC5D,aAAa,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC/E,WAAW,EAAE,O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CAAC,GAAG,CAAC,CAAC,CAAC;CACX,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { QuizAttempt } from '../entities/quiz-attempt.entity.js';
2
+ import { QuizAnswer } from '../entities/quiz-answer.entity.js';
3
+ import { QuizQuestion } from '../entities/quiz-question.entity.js';
4
+ import type { SubmitAnswersDto } from '../schemas/attempt.schema.js';
5
+ export interface AttemptDetail {
6
+ attempt: QuizAttempt;
7
+ answers: Array<QuizAnswer & {
8
+ questionDetail: QuizQuestion;
9
+ }>;
10
+ }
11
+ export declare class AttemptService {
12
+ private attemptRepo;
13
+ private answerRepo;
14
+ private examRepo;
15
+ private pqRepo;
16
+ private questionRepo;
17
+ private initialized;
18
+ initialize(): void;
19
+ private ensureInitialized;
20
+ startAttempt(examId: string, userId: string): Promise<QuizAttempt>;
21
+ submitAttempt(attemptId: string, userId: string, dto: SubmitAnswersDto): Promise<QuizAttempt>;
22
+ findAttemptsByExam(examId: string, page: number, pageSize: number): Promise<{
23
+ items: QuizAttempt[];
24
+ total: number;
25
+ }>;
26
+ findAttemptsByUser(userId: string, page: number, pageSize: number): Promise<{
27
+ items: QuizAttempt[];
28
+ total: number;
29
+ }>;
30
+ findAttemptDetail(attemptId: string): Promise<AttemptDetail>;
31
+ private autoGrade;
32
+ }
33
+ //# sourceMappingURL=attempt.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.service.d.ts","sourceRoot":"","sources":["../../src/services/attempt.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,KAAK,CAAC,UAAU,GAAG;QAAE,cAAc,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;CAC/D;AAED,qBACa,cAAc;IACzB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IAAI;IAUlB,OAAO,CAAC,iBAAiB;IAQnB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAsClE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwD7F,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAWpH,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAWpH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAwBlE,OAAO,CAAC,SAAS;CA6BlB"}
@@ -0,0 +1,197 @@
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.AttemptService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_attempt_entity_js_1 = require("../entities/quiz-attempt.entity.js");
12
+ const quiz_answer_entity_js_1 = require("../entities/quiz-answer.entity.js");
13
+ const quiz_exam_entity_js_1 = require("../entities/quiz-exam.entity.js");
14
+ const quiz_paper_question_entity_js_1 = require("../entities/quiz-paper-question.entity.js");
15
+ const quiz_question_entity_js_1 = require("../entities/quiz-question.entity.js");
16
+ let AttemptService = class AttemptService {
17
+ attemptRepo;
18
+ answerRepo;
19
+ examRepo;
20
+ pqRepo;
21
+ questionRepo;
22
+ initialized = false;
23
+ initialize() {
24
+ const db = core_1.Container.get(core_1.DatabaseService);
25
+ this.attemptRepo = db.getRepository(quiz_attempt_entity_js_1.QuizAttempt);
26
+ this.answerRepo = db.getRepository(quiz_answer_entity_js_1.QuizAnswer);
27
+ this.examRepo = db.getRepository(quiz_exam_entity_js_1.QuizExam);
28
+ this.pqRepo = db.getRepository(quiz_paper_question_entity_js_1.QuizPaperQuestion);
29
+ this.questionRepo = db.getRepository(quiz_question_entity_js_1.QuizQuestion);
30
+ this.initialized = true;
31
+ }
32
+ ensureInitialized() {
33
+ if (!this.initialized) {
34
+ try {
35
+ this.initialize();
36
+ }
37
+ catch {
38
+ throw new core_1.AppError('AttemptService not initialized', 500);
39
+ }
40
+ }
41
+ }
42
+ async startAttempt(examId, userId) {
43
+ this.ensureInitialized();
44
+ const exam = await this.examRepo.findOne({ where: { id: examId } });
45
+ if (!exam)
46
+ throw core_1.AppError.notFound('Exam not found');
47
+ if (exam.status === 'CANCELLED')
48
+ throw core_1.AppError.badRequest('Exam is cancelled');
49
+ if (exam.status === 'ENDED')
50
+ throw core_1.AppError.badRequest('Exam has ended');
51
+ const now = new Date();
52
+ if (exam.startTime && now < exam.startTime) {
53
+ throw core_1.AppError.badRequest('Exam has not started yet');
54
+ }
55
+ if (exam.endTime && now > exam.endTime) {
56
+ throw core_1.AppError.badRequest('Exam has already ended');
57
+ }
58
+ if (exam.maxAttempts > 0) {
59
+ const count = await this.attemptRepo.count({ where: { examId, userId } });
60
+ if (count >= exam.maxAttempts) {
61
+ throw core_1.AppError.badRequest(`Max attempts (${exam.maxAttempts}) reached`);
62
+ }
63
+ }
64
+ const inProgress = await this.attemptRepo.findOne({
65
+ where: { examId, userId, status: 'IN_PROGRESS' },
66
+ });
67
+ if (inProgress)
68
+ return inProgress;
69
+ const attempt = this.attemptRepo.create({
70
+ examId,
71
+ userId,
72
+ startedAt: now,
73
+ status: 'IN_PROGRESS',
74
+ });
75
+ const saved = await this.attemptRepo.save(attempt);
76
+ core_1.Container.get(core_1.LoggerService).info(`[AttemptService] Started attempt: ${saved.id}`);
77
+ return saved;
78
+ }
79
+ async submitAttempt(attemptId, userId, dto) {
80
+ this.ensureInitialized();
81
+ const attempt = await this.attemptRepo.findOne({ where: { id: attemptId, userId } });
82
+ if (!attempt)
83
+ throw core_1.AppError.notFound('Attempt not found');
84
+ if (attempt.status !== 'IN_PROGRESS') {
85
+ throw core_1.AppError.badRequest('Attempt is not in progress');
86
+ }
87
+ const exam = await this.examRepo.findOne({ where: { id: attempt.examId } });
88
+ if (!exam)
89
+ throw core_1.AppError.notFound('Exam not found');
90
+ const pqs = await this.pqRepo.find({ where: { paperId: exam.paperId } });
91
+ const qIds = pqs.map((pq) => pq.questionId);
92
+ const questions = await this.questionRepo.createQueryBuilder('q')
93
+ .where('q.id IN (:...ids)', { ids: qIds })
94
+ .getMany();
95
+ const questionMap = new Map(questions.map((q) => [q.id, q]));
96
+ const scoreMap = new Map(pqs.map((pq) => [pq.questionId, pq.score]));
97
+ let totalScore = 0;
98
+ for (const ans of dto.answers) {
99
+ const question = questionMap.get(ans.questionId);
100
+ if (!question)
101
+ continue;
102
+ const maxScore = scoreMap.get(ans.questionId) ?? question.defaultScore;
103
+ const { isCorrect, score } = this.autoGrade(question, ans.userAnswer, maxScore);
104
+ const answer = this.answerRepo.create({
105
+ attemptId,
106
+ questionId: ans.questionId,
107
+ userAnswer: ans.userAnswer != null ? JSON.stringify(ans.userAnswer) : null,
108
+ isCorrect,
109
+ score,
110
+ });
111
+ await this.answerRepo.save(answer);
112
+ totalScore += score;
113
+ }
114
+ attempt.status = 'SUBMITTED';
115
+ attempt.submittedAt = new Date();
116
+ attempt.timeUsedSeconds = dto.timeUsedSeconds ?? 0;
117
+ attempt.totalScore = totalScore;
118
+ const hasPendingSubjective = dto.answers.some((ans) => {
119
+ const q = questionMap.get(ans.questionId);
120
+ return q && (q.type === 'ESSAY' || q.type === 'FILL_BLANK');
121
+ });
122
+ if (!hasPendingSubjective) {
123
+ attempt.status = 'GRADED';
124
+ }
125
+ const saved = await this.attemptRepo.save(attempt);
126
+ core_1.Container.get(core_1.LoggerService).info(`[AttemptService] Submitted attempt: ${attemptId}, score: ${totalScore}`);
127
+ return saved;
128
+ }
129
+ async findAttemptsByExam(examId, page, pageSize) {
130
+ this.ensureInitialized();
131
+ const [items, total] = await this.attemptRepo.findAndCount({
132
+ where: { examId },
133
+ order: { createdAt: 'DESC' },
134
+ skip: (page - 1) * pageSize,
135
+ take: pageSize,
136
+ });
137
+ return { items, total };
138
+ }
139
+ async findAttemptsByUser(userId, page, pageSize) {
140
+ this.ensureInitialized();
141
+ const [items, total] = await this.attemptRepo.findAndCount({
142
+ where: { userId },
143
+ order: { createdAt: 'DESC' },
144
+ skip: (page - 1) * pageSize,
145
+ take: pageSize,
146
+ });
147
+ return { items, total };
148
+ }
149
+ async findAttemptDetail(attemptId) {
150
+ this.ensureInitialized();
151
+ const attempt = await this.attemptRepo.findOne({ where: { id: attemptId } });
152
+ if (!attempt)
153
+ throw core_1.AppError.notFound('Attempt not found');
154
+ const answers = await this.answerRepo.find({ where: { attemptId } });
155
+ const qIds = answers.map((a) => a.questionId);
156
+ const questionMap = new Map();
157
+ if (qIds.length > 0) {
158
+ const questions = await this.questionRepo.createQueryBuilder('q')
159
+ .where('q.id IN (:...ids)', { ids: qIds })
160
+ .getMany();
161
+ questions.forEach((q) => questionMap.set(q.id, q));
162
+ }
163
+ const detailedAnswers = answers.map((a) => ({
164
+ ...a,
165
+ questionDetail: questionMap.get(a.questionId),
166
+ }));
167
+ return { attempt, answers: detailedAnswers };
168
+ }
169
+ autoGrade(question, userAnswer, maxScore) {
170
+ if (question.type === 'ESSAY' || question.type === 'FILL_BLANK') {
171
+ return { isCorrect: null, score: 0 };
172
+ }
173
+ if (!question.correctAnswer || userAnswer == null) {
174
+ return { isCorrect: false, score: 0 };
175
+ }
176
+ let correct;
177
+ try {
178
+ correct = JSON.parse(question.correctAnswer);
179
+ }
180
+ catch {
181
+ return { isCorrect: false, score: 0 };
182
+ }
183
+ const userStr = Array.isArray(userAnswer)
184
+ ? [...userAnswer].sort().join(',')
185
+ : String(userAnswer).toLowerCase();
186
+ const correctStr = Array.isArray(correct)
187
+ ? [...correct].sort().join(',')
188
+ : String(correct).toLowerCase();
189
+ const isCorrect = userStr === correctStr;
190
+ return { isCorrect, score: isCorrect ? maxScore : 0 };
191
+ }
192
+ };
193
+ exports.AttemptService = AttemptService;
194
+ exports.AttemptService = AttemptService = __decorate([
195
+ (0, core_1.Service)()
196
+ ], AttemptService);
197
+ //# sourceMappingURL=attempt.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.service.js","sourceRoot":"","sources":["../../src/services/attempt.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,+EAAiE;AACjE,6EAA+D;AAC/D,yEAA2D;AAC3D,6FAA8E;AAC9E,iFAAmE;AAU5D,IAAM,cAAc,GAApB,MAAM,cAAc;IACjB,WAAW,CAA2B;IACtC,UAAU,CAA0B;IACpC,QAAQ,CAAwB;IAChC,MAAM,CAAiC;IAC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MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YACvC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAElC,MAAM,SAAS,GAAG,OAAO,KAAK,UAAU,CAAC;QACzC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,CAAC;CACF,CAAA;AAnMY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,cAAO,GAAE;GACG,cAAc,CAmM1B"}
@@ -0,0 +1,14 @@
1
+ import { QuizCategory } from '../entities/quiz-category.entity.js';
2
+ import type { CreateCategoryDto, UpdateCategoryDto } from '../schemas/category.schema.js';
3
+ export declare class CategoryService {
4
+ private repo;
5
+ private initialized;
6
+ initialize(): void;
7
+ private ensureInitialized;
8
+ findAll(): Promise<QuizCategory[]>;
9
+ findById(id: string): Promise<QuizCategory>;
10
+ create(dto: CreateCategoryDto): Promise<QuizCategory>;
11
+ update(id: string, dto: UpdateCategoryDto): Promise<QuizCategory>;
12
+ delete(id: string): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=category.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category.service.d.ts","sourceRoot":"","sources":["../../src/services/category.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAE1F,qBACa,eAAe;IAC1B,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IAAI;IAMlB,OAAO,CAAC,iBAAiB;IAQnB,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKlC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO3C,MAAM,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAarD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAQjE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxC"}
@@ -0,0 +1,74 @@
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.CategoryService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_category_entity_js_1 = require("../entities/quiz-category.entity.js");
12
+ let CategoryService = class CategoryService {
13
+ repo;
14
+ initialized = false;
15
+ initialize() {
16
+ const db = core_1.Container.get(core_1.DatabaseService);
17
+ this.repo = db.getRepository(quiz_category_entity_js_1.QuizCategory);
18
+ this.initialized = true;
19
+ }
20
+ ensureInitialized() {
21
+ if (!this.initialized) {
22
+ try {
23
+ this.initialize();
24
+ }
25
+ catch {
26
+ throw new core_1.AppError('CategoryService not initialized', 500);
27
+ }
28
+ }
29
+ }
30
+ async findAll() {
31
+ this.ensureInitialized();
32
+ return this.repo.find({ order: { sortOrder: 'ASC', name: 'ASC' } });
33
+ }
34
+ async findById(id) {
35
+ this.ensureInitialized();
36
+ const entity = await this.repo.findOne({ where: { id } });
37
+ if (!entity)
38
+ throw core_1.AppError.notFound('Category not found');
39
+ return entity;
40
+ }
41
+ async create(dto) {
42
+ this.ensureInitialized();
43
+ const entity = this.repo.create({
44
+ name: dto.name,
45
+ parentId: dto.parentId ?? null,
46
+ description: dto.description ?? null,
47
+ sortOrder: dto.sortOrder ?? 0,
48
+ });
49
+ const saved = await this.repo.save(entity);
50
+ core_1.Container.get(core_1.LoggerService).info(`[CategoryService] Created category: ${saved.id}`);
51
+ return saved;
52
+ }
53
+ async update(id, dto) {
54
+ this.ensureInitialized();
55
+ const existing = await this.repo.findOne({ where: { id } });
56
+ if (!existing)
57
+ throw core_1.AppError.notFound('Category not found');
58
+ Object.assign(existing, dto);
59
+ return this.repo.save(existing);
60
+ }
61
+ async delete(id) {
62
+ this.ensureInitialized();
63
+ const existing = await this.repo.findOne({ where: { id } });
64
+ if (!existing)
65
+ throw core_1.AppError.notFound('Category not found');
66
+ await this.repo.remove(existing);
67
+ core_1.Container.get(core_1.LoggerService).info(`[CategoryService] Deleted category: ${id}`);
68
+ }
69
+ };
70
+ exports.CategoryService = CategoryService;
71
+ exports.CategoryService = CategoryService = __decorate([
72
+ (0, core_1.Service)()
73
+ ], CategoryService);
74
+ //# sourceMappingURL=category.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category.service.js","sourceRoot":"","sources":["../../src/services/category.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgG;AAEhG,iFAAmE;AAI5D,IAAM,eAAe,GAArB,MAAM,eAAe;IAClB,IAAI,CAA4B;IAChC,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,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,iBAAiB;QACvB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I,CAAC,uCAAuC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QACrF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,GAAsB;QAC7C,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,oBAAoB,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC7B,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,oBAAoB,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,gBAAS,CAAC,GAAG,CAAC,oBAAa,CAAC,CAAC,IAAI,CAAC,uCAAuC,EAAE,EAAE,CAAC,CAAC;IACjF,CAAC;CACF,CAAA;AA1DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,cAAO,GAAE;GACG,eAAe,CA0D3B"}
@@ -0,0 +1,17 @@
1
+ import { QuizExam } from '../entities/quiz-exam.entity.js';
2
+ import type { CreateExamDto, UpdateExamDto } from '../schemas/exam.schema.js';
3
+ export declare class ExamService {
4
+ private repo;
5
+ private initialized;
6
+ initialize(): void;
7
+ private ensureInitialized;
8
+ findAll(page: number, pageSize: number): Promise<{
9
+ items: QuizExam[];
10
+ total: number;
11
+ }>;
12
+ findById(id: string): Promise<QuizExam>;
13
+ create(dto: CreateExamDto, userId?: string): Promise<QuizExam>;
14
+ update(id: string, dto: UpdateExamDto): Promise<QuizExam>;
15
+ delete(id: string): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=exam.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exam.service.d.ts","sourceRoot":"","sources":["../../src/services/exam.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE9E,qBACa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,WAAW,CAAS;IAE5B,UAAU,IAAI,IAAI;IAMlB,OAAO,CAAC,iBAAiB;IAQnB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAUtF,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOvC,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmB9D,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;IAezD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxC"}
@@ -0,0 +1,92 @@
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.ExamService = void 0;
10
+ const core_1 = require("@octo-cyber/core");
11
+ const quiz_exam_entity_js_1 = require("../entities/quiz-exam.entity.js");
12
+ let ExamService = class ExamService {
13
+ repo;
14
+ initialized = false;
15
+ initialize() {
16
+ const db = core_1.Container.get(core_1.DatabaseService);
17
+ this.repo = db.getRepository(quiz_exam_entity_js_1.QuizExam);
18
+ this.initialized = true;
19
+ }
20
+ ensureInitialized() {
21
+ if (!this.initialized) {
22
+ try {
23
+ this.initialize();
24
+ }
25
+ catch {
26
+ throw new core_1.AppError('ExamService not initialized', 500);
27
+ }
28
+ }
29
+ }
30
+ async findAll(page, pageSize) {
31
+ this.ensureInitialized();
32
+ const [items, total] = await this.repo.findAndCount({
33
+ order: { createdAt: 'DESC' },
34
+ skip: (page - 1) * pageSize,
35
+ take: pageSize,
36
+ });
37
+ return { items, total };
38
+ }
39
+ async findById(id) {
40
+ this.ensureInitialized();
41
+ const entity = await this.repo.findOne({ where: { id } });
42
+ if (!entity)
43
+ throw core_1.AppError.notFound('Exam not found');
44
+ return entity;
45
+ }
46
+ async create(dto, userId) {
47
+ this.ensureInitialized();
48
+ const entity = this.repo.create({
49
+ title: dto.title,
50
+ paperId: dto.paperId,
51
+ description: dto.description ?? null,
52
+ startTime: dto.startTime ? new Date(dto.startTime) : null,
53
+ endTime: dto.endTime ? new Date(dto.endTime) : null,
54
+ maxAttempts: dto.maxAttempts ?? 1,
55
+ shuffleQuestions: dto.shuffleQuestions ?? false,
56
+ shuffleOptions: dto.shuffleOptions ?? false,
57
+ showAnswerAfterSubmit: dto.showAnswerAfterSubmit ?? false,
58
+ createdBy: userId ?? null,
59
+ });
60
+ const saved = await this.repo.save(entity);
61
+ core_1.Container.get(core_1.LoggerService).info(`[ExamService] Created exam: ${saved.id}`);
62
+ return saved;
63
+ }
64
+ async update(id, dto) {
65
+ this.ensureInitialized();
66
+ const existing = await this.repo.findOne({ where: { id } });
67
+ if (!existing)
68
+ throw core_1.AppError.notFound('Exam not found');
69
+ if (dto.startTime !== undefined) {
70
+ existing['startTime'] = dto.startTime ? new Date(dto.startTime) : null;
71
+ }
72
+ if (dto.endTime !== undefined) {
73
+ existing['endTime'] = dto.endTime ? new Date(dto.endTime) : null;
74
+ }
75
+ const { startTime: _s, endTime: _e, ...rest } = dto;
76
+ Object.assign(existing, rest);
77
+ return this.repo.save(existing);
78
+ }
79
+ async delete(id) {
80
+ this.ensureInitialized();
81
+ const existing = await this.repo.findOne({ where: { id } });
82
+ if (!existing)
83
+ throw core_1.AppError.notFound('Exam not found');
84
+ await this.repo.remove(existing);
85
+ core_1.Container.get(core_1.LoggerService).info(`[ExamService] Deleted exam: ${id}`);
86
+ }
87
+ };
88
+ exports.ExamService = ExamService;
89
+ exports.ExamService = ExamService = __decorate([
90
+ (0, core_1.Service)()
91
+ ], ExamService);
92
+ //# sourceMappingURL=exam.service.js.map