@hed-hog/lms 0.0.304 → 0.0.306

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 (458) hide show
  1. package/README.md +413 -401
  2. package/dist/certificate/certificate.controller.d.ts +90 -0
  3. package/dist/certificate/certificate.controller.d.ts.map +1 -0
  4. package/dist/certificate/certificate.controller.js +121 -0
  5. package/dist/certificate/certificate.controller.js.map +1 -0
  6. package/dist/certificate/certificate.module.d.ts +3 -0
  7. package/dist/certificate/certificate.module.d.ts.map +1 -0
  8. package/dist/certificate/certificate.module.js +26 -0
  9. package/dist/certificate/certificate.module.js.map +1 -0
  10. package/dist/certificate/certificate.service.d.ts +115 -0
  11. package/dist/certificate/certificate.service.d.ts.map +1 -0
  12. package/dist/certificate/certificate.service.js +343 -0
  13. package/dist/certificate/certificate.service.js.map +1 -0
  14. package/dist/certificate/dto/create-certificate-template.dto.d.ts +8 -0
  15. package/dist/certificate/dto/create-certificate-template.dto.d.ts.map +1 -0
  16. package/dist/certificate/dto/create-certificate-template.dto.js +44 -0
  17. package/dist/certificate/dto/create-certificate-template.dto.js.map +1 -0
  18. package/dist/certificate/dto/update-certificate-template.dto.d.ts +6 -0
  19. package/dist/certificate/dto/update-certificate-template.dto.d.ts.map +1 -0
  20. package/dist/certificate/dto/update-certificate-template.dto.js +9 -0
  21. package/dist/certificate/dto/update-certificate-template.dto.js.map +1 -0
  22. package/dist/class-group/class-group.controller.d.ts +305 -0
  23. package/dist/class-group/class-group.controller.d.ts.map +1 -0
  24. package/dist/class-group/class-group.controller.js +257 -0
  25. package/dist/class-group/class-group.controller.js.map +1 -0
  26. package/dist/class-group/class-group.module.d.ts +3 -0
  27. package/dist/class-group/class-group.module.d.ts.map +1 -0
  28. package/dist/class-group/class-group.module.js +25 -0
  29. package/dist/class-group/class-group.module.js.map +1 -0
  30. package/dist/class-group/class-group.service.d.ts +354 -0
  31. package/dist/class-group/class-group.service.d.ts.map +1 -0
  32. package/dist/class-group/class-group.service.js +1356 -0
  33. package/dist/class-group/class-group.service.js.map +1 -0
  34. package/dist/class-group/dto/create-class-group.dto.d.ts +33 -0
  35. package/dist/class-group/dto/create-class-group.dto.d.ts.map +1 -0
  36. package/dist/class-group/dto/create-class-group.dto.js +165 -0
  37. package/dist/class-group/dto/create-class-group.dto.js.map +1 -0
  38. package/dist/class-group/dto/create-session.dto.d.ts +22 -0
  39. package/dist/class-group/dto/create-session.dto.d.ts.map +1 -0
  40. package/dist/class-group/dto/create-session.dto.js +117 -0
  41. package/dist/class-group/dto/create-session.dto.js.map +1 -0
  42. package/dist/class-group/dto/enrollment.dto.d.ts +22 -0
  43. package/dist/class-group/dto/enrollment.dto.d.ts.map +1 -0
  44. package/dist/class-group/dto/enrollment.dto.js +89 -0
  45. package/dist/class-group/dto/enrollment.dto.js.map +1 -0
  46. package/dist/class-group/dto/update-class-group.dto.d.ts +6 -0
  47. package/dist/class-group/dto/update-class-group.dto.d.ts.map +1 -0
  48. package/dist/class-group/dto/update-class-group.dto.js +9 -0
  49. package/dist/class-group/dto/update-class-group.dto.js.map +1 -0
  50. package/dist/class-group/dto/update-session.dto.d.ts +7 -0
  51. package/dist/class-group/dto/update-session.dto.d.ts.map +1 -0
  52. package/dist/class-group/dto/update-session.dto.js +24 -0
  53. package/dist/class-group/dto/update-session.dto.js.map +1 -0
  54. package/dist/course/course-structure.controller.d.ts +127 -0
  55. package/dist/course/course-structure.controller.d.ts.map +1 -0
  56. package/dist/course/course-structure.controller.js +115 -0
  57. package/dist/course/course-structure.controller.js.map +1 -0
  58. package/dist/course/course-structure.service.d.ts +142 -0
  59. package/dist/course/course-structure.service.d.ts.map +1 -0
  60. package/dist/course/course-structure.service.js +445 -0
  61. package/dist/course/course-structure.service.js.map +1 -0
  62. package/dist/course/course.controller.d.ts +195 -0
  63. package/dist/course/course.controller.d.ts.map +1 -0
  64. package/dist/course/course.controller.js +104 -0
  65. package/dist/course/course.controller.js.map +1 -0
  66. package/dist/course/course.module.d.ts +3 -0
  67. package/dist/course/course.module.d.ts.map +1 -0
  68. package/dist/course/course.module.js +28 -0
  69. package/dist/course/course.module.js.map +1 -0
  70. package/dist/course/course.service.d.ts +215 -0
  71. package/dist/course/course.service.d.ts.map +1 -0
  72. package/dist/course/course.service.js +743 -0
  73. package/dist/course/course.service.js.map +1 -0
  74. package/dist/course/dto/create-course-structure-lesson.dto.d.ts +24 -0
  75. package/dist/course/dto/create-course-structure-lesson.dto.d.ts.map +1 -0
  76. package/dist/course/dto/create-course-structure-lesson.dto.js +118 -0
  77. package/dist/course/dto/create-course-structure-lesson.dto.js.map +1 -0
  78. package/dist/course/dto/create-course-structure-session.dto.d.ts +7 -0
  79. package/dist/course/dto/create-course-structure-session.dto.d.ts.map +1 -0
  80. package/dist/course/dto/create-course-structure-session.dto.js +40 -0
  81. package/dist/course/dto/create-course-structure-session.dto.js.map +1 -0
  82. package/dist/course/dto/create-course.dto.d.ts +26 -0
  83. package/dist/course/dto/create-course.dto.d.ts.map +1 -0
  84. package/dist/course/dto/create-course.dto.js +138 -0
  85. package/dist/course/dto/create-course.dto.js.map +1 -0
  86. package/dist/course/dto/update-course-structure-lesson.dto.d.ts +6 -0
  87. package/dist/course/dto/update-course-structure-lesson.dto.d.ts.map +1 -0
  88. package/dist/course/dto/update-course-structure-lesson.dto.js +9 -0
  89. package/dist/course/dto/update-course-structure-lesson.dto.js.map +1 -0
  90. package/dist/course/dto/update-course-structure-session.dto.d.ts +6 -0
  91. package/dist/course/dto/update-course-structure-session.dto.d.ts.map +1 -0
  92. package/dist/course/dto/update-course-structure-session.dto.js +9 -0
  93. package/dist/course/dto/update-course-structure-session.dto.js.map +1 -0
  94. package/dist/course/dto/update-course.dto.d.ts +6 -0
  95. package/dist/course/dto/update-course.dto.d.ts.map +1 -0
  96. package/dist/course/dto/update-course.dto.js +9 -0
  97. package/dist/course/dto/update-course.dto.js.map +1 -0
  98. package/dist/dashboard/dashboard.controller.d.ts +101 -0
  99. package/dist/dashboard/dashboard.controller.d.ts.map +1 -0
  100. package/dist/dashboard/dashboard.controller.js +40 -0
  101. package/dist/dashboard/dashboard.controller.js.map +1 -0
  102. package/dist/dashboard/dashboard.module.d.ts +3 -0
  103. package/dist/dashboard/dashboard.module.d.ts.map +1 -0
  104. package/dist/dashboard/dashboard.module.js +25 -0
  105. package/dist/dashboard/dashboard.module.js.map +1 -0
  106. package/dist/dashboard/dashboard.service.d.ts +130 -0
  107. package/dist/dashboard/dashboard.service.d.ts.map +1 -0
  108. package/dist/dashboard/dashboard.service.js +626 -0
  109. package/dist/dashboard/dashboard.service.js.map +1 -0
  110. package/dist/enterprise/dto/add-enterprise-class-group.dto.d.ts +4 -0
  111. package/dist/enterprise/dto/add-enterprise-class-group.dto.d.ts.map +1 -0
  112. package/dist/enterprise/dto/add-enterprise-class-group.dto.js +22 -0
  113. package/dist/enterprise/dto/add-enterprise-class-group.dto.js.map +1 -0
  114. package/dist/enterprise/dto/add-enterprise-course.dto.d.ts +5 -0
  115. package/dist/enterprise/dto/add-enterprise-course.dto.d.ts.map +1 -0
  116. package/dist/enterprise/dto/add-enterprise-course.dto.js +27 -0
  117. package/dist/enterprise/dto/add-enterprise-course.dto.js.map +1 -0
  118. package/dist/enterprise/dto/add-enterprise-student.dto.d.ts +5 -0
  119. package/dist/enterprise/dto/add-enterprise-student.dto.d.ts.map +1 -0
  120. package/dist/enterprise/dto/add-enterprise-student.dto.js +27 -0
  121. package/dist/enterprise/dto/add-enterprise-student.dto.js.map +1 -0
  122. package/dist/enterprise/dto/add-enterprise-user.dto.d.ts +7 -0
  123. package/dist/enterprise/dto/add-enterprise-user.dto.d.ts.map +1 -0
  124. package/dist/enterprise/dto/add-enterprise-user.dto.js +36 -0
  125. package/dist/enterprise/dto/add-enterprise-user.dto.js.map +1 -0
  126. package/dist/enterprise/dto/create-enterprise.dto.d.ts +10 -0
  127. package/dist/enterprise/dto/create-enterprise.dto.d.ts.map +1 -0
  128. package/dist/enterprise/dto/create-enterprise.dto.js +54 -0
  129. package/dist/enterprise/dto/create-enterprise.dto.js.map +1 -0
  130. package/dist/enterprise/dto/update-enterprise-student.dto.d.ts +4 -0
  131. package/dist/enterprise/dto/update-enterprise-student.dto.d.ts.map +1 -0
  132. package/dist/enterprise/dto/update-enterprise-student.dto.js +22 -0
  133. package/dist/enterprise/dto/update-enterprise-student.dto.js.map +1 -0
  134. package/dist/enterprise/dto/update-enterprise-user.dto.d.ts +5 -0
  135. package/dist/enterprise/dto/update-enterprise-user.dto.d.ts.map +1 -0
  136. package/dist/enterprise/dto/update-enterprise-user.dto.js +27 -0
  137. package/dist/enterprise/dto/update-enterprise-user.dto.js.map +1 -0
  138. package/dist/enterprise/dto/update-enterprise.dto.d.ts +6 -0
  139. package/dist/enterprise/dto/update-enterprise.dto.d.ts.map +1 -0
  140. package/dist/enterprise/dto/update-enterprise.dto.js +9 -0
  141. package/dist/enterprise/dto/update-enterprise.dto.js.map +1 -0
  142. package/dist/enterprise/enterprise.controller.d.ts +269 -0
  143. package/dist/enterprise/enterprise.controller.d.ts.map +1 -0
  144. package/dist/enterprise/enterprise.controller.js +311 -0
  145. package/dist/enterprise/enterprise.controller.js.map +1 -0
  146. package/dist/enterprise/enterprise.module.d.ts +3 -0
  147. package/dist/enterprise/enterprise.module.d.ts.map +1 -0
  148. package/dist/enterprise/enterprise.module.js +25 -0
  149. package/dist/enterprise/enterprise.module.js.map +1 -0
  150. package/dist/enterprise/enterprise.service.d.ts +282 -0
  151. package/dist/enterprise/enterprise.service.d.ts.map +1 -0
  152. package/dist/enterprise/enterprise.service.js +627 -0
  153. package/dist/enterprise/enterprise.service.js.map +1 -0
  154. package/dist/evaluation/evaluation.controller.d.ts +56 -0
  155. package/dist/evaluation/evaluation.controller.d.ts.map +1 -0
  156. package/dist/evaluation/evaluation.controller.js +76 -0
  157. package/dist/evaluation/evaluation.controller.js.map +1 -0
  158. package/dist/evaluation/evaluation.module.d.ts +3 -0
  159. package/dist/evaluation/evaluation.module.d.ts.map +1 -0
  160. package/dist/evaluation/evaluation.module.js +25 -0
  161. package/dist/evaluation/evaluation.module.js.map +1 -0
  162. package/dist/evaluation/evaluation.service.d.ts +67 -0
  163. package/dist/evaluation/evaluation.service.d.ts.map +1 -0
  164. package/dist/evaluation/evaluation.service.js +378 -0
  165. package/dist/evaluation/evaluation.service.js.map +1 -0
  166. package/dist/exam/dto/create-exam-question.dto.d.ts +25 -0
  167. package/dist/exam/dto/create-exam-question.dto.d.ts.map +1 -0
  168. package/dist/exam/dto/create-exam-question.dto.js +117 -0
  169. package/dist/exam/dto/create-exam-question.dto.js.map +1 -0
  170. package/dist/exam/dto/create-exam.dto.d.ts +11 -0
  171. package/dist/exam/dto/create-exam.dto.d.ts.map +1 -0
  172. package/dist/exam/dto/create-exam.dto.js +63 -0
  173. package/dist/exam/dto/create-exam.dto.js.map +1 -0
  174. package/dist/exam/dto/reorder-exam-questions.dto.d.ts +4 -0
  175. package/dist/exam/dto/reorder-exam-questions.dto.d.ts.map +1 -0
  176. package/dist/exam/dto/reorder-exam-questions.dto.js +23 -0
  177. package/dist/exam/dto/reorder-exam-questions.dto.js.map +1 -0
  178. package/dist/exam/dto/save-exam-attempt-answers.dto.d.ts +14 -0
  179. package/dist/exam/dto/save-exam-attempt-answers.dto.d.ts.map +1 -0
  180. package/dist/exam/dto/save-exam-attempt-answers.dto.js +68 -0
  181. package/dist/exam/dto/save-exam-attempt-answers.dto.js.map +1 -0
  182. package/dist/exam/dto/start-exam-attempt.dto.d.ts +4 -0
  183. package/dist/exam/dto/start-exam-attempt.dto.d.ts.map +1 -0
  184. package/dist/exam/dto/start-exam-attempt.dto.js +23 -0
  185. package/dist/exam/dto/start-exam-attempt.dto.js.map +1 -0
  186. package/dist/exam/dto/submit-exam-attempt.dto.d.ts +5 -0
  187. package/dist/exam/dto/submit-exam-attempt.dto.d.ts.map +1 -0
  188. package/dist/exam/dto/submit-exam-attempt.dto.js +23 -0
  189. package/dist/exam/dto/submit-exam-attempt.dto.js.map +1 -0
  190. package/dist/exam/dto/update-exam-question.dto.d.ts +6 -0
  191. package/dist/exam/dto/update-exam-question.dto.d.ts.map +1 -0
  192. package/dist/exam/dto/update-exam-question.dto.js +9 -0
  193. package/dist/exam/dto/update-exam-question.dto.js.map +1 -0
  194. package/dist/exam/dto/update-exam.dto.d.ts +6 -0
  195. package/dist/exam/dto/update-exam.dto.d.ts.map +1 -0
  196. package/dist/exam/dto/update-exam.dto.js +9 -0
  197. package/dist/exam/dto/update-exam.dto.js.map +1 -0
  198. package/dist/exam/exam-attempt.controller.d.ts +273 -0
  199. package/dist/exam/exam-attempt.controller.d.ts.map +1 -0
  200. package/dist/exam/exam-attempt.controller.js +84 -0
  201. package/dist/exam/exam-attempt.controller.js.map +1 -0
  202. package/dist/exam/exam-attempt.service.d.ts +302 -0
  203. package/dist/exam/exam-attempt.service.d.ts.map +1 -0
  204. package/dist/exam/exam-attempt.service.js +776 -0
  205. package/dist/exam/exam-attempt.service.js.map +1 -0
  206. package/dist/exam/exam.controller.d.ts +162 -0
  207. package/dist/exam/exam.controller.d.ts.map +1 -0
  208. package/dist/exam/exam.controller.js +158 -0
  209. package/dist/exam/exam.controller.js.map +1 -0
  210. package/dist/exam/exam.module.d.ts +3 -0
  211. package/dist/exam/exam.module.d.ts.map +1 -0
  212. package/dist/exam/exam.module.js +27 -0
  213. package/dist/exam/exam.module.js.map +1 -0
  214. package/dist/exam/exam.service.d.ts +179 -0
  215. package/dist/exam/exam.service.d.ts.map +1 -0
  216. package/dist/exam/exam.service.js +597 -0
  217. package/dist/exam/exam.service.js.map +1 -0
  218. package/dist/index.d.ts +28 -0
  219. package/dist/index.d.ts.map +1 -1
  220. package/dist/index.js +28 -0
  221. package/dist/index.js.map +1 -1
  222. package/dist/instructor/dto/create-instructor.dto.d.ts +10 -0
  223. package/dist/instructor/dto/create-instructor.dto.d.ts.map +1 -0
  224. package/dist/instructor/dto/create-instructor.dto.js +55 -0
  225. package/dist/instructor/dto/create-instructor.dto.js.map +1 -0
  226. package/dist/instructor/dto/update-instructor.dto.d.ts +9 -0
  227. package/dist/instructor/dto/update-instructor.dto.d.ts.map +1 -0
  228. package/dist/instructor/dto/update-instructor.dto.js +51 -0
  229. package/dist/instructor/dto/update-instructor.dto.js.map +1 -0
  230. package/dist/instructor/instructor.controller.d.ts +52 -0
  231. package/dist/instructor/instructor.controller.d.ts.map +1 -0
  232. package/dist/instructor/instructor.controller.js +98 -0
  233. package/dist/instructor/instructor.controller.js.map +1 -0
  234. package/dist/instructor/instructor.module.d.ts +3 -0
  235. package/dist/instructor/instructor.module.d.ts.map +1 -0
  236. package/dist/instructor/instructor.module.js +25 -0
  237. package/dist/instructor/instructor.module.js.map +1 -0
  238. package/dist/instructor/instructor.service.d.ts +79 -0
  239. package/dist/instructor/instructor.service.d.ts.map +1 -0
  240. package/dist/instructor/instructor.service.js +528 -0
  241. package/dist/instructor/instructor.service.js.map +1 -0
  242. package/dist/lms.module.d.ts.map +1 -1
  243. package/dist/lms.module.js +36 -4
  244. package/dist/lms.module.js.map +1 -1
  245. package/dist/reports/reports.controller.d.ts +69 -0
  246. package/dist/reports/reports.controller.d.ts.map +1 -0
  247. package/dist/reports/reports.controller.js +40 -0
  248. package/dist/reports/reports.controller.js.map +1 -0
  249. package/dist/reports/reports.module.d.ts +3 -0
  250. package/dist/reports/reports.module.d.ts.map +1 -0
  251. package/dist/reports/reports.module.js +25 -0
  252. package/dist/reports/reports.module.js.map +1 -0
  253. package/dist/reports/reports.service.d.ts +80 -0
  254. package/dist/reports/reports.service.d.ts.map +1 -0
  255. package/dist/reports/reports.service.js +366 -0
  256. package/dist/reports/reports.service.js.map +1 -0
  257. package/dist/training/dto/create-training.dto.d.ts +19 -0
  258. package/dist/training/dto/create-training.dto.d.ts.map +1 -0
  259. package/dist/training/dto/create-training.dto.js +98 -0
  260. package/dist/training/dto/create-training.dto.js.map +1 -0
  261. package/dist/training/dto/update-training.dto.d.ts +6 -0
  262. package/dist/training/dto/update-training.dto.d.ts.map +1 -0
  263. package/dist/training/dto/update-training.dto.js +9 -0
  264. package/dist/training/dto/update-training.dto.js.map +1 -0
  265. package/dist/training/training.controller.d.ts +195 -0
  266. package/dist/training/training.controller.d.ts.map +1 -0
  267. package/dist/training/training.controller.js +104 -0
  268. package/dist/training/training.controller.js.map +1 -0
  269. package/dist/training/training.module.d.ts +3 -0
  270. package/dist/training/training.module.d.ts.map +1 -0
  271. package/dist/training/training.module.js +25 -0
  272. package/dist/training/training.module.js.map +1 -0
  273. package/dist/training/training.service.d.ts +213 -0
  274. package/dist/training/training.service.d.ts.map +1 -0
  275. package/dist/training/training.service.js +497 -0
  276. package/dist/training/training.service.js.map +1 -0
  277. package/hedhog/data/dashboard.yaml +6 -0
  278. package/hedhog/data/dashboard_component.yaml +153 -0
  279. package/hedhog/data/dashboard_component_role.yaml +97 -0
  280. package/hedhog/data/dashboard_item.yaml +167 -0
  281. package/hedhog/data/dashboard_role.yaml +6 -0
  282. package/hedhog/data/instructor_qualification.yaml +16 -0
  283. package/hedhog/data/menu.yaml +129 -19
  284. package/hedhog/data/role.yaml +25 -1
  285. package/hedhog/data/route.yaml +867 -0
  286. package/hedhog/frontend/app/_components/class-form-sheet.tsx.ejs +1992 -0
  287. package/hedhog/frontend/app/_components/course-form-sheet.tsx.ejs +480 -0
  288. package/hedhog/frontend/app/_components/create-lms-instructor-sheet.tsx.ejs +591 -0
  289. package/hedhog/frontend/app/_components/create-lms-person-sheet.tsx.ejs +164 -0
  290. package/hedhog/frontend/app/_components/create-lms-student-person-sheet.tsx.ejs +120 -0
  291. package/hedhog/frontend/app/_components/lms-class-calendar.tsx.ejs +272 -0
  292. package/hedhog/frontend/app/_components/mobile-calendar.tsx.ejs +277 -0
  293. package/hedhog/frontend/app/_lib/editor/canvasInstance.ts.ejs +48 -0
  294. package/hedhog/frontend/app/_lib/editor/pctHelpers.ts.ejs +50 -0
  295. package/hedhog/frontend/app/_lib/editor/templateSerializer.ts.ejs +268 -0
  296. package/hedhog/frontend/app/_lib/editor/types.ts.ejs +94 -0
  297. package/hedhog/frontend/app/_lib/store/useTemplateStore.ts.ejs +284 -0
  298. package/hedhog/frontend/app/certificates/issued/page.tsx.ejs +638 -0
  299. package/hedhog/frontend/app/certificates/models/CanvasStage.tsx.ejs +916 -0
  300. package/hedhog/frontend/app/certificates/models/LeftPanel.tsx.ejs +200 -0
  301. package/hedhog/frontend/app/certificates/models/RightPanel.tsx.ejs +769 -0
  302. package/hedhog/frontend/app/certificates/models/TemplateEditorPage.tsx.ejs +104 -0
  303. package/hedhog/frontend/app/certificates/models/TopBar.tsx.ejs +354 -0
  304. package/hedhog/frontend/app/certificates/models/editor/page.tsx.ejs +5 -0
  305. package/hedhog/frontend/app/certificates/models/page.tsx.ejs +883 -0
  306. package/hedhog/frontend/app/classes/[id]/_components/event-summary-popover.tsx.ejs +279 -0
  307. package/hedhog/frontend/app/classes/[id]/_components/quick-create-session-popover.tsx.ejs +1027 -0
  308. package/hedhog/frontend/app/classes/[id]/page.tsx.ejs +3130 -993
  309. package/hedhog/frontend/app/classes/page.tsx.ejs +2731 -759
  310. package/hedhog/frontend/app/courses/[id]/_components/CourseCertificateCard.tsx.ejs +80 -0
  311. package/hedhog/frontend/app/courses/[id]/_components/CourseClassificationCard.tsx.ejs +226 -0
  312. package/hedhog/frontend/app/courses/[id]/_components/CourseContentCard.tsx.ejs +71 -0
  313. package/hedhog/frontend/app/courses/[id]/_components/CourseDangerZoneCard.tsx.ejs +42 -0
  314. package/hedhog/frontend/app/courses/[id]/_components/CourseFlagsCard.tsx.ejs +111 -0
  315. package/hedhog/frontend/app/courses/[id]/_components/CourseMainInfoCard.tsx.ejs +113 -0
  316. package/hedhog/frontend/app/courses/[id]/_components/CourseMediaCard.tsx.ejs +215 -0
  317. package/hedhog/frontend/app/courses/[id]/_components/CourseMultiEntityPicker.tsx.ejs +236 -0
  318. package/hedhog/frontend/app/courses/[id]/_components/CourseRelationsCard.tsx.ejs +141 -0
  319. package/hedhog/frontend/app/courses/[id]/_components/CourseSectionCard.tsx.ejs +57 -0
  320. package/hedhog/frontend/app/courses/[id]/_components/CourseSummaryCard.tsx.ejs +60 -0
  321. package/hedhog/frontend/app/courses/[id]/_components/course-edit-types.ts.ejs +33 -0
  322. package/hedhog/frontend/app/courses/[id]/page.tsx.ejs +933 -1103
  323. package/hedhog/frontend/app/courses/[id]/structure/page.tsx.ejs +699 -117
  324. package/hedhog/frontend/app/courses/page.tsx.ejs +1018 -1042
  325. package/hedhog/frontend/app/enterprise/[id]/page.tsx.ejs +317 -0
  326. package/hedhog/frontend/app/enterprise/_components/enterprise-activity-panel.tsx.ejs +88 -0
  327. package/hedhog/frontend/app/enterprise/_components/enterprise-admin-create-sheet.tsx.ejs +318 -0
  328. package/hedhog/frontend/app/enterprise/_components/enterprise-administrators-tab.tsx.ejs +332 -0
  329. package/hedhog/frontend/app/enterprise/_components/enterprise-class-create-sheet.tsx.ejs +58 -0
  330. package/hedhog/frontend/app/enterprise/_components/enterprise-classes-tab.tsx.ejs +390 -0
  331. package/hedhog/frontend/app/enterprise/_components/enterprise-company-identity-card.tsx.ejs +112 -0
  332. package/hedhog/frontend/app/enterprise/_components/enterprise-course-create-sheet.tsx.ejs +183 -0
  333. package/hedhog/frontend/app/enterprise/_components/enterprise-courses-tab.tsx.ejs +363 -0
  334. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-constants.ts.ejs +88 -0
  335. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-sheet.tsx.ejs +548 -0
  336. package/hedhog/frontend/app/enterprise/_components/enterprise-detail-utils.ts.ejs +33 -0
  337. package/hedhog/frontend/app/enterprise/_components/enterprise-mocks.ts.ejs +277 -0
  338. package/hedhog/frontend/app/enterprise/_components/enterprise-person-picker.ts.ejs +31 -0
  339. package/hedhog/frontend/app/enterprise/_components/enterprise-progress-bar.tsx.ejs +21 -0
  340. package/hedhog/frontend/app/enterprise/_components/enterprise-related-tab.tsx.ejs +224 -0
  341. package/hedhog/frontend/app/enterprise/_components/enterprise-sheet.tsx.ejs +397 -0
  342. package/hedhog/frontend/app/enterprise/_components/enterprise-student-create-sheet.tsx.ejs +167 -0
  343. package/hedhog/frontend/app/enterprise/_components/enterprise-students-tab.tsx.ejs +267 -0
  344. package/hedhog/frontend/app/enterprise/_components/enterprise-system-user-picker.ts.ejs +42 -0
  345. package/hedhog/frontend/app/enterprise/_components/enterprise-types.ts.ejs +96 -0
  346. package/hedhog/frontend/app/enterprise/_components/enterprise-user-create-sheet.tsx.ejs +207 -0
  347. package/hedhog/frontend/app/enterprise/_components/enterprise-user-distribution-chart.tsx.ejs +149 -0
  348. package/hedhog/frontend/app/enterprise/page.tsx.ejs +596 -0
  349. package/hedhog/frontend/app/evaluations/page.tsx.ejs +1250 -0
  350. package/hedhog/frontend/app/exams/[id]/attempt/page.tsx.ejs +642 -196
  351. package/hedhog/frontend/app/exams/[id]/page.tsx.ejs +11 -0
  352. package/hedhog/frontend/app/exams/[id]/questions/page.tsx.ejs +1316 -436
  353. package/hedhog/frontend/app/exams/page.tsx.ejs +799 -546
  354. package/hedhog/frontend/app/layout.tsx.ejs +5 -0
  355. package/hedhog/frontend/app/page.tsx.ejs +3 -1220
  356. package/hedhog/frontend/app/reports/courses/page.tsx.ejs +843 -0
  357. package/hedhog/frontend/app/reports/dashboard/page.tsx.ejs +890 -0
  358. package/hedhog/frontend/app/reports/page.tsx.ejs +802 -808
  359. package/hedhog/frontend/app/reports/students/page.tsx.ejs +772 -0
  360. package/hedhog/frontend/app/training/page.tsx.ejs +1873 -628
  361. package/hedhog/frontend/messages/en.json +1606 -111
  362. package/hedhog/frontend/messages/pt.json +1636 -134
  363. package/hedhog/frontend/widgets/active-classes-kpi.tsx.ejs +74 -0
  364. package/hedhog/frontend/widgets/active-courses-kpi.tsx.ejs +74 -0
  365. package/hedhog/frontend/widgets/approval-rate-kpi.tsx.ejs +81 -0
  366. package/hedhog/frontend/widgets/category-distribution-chart.tsx.ejs +119 -0
  367. package/hedhog/frontend/widgets/class-calendar.tsx.ejs +440 -0
  368. package/hedhog/frontend/widgets/completion-rate-kpi.tsx.ejs +81 -0
  369. package/hedhog/frontend/widgets/engagement-chart.tsx.ejs +120 -0
  370. package/hedhog/frontend/widgets/footer-summary.tsx.ejs +80 -0
  371. package/hedhog/frontend/widgets/issued-certificates-kpi.tsx.ejs +74 -0
  372. package/hedhog/frontend/widgets/latest-enrollments.tsx.ejs +166 -0
  373. package/hedhog/frontend/widgets/student-growth-chart.tsx.ejs +89 -0
  374. package/hedhog/frontend/widgets/top-courses-chart.tsx.ejs +104 -0
  375. package/hedhog/frontend/widgets/total-students-kpi.tsx.ejs +78 -0
  376. package/hedhog/frontend/widgets/upcoming-classes.tsx.ejs +152 -0
  377. package/hedhog/table/course.yaml +19 -1
  378. package/hedhog/table/course_class_group.yaml +8 -0
  379. package/hedhog/table/course_class_session.yaml +33 -0
  380. package/hedhog/table/course_instructor.yaml +27 -0
  381. package/hedhog/table/enterprise.yaml +29 -0
  382. package/hedhog/table/enterprise_class_group.yaml +20 -0
  383. package/hedhog/table/enterprise_course.yaml +23 -0
  384. package/hedhog/table/enterprise_student.yaml +24 -0
  385. package/hedhog/table/enterprise_user.yaml +35 -0
  386. package/hedhog/table/instructor_qualification.yaml +26 -0
  387. package/hedhog/table/instructor_qualification_assignment.yaml +22 -0
  388. package/hedhog/table/question.yaml +6 -0
  389. package/package.json +6 -6
  390. package/src/certificate/certificate.controller.ts +83 -0
  391. package/src/certificate/certificate.module.ts +13 -0
  392. package/src/certificate/certificate.service.ts +413 -0
  393. package/src/certificate/dto/create-certificate-template.dto.ts +25 -0
  394. package/src/certificate/dto/update-certificate-template.dto.ts +6 -0
  395. package/src/class-group/class-group.controller.ts +189 -0
  396. package/src/class-group/class-group.module.ts +12 -0
  397. package/src/class-group/class-group.service.ts +1802 -0
  398. package/src/class-group/dto/create-class-group.dto.ts +139 -0
  399. package/src/class-group/dto/create-session.dto.ts +102 -0
  400. package/src/class-group/dto/enrollment.dto.ts +70 -0
  401. package/src/class-group/dto/update-class-group.dto.ts +4 -0
  402. package/src/class-group/dto/update-session.dto.ts +9 -0
  403. package/src/course/course-structure.controller.ts +85 -0
  404. package/src/course/course-structure.service.ts +525 -0
  405. package/src/course/course.controller.ts +69 -0
  406. package/src/course/course.module.ts +15 -0
  407. package/src/course/course.service.ts +920 -0
  408. package/src/course/dto/create-course-structure-lesson.dto.ts +97 -0
  409. package/src/course/dto/create-course-structure-session.dto.ts +22 -0
  410. package/src/course/dto/create-course.dto.ts +111 -0
  411. package/src/course/dto/update-course-structure-lesson.dto.ts +6 -0
  412. package/src/course/dto/update-course-structure-session.dto.ts +6 -0
  413. package/src/course/dto/update-course.dto.ts +4 -0
  414. package/src/dashboard/dashboard.controller.ts +14 -0
  415. package/src/dashboard/dashboard.module.ts +12 -0
  416. package/src/dashboard/dashboard.service.ts +726 -0
  417. package/src/enterprise/dto/add-enterprise-class-group.dto.ts +7 -0
  418. package/src/enterprise/dto/add-enterprise-course.dto.ts +11 -0
  419. package/src/enterprise/dto/add-enterprise-student.dto.ts +16 -0
  420. package/src/enterprise/dto/add-enterprise-user.dto.ts +23 -0
  421. package/src/enterprise/dto/create-enterprise.dto.ts +41 -0
  422. package/src/enterprise/dto/update-enterprise-student.dto.ts +7 -0
  423. package/src/enterprise/dto/update-enterprise-user.dto.ts +11 -0
  424. package/src/enterprise/dto/update-enterprise.dto.ts +4 -0
  425. package/src/enterprise/enterprise.controller.ts +233 -0
  426. package/src/enterprise/enterprise.module.ts +12 -0
  427. package/src/enterprise/enterprise.service.ts +712 -0
  428. package/src/evaluation/evaluation.controller.ts +44 -0
  429. package/src/evaluation/evaluation.module.ts +12 -0
  430. package/src/evaluation/evaluation.service.ts +394 -0
  431. package/src/exam/dto/create-exam-question.dto.ts +103 -0
  432. package/src/exam/dto/create-exam.dto.ts +41 -0
  433. package/src/exam/dto/reorder-exam-questions.dto.ts +8 -0
  434. package/src/exam/dto/save-exam-attempt-answers.dto.ts +55 -0
  435. package/src/exam/dto/start-exam-attempt.dto.ts +8 -0
  436. package/src/exam/dto/submit-exam-attempt.dto.ts +8 -0
  437. package/src/exam/dto/update-exam-question.dto.ts +4 -0
  438. package/src/exam/dto/update-exam.dto.ts +4 -0
  439. package/src/exam/exam-attempt.controller.ts +65 -0
  440. package/src/exam/exam-attempt.service.ts +1008 -0
  441. package/src/exam/exam.controller.ts +102 -0
  442. package/src/exam/exam.module.ts +14 -0
  443. package/src/exam/exam.service.ts +784 -0
  444. package/src/index.ts +29 -0
  445. package/src/instructor/dto/create-instructor.dto.ts +43 -0
  446. package/src/instructor/dto/update-instructor.dto.ts +38 -0
  447. package/src/instructor/instructor.controller.ts +73 -0
  448. package/src/instructor/instructor.module.ts +12 -0
  449. package/src/instructor/instructor.service.ts +646 -0
  450. package/src/lms.module.ts +36 -4
  451. package/src/reports/reports.controller.ts +14 -0
  452. package/src/reports/reports.module.ts +12 -0
  453. package/src/reports/reports.service.ts +485 -0
  454. package/src/training/dto/create-training.dto.ts +81 -0
  455. package/src/training/dto/update-training.dto.ts +4 -0
  456. package/src/training/training.controller.ts +68 -0
  457. package/src/training/training.module.ts +12 -0
  458. package/src/training/training.service.ts +574 -0
@@ -0,0 +1,784 @@
1
+ import { PrismaService } from '@hed-hog/api-prisma';
2
+ import {
3
+ BadRequestException,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import {
8
+ CreateExamQuestionDto,
9
+ OBJECTIVE_EXAM_QUESTION_TYPES,
10
+ type ExamQuestionType,
11
+ } from './dto/create-exam-question.dto';
12
+ import { CreateExamDto } from './dto/create-exam.dto';
13
+ import { UpdateExamQuestionDto } from './dto/update-exam-question.dto';
14
+ import { UpdateExamDto } from './dto/update-exam.dto';
15
+
16
+ @Injectable()
17
+ export class ExamService {
18
+ constructor(private readonly prisma: PrismaService) {}
19
+
20
+ async list(params: {
21
+ page?: number;
22
+ pageSize?: number;
23
+ search?: string;
24
+ status?: string;
25
+ }) {
26
+ const page = Math.max(Number(params.page) || 1, 1);
27
+ const pageSize = Math.max(Number(params.pageSize) || 12, 1);
28
+ const skip = (page - 1) * pageSize;
29
+
30
+ const where: any = {};
31
+
32
+ if (params.status) {
33
+ where.status = params.status;
34
+ }
35
+
36
+ if (params.search) {
37
+ const normalized = params.search.trim();
38
+ const parsedId = this.parseCodeToId(normalized);
39
+
40
+ where.OR = [
41
+ { title: { contains: normalized, mode: 'insensitive' } },
42
+ { description: { contains: normalized, mode: 'insensitive' } },
43
+ { instructions: { contains: normalized, mode: 'insensitive' } },
44
+ ];
45
+
46
+ if (parsedId !== null) {
47
+ where.OR.push({ id: parsedId });
48
+ }
49
+ }
50
+
51
+ const [exams, total] = await Promise.all([
52
+ this.prisma.exam.findMany({
53
+ skip,
54
+ take: pageSize,
55
+ where,
56
+ orderBy: { created_at: 'desc' },
57
+ include: {
58
+ _count: {
59
+ select: {
60
+ exam_question: true,
61
+ exam_attempt: true,
62
+ },
63
+ },
64
+ },
65
+ }),
66
+ this.prisma.exam.count({ where }),
67
+ ]);
68
+
69
+ const avgScores = await this.findAverageScoresByExam(
70
+ exams.map((exam) => exam.id),
71
+ );
72
+
73
+ return {
74
+ total,
75
+ page,
76
+ pageSize,
77
+ lastPage: Math.max(1, Math.ceil(total / pageSize)),
78
+ data: exams.map((exam) => this.mapExam(exam, avgScores[exam.id] ?? 0)),
79
+ };
80
+ }
81
+
82
+ async stats() {
83
+ const [totalExams, publishedExams, totalQuestions, avgScore] =
84
+ await Promise.all([
85
+ this.prisma.exam.count(),
86
+ this.prisma.exam.count({ where: { status: 'published' } }),
87
+ this.prisma.exam_question.count(),
88
+ this.prisma.exam_attempt.aggregate({
89
+ _avg: { score: true },
90
+ where: { score: { not: null } },
91
+ }),
92
+ ]);
93
+
94
+ return {
95
+ totalExams,
96
+ publishedExams,
97
+ totalQuestions,
98
+ overallAverage: this.scoreToTen(avgScore._avg.score ?? 0),
99
+ };
100
+ }
101
+
102
+ async getById(id: number) {
103
+ const exam = await this.prisma.exam.findUnique({
104
+ where: { id },
105
+ include: {
106
+ _count: {
107
+ select: {
108
+ exam_question: true,
109
+ exam_attempt: true,
110
+ },
111
+ },
112
+ },
113
+ });
114
+
115
+ if (!exam) return null;
116
+
117
+ const avgScores = await this.findAverageScoresByExam([id]);
118
+ return this.mapExam(exam, avgScores[id] ?? 0);
119
+ }
120
+
121
+ async listQuestions(examId: number) {
122
+ const exam = await this.prisma.exam.findUnique({
123
+ where: { id: examId },
124
+ include: {
125
+ _count: {
126
+ select: {
127
+ exam_question: true,
128
+ },
129
+ },
130
+ exam_question: {
131
+ orderBy: { order: 'asc' },
132
+ include: {
133
+ question: {
134
+ include: {
135
+ exam_option: {
136
+ orderBy: { position: 'asc' },
137
+ },
138
+ },
139
+ },
140
+ },
141
+ },
142
+ },
143
+ });
144
+
145
+ if (!exam) {
146
+ throw new NotFoundException('Exam not found');
147
+ }
148
+
149
+ return {
150
+ exam: {
151
+ id: exam.id,
152
+ code: this.idToCode(exam.id),
153
+ title: exam.title,
154
+ },
155
+ questionCount: exam._count.exam_question,
156
+ data: exam.exam_question.map((item) => this.mapExamQuestion(item)),
157
+ };
158
+ }
159
+
160
+ async createQuestion(examId: number, dto: CreateExamQuestionDto) {
161
+ const exam = await this.prisma.exam.findUnique({ where: { id: examId } });
162
+ if (!exam) {
163
+ throw new NotFoundException('Exam not found');
164
+ }
165
+
166
+ const last = await this.prisma.exam_question.findFirst({
167
+ where: { exam_id: examId },
168
+ orderBy: { order: 'desc' },
169
+ select: { order: true },
170
+ });
171
+ const questionType = this.resolveQuestionType(dto.questionType);
172
+ const alternatives = this.normalizeAlternatives(
173
+ questionType,
174
+ dto.alternatives,
175
+ true,
176
+ );
177
+ const fillBlankAnswers = this.normalizeFillBlankAnswers(
178
+ questionType,
179
+ dto.fillBlankAnswers,
180
+ true,
181
+ );
182
+ const matchingPairs = this.normalizeMatchingPairs(
183
+ questionType,
184
+ dto.matchingPairs,
185
+ true,
186
+ );
187
+ const specialOptions = this.buildSpecialOptions(
188
+ questionType,
189
+ fillBlankAnswers,
190
+ matchingPairs,
191
+ );
192
+
193
+ const created = await this.prisma.$transaction(async (tx) => {
194
+ const question = await tx.question.create({
195
+ data: {
196
+ question_type: questionType,
197
+ statement: dto.statement,
198
+ points: dto.points,
199
+ },
200
+ });
201
+
202
+ const optionsToPersist =
203
+ alternatives.length > 0
204
+ ? alternatives.map((alternative, index) => ({
205
+ question_id: question.id,
206
+ option_text: alternative.text,
207
+ is_correct: alternative.isCorrect,
208
+ position: index,
209
+ }))
210
+ : specialOptions.map((option, index) => ({
211
+ question_id: question.id,
212
+ option_text: option.optionText,
213
+ is_correct: true,
214
+ position: index,
215
+ }));
216
+
217
+ if (optionsToPersist.length > 0) {
218
+ await tx.exam_option.createMany({
219
+ data: optionsToPersist,
220
+ });
221
+ }
222
+
223
+ const relation = await tx.exam_question.create({
224
+ data: {
225
+ exam_id: examId,
226
+ question_id: question.id,
227
+ order: (last?.order ?? -1) + 1,
228
+ },
229
+ });
230
+
231
+ return tx.exam_question.findUnique({
232
+ where: { id: relation.id },
233
+ include: {
234
+ question: {
235
+ include: {
236
+ exam_option: {
237
+ orderBy: { position: 'asc' },
238
+ },
239
+ },
240
+ },
241
+ },
242
+ });
243
+ });
244
+
245
+ return this.mapExamQuestion(created);
246
+ }
247
+
248
+ async updateQuestion(
249
+ examId: number,
250
+ questionId: number,
251
+ dto: UpdateExamQuestionDto,
252
+ ) {
253
+ const relation = await this.prisma.exam_question.findFirst({
254
+ where: {
255
+ exam_id: examId,
256
+ question_id: questionId,
257
+ },
258
+ select: {
259
+ id: true,
260
+ question_id: true,
261
+ question: {
262
+ select: {
263
+ question_type: true,
264
+ },
265
+ },
266
+ },
267
+ });
268
+
269
+ if (!relation) {
270
+ throw new NotFoundException('Question not found in exam');
271
+ }
272
+
273
+ const nextQuestionType = this.resolveQuestionType(
274
+ dto.questionType ?? relation.question.question_type,
275
+ );
276
+ const shouldReplaceAlternatives =
277
+ dto.alternatives !== undefined ||
278
+ nextQuestionType !== relation.question.question_type;
279
+ const alternatives = shouldReplaceAlternatives
280
+ ? this.normalizeAlternatives(
281
+ nextQuestionType,
282
+ dto.alternatives,
283
+ nextQuestionType !== relation.question.question_type,
284
+ )
285
+ : null;
286
+ const shouldReplaceFillBlankAnswers =
287
+ dto.fillBlankAnswers !== undefined ||
288
+ nextQuestionType !== relation.question.question_type;
289
+ const fillBlankAnswers = shouldReplaceFillBlankAnswers
290
+ ? this.normalizeFillBlankAnswers(
291
+ nextQuestionType,
292
+ dto.fillBlankAnswers,
293
+ nextQuestionType !== relation.question.question_type,
294
+ )
295
+ : null;
296
+ const shouldReplaceMatchingPairs =
297
+ dto.matchingPairs !== undefined ||
298
+ nextQuestionType !== relation.question.question_type;
299
+ const matchingPairs = shouldReplaceMatchingPairs
300
+ ? this.normalizeMatchingPairs(
301
+ nextQuestionType,
302
+ dto.matchingPairs,
303
+ nextQuestionType !== relation.question.question_type,
304
+ )
305
+ : null;
306
+ const shouldReplaceSpecialOptions =
307
+ shouldReplaceFillBlankAnswers || shouldReplaceMatchingPairs;
308
+ const specialOptions = shouldReplaceSpecialOptions
309
+ ? this.buildSpecialOptions(
310
+ nextQuestionType,
311
+ fillBlankAnswers,
312
+ matchingPairs,
313
+ )
314
+ : [];
315
+
316
+ const updated = await this.prisma.$transaction(async (tx) => {
317
+ await tx.question.update({
318
+ where: { id: relation.question_id },
319
+ data: {
320
+ ...(dto.questionType !== undefined && {
321
+ question_type: nextQuestionType,
322
+ }),
323
+ ...(dto.statement !== undefined && { statement: dto.statement }),
324
+ ...(dto.points !== undefined && { points: dto.points }),
325
+ },
326
+ });
327
+
328
+ if (shouldReplaceAlternatives || shouldReplaceSpecialOptions) {
329
+ await tx.exam_option.deleteMany({
330
+ where: { question_id: relation.question_id },
331
+ });
332
+
333
+ const optionsToPersist = (alternatives?.length ?? 0)
334
+ ? alternatives!.map((alternative, index) => ({
335
+ question_id: relation.question_id,
336
+ option_text: alternative.text,
337
+ is_correct: alternative.isCorrect,
338
+ position: index,
339
+ }))
340
+ : specialOptions.map((option, index) => ({
341
+ question_id: relation.question_id,
342
+ option_text: option.optionText,
343
+ is_correct: true,
344
+ position: index,
345
+ }));
346
+
347
+ if (optionsToPersist.length > 0) {
348
+ await tx.exam_option.createMany({
349
+ data: optionsToPersist,
350
+ });
351
+ }
352
+ }
353
+
354
+ return tx.exam_question.findUnique({
355
+ where: { id: relation.id },
356
+ include: {
357
+ question: {
358
+ include: {
359
+ exam_option: {
360
+ orderBy: { position: 'asc' },
361
+ },
362
+ },
363
+ },
364
+ },
365
+ });
366
+ });
367
+
368
+ return this.mapExamQuestion(updated);
369
+ }
370
+
371
+ async removeQuestion(examId: number, questionId: number) {
372
+ await this.prisma.exam_question.deleteMany({
373
+ where: {
374
+ exam_id: examId,
375
+ question_id: questionId,
376
+ },
377
+ });
378
+
379
+ const remaining = await this.prisma.exam_question.findMany({
380
+ where: { exam_id: examId },
381
+ orderBy: { order: 'asc' },
382
+ select: { id: true },
383
+ });
384
+
385
+ await Promise.all(
386
+ remaining.map((item, index) =>
387
+ this.prisma.exam_question.update({
388
+ where: { id: item.id },
389
+ data: { order: index },
390
+ }),
391
+ ),
392
+ );
393
+
394
+ return { success: true };
395
+ }
396
+
397
+ async reorderQuestions(examId: number, questionIds: number[]) {
398
+ const relations = await this.prisma.exam_question.findMany({
399
+ where: { exam_id: examId },
400
+ select: { question_id: true, id: true },
401
+ });
402
+
403
+ const existingQuestionIds = new Set(relations.map((item) => item.question_id));
404
+ const receivedQuestionIds = new Set(questionIds);
405
+
406
+ if (
407
+ existingQuestionIds.size !== receivedQuestionIds.size ||
408
+ !questionIds.every((id) => existingQuestionIds.has(id))
409
+ ) {
410
+ return { success: false };
411
+ }
412
+
413
+ const byQuestionId = new Map(relations.map((item) => [item.question_id, item.id]));
414
+
415
+ await this.prisma.$transaction(
416
+ questionIds.map((questionId, index) =>
417
+ this.prisma.exam_question.update({
418
+ where: { id: byQuestionId.get(questionId)! },
419
+ data: { order: index },
420
+ }),
421
+ ),
422
+ );
423
+
424
+ return { success: true };
425
+ }
426
+
427
+ async create(dto: CreateExamDto) {
428
+ const exam = await this.prisma.exam.create({
429
+ data: {
430
+ title: dto.title,
431
+ exam_type: 'test',
432
+ status: dto.status ?? 'draft',
433
+ min_score: this.scoreFromTen(dto.minScore ?? 7),
434
+ time_limit_minutes: dto.timeLimit ?? 60,
435
+ shuffle_questions: dto.shuffle ?? false,
436
+ ...(dto.primaryColor !== undefined && {
437
+ primary_color: dto.primaryColor,
438
+ }),
439
+ ...(dto.secondaryColor !== undefined && {
440
+ secondary_color: dto.secondaryColor,
441
+ }),
442
+ },
443
+ include: {
444
+ _count: {
445
+ select: {
446
+ exam_question: true,
447
+ exam_attempt: true,
448
+ },
449
+ },
450
+ },
451
+ });
452
+
453
+ return this.mapExam(exam, 0);
454
+ }
455
+
456
+ async update(id: number, dto: UpdateExamDto) {
457
+ const exam = await this.prisma.exam.update({
458
+ where: { id },
459
+ data: {
460
+ ...(dto.title !== undefined && { title: dto.title }),
461
+ ...(dto.status !== undefined && { status: dto.status }),
462
+ ...(dto.minScore !== undefined && {
463
+ min_score: this.scoreFromTen(dto.minScore),
464
+ }),
465
+ ...(dto.timeLimit !== undefined && {
466
+ time_limit_minutes: dto.timeLimit,
467
+ }),
468
+ ...(dto.shuffle !== undefined && {
469
+ shuffle_questions: dto.shuffle,
470
+ }),
471
+ ...(dto.primaryColor !== undefined && {
472
+ primary_color: dto.primaryColor,
473
+ }),
474
+ ...(dto.secondaryColor !== undefined && {
475
+ secondary_color: dto.secondaryColor,
476
+ }),
477
+ },
478
+ include: {
479
+ _count: {
480
+ select: {
481
+ exam_question: true,
482
+ exam_attempt: true,
483
+ },
484
+ },
485
+ },
486
+ });
487
+
488
+ const avgScores = await this.findAverageScoresByExam([id]);
489
+ return this.mapExam(exam, avgScores[id] ?? 0);
490
+ }
491
+
492
+ async remove(id: number) {
493
+ await this.prisma.exam.delete({ where: { id } });
494
+ return { success: true };
495
+ }
496
+
497
+ private async findAverageScoresByExam(examIds: number[]) {
498
+ if (examIds.length === 0) return {} as Record<number, number>;
499
+
500
+ const grouped = await this.prisma.exam_attempt.groupBy({
501
+ by: ['exam_id'],
502
+ where: {
503
+ exam_id: { in: examIds },
504
+ score: { not: null },
505
+ },
506
+ _avg: { score: true },
507
+ });
508
+
509
+ return grouped.reduce(
510
+ (acc, item) => {
511
+ acc[item.exam_id] = this.scoreToTen(item._avg.score ?? 0);
512
+ return acc;
513
+ },
514
+ {} as Record<number, number>,
515
+ );
516
+ }
517
+
518
+ private mapExam(exam: any, averageScore: number) {
519
+ return {
520
+ id: exam.id,
521
+ code: this.idToCode(exam.id),
522
+ title: exam.title,
523
+ minScore: this.scoreToTen(exam.min_score ?? 0),
524
+ timeLimit: exam.time_limit_minutes ?? 0,
525
+ shuffle: Boolean(exam.shuffle_questions),
526
+ status: exam.status,
527
+ questions: exam._count?.exam_question ?? 0,
528
+ attempts: exam._count?.exam_attempt ?? 0,
529
+ averageScore,
530
+ primaryColor: exam.primary_color ?? null,
531
+ primaryContrastColor: exam.primary_contrast_color ?? null,
532
+ secondaryColor: exam.secondary_color ?? null,
533
+ secondaryContrastColor: exam.secondary_contrast_color ?? null,
534
+ createdAt: exam.created_at,
535
+ };
536
+ }
537
+
538
+ private mapExamQuestion(item: any) {
539
+ const questionType = this.resolveQuestionType(item.question.question_type);
540
+ const parsedOptions = this.parseSpecialOptions(item.question.exam_option ?? []);
541
+
542
+ return {
543
+ id: item.question.id,
544
+ examQuestionId: item.id,
545
+ order: item.order,
546
+ questionType,
547
+ statement: item.question.statement,
548
+ points: item.question.points,
549
+ fillBlankAnswers: parsedOptions.fillBlankAnswers,
550
+ matchingPairs: parsedOptions.matchingPairs,
551
+ alternatives: OBJECTIVE_EXAM_QUESTION_TYPES.includes(questionType)
552
+ ? (item.question.exam_option ?? []).map((option: any) => ({
553
+ id: option.id,
554
+ text: option.option_text,
555
+ isCorrect: Boolean(option.is_correct),
556
+ }))
557
+ : [],
558
+ };
559
+ }
560
+
561
+ private parseCodeToId(value: string) {
562
+ const normalized = value.trim();
563
+
564
+ if (/^\d+$/.test(normalized)) {
565
+ return Number(normalized);
566
+ }
567
+
568
+ const codeMatch = normalized.match(/^ex[-_\s]?0*(\d+)$/i);
569
+ if (!codeMatch) return null;
570
+
571
+ return Number(codeMatch[1]);
572
+ }
573
+
574
+ private idToCode(id: number) {
575
+ return `EX-${String(id).padStart(3, '0')}`;
576
+ }
577
+
578
+ private scoreToTen(score: number) {
579
+ if (!score) return 0;
580
+ return score > 10 ? Number((score / 10).toFixed(1)) : Number(score.toFixed(1));
581
+ }
582
+
583
+ private scoreFromTen(score: number) {
584
+ if (score > 10) return Math.round(score);
585
+ return Math.round(score * 10);
586
+ }
587
+
588
+ private resolveQuestionType(questionType?: string): ExamQuestionType {
589
+ return (questionType as ExamQuestionType | undefined) ?? 'multiple_choice';
590
+ }
591
+
592
+ private normalizeAlternatives(
593
+ questionType: ExamQuestionType,
594
+ alternatives: CreateExamQuestionDto['alternatives'],
595
+ requireOnObjective: boolean,
596
+ ) {
597
+ if (!OBJECTIVE_EXAM_QUESTION_TYPES.includes(questionType)) {
598
+ return [];
599
+ }
600
+
601
+ if (!alternatives || alternatives.length < 2) {
602
+ if (requireOnObjective) {
603
+ throw new BadRequestException(
604
+ 'Objective questions require at least 2 alternatives',
605
+ );
606
+ }
607
+
608
+ return [];
609
+ }
610
+
611
+ const normalized = alternatives.map((alternative) => ({
612
+ text: alternative.text.trim(),
613
+ isCorrect: Boolean(alternative.isCorrect),
614
+ }));
615
+
616
+ if (normalized.some((alternative) => alternative.text.length === 0)) {
617
+ throw new BadRequestException('All alternatives must have text');
618
+ }
619
+
620
+ const correctCount = normalized.filter(
621
+ (alternative) => alternative.isCorrect,
622
+ ).length;
623
+
624
+ if (correctCount === 0) {
625
+ throw new BadRequestException(
626
+ 'Objective questions require at least 1 correct alternative',
627
+ );
628
+ }
629
+
630
+ if (questionType === 'true_false' && normalized.length !== 2) {
631
+ throw new BadRequestException(
632
+ 'True/false questions require exactly 2 alternatives',
633
+ );
634
+ }
635
+
636
+ return normalized;
637
+ }
638
+
639
+ private normalizeFillBlankAnswers(
640
+ questionType: ExamQuestionType,
641
+ fillBlankAnswers: CreateExamQuestionDto['fillBlankAnswers'],
642
+ requireOnFillBlank: boolean,
643
+ ) {
644
+ if (questionType !== 'fill_blank') {
645
+ return null;
646
+ }
647
+
648
+ if (!fillBlankAnswers || fillBlankAnswers.length === 0) {
649
+ if (requireOnFillBlank) {
650
+ throw new BadRequestException(
651
+ 'Fill-blank questions require at least 1 expected answer',
652
+ );
653
+ }
654
+
655
+ return [];
656
+ }
657
+
658
+ const normalized = fillBlankAnswers.map((item) => ({
659
+ answer: item.answer.trim(),
660
+ alternatives: (item.alternatives ?? [])
661
+ .map((alternative) => alternative.trim())
662
+ .filter((alternative) => alternative.length > 0),
663
+ }));
664
+
665
+ if (normalized.some((item) => item.answer.length === 0)) {
666
+ throw new BadRequestException(
667
+ 'Fill-blank expected answers cannot be empty',
668
+ );
669
+ }
670
+
671
+ return normalized;
672
+ }
673
+
674
+ private normalizeMatchingPairs(
675
+ questionType: ExamQuestionType,
676
+ matchingPairs: CreateExamQuestionDto['matchingPairs'],
677
+ requireOnMatching: boolean,
678
+ ) {
679
+ if (questionType !== 'matching') {
680
+ return null;
681
+ }
682
+
683
+ if (!matchingPairs || matchingPairs.length < 2) {
684
+ if (requireOnMatching) {
685
+ throw new BadRequestException(
686
+ 'Matching questions require at least 2 pairs',
687
+ );
688
+ }
689
+
690
+ return [];
691
+ }
692
+
693
+ const normalized = matchingPairs.map((pair, index) => ({
694
+ id: pair.id.trim() || `pair-${index + 1}`,
695
+ leftText: pair.leftText.trim(),
696
+ rightText: pair.rightText.trim(),
697
+ }));
698
+
699
+ if (
700
+ normalized.some(
701
+ (pair) => pair.leftText.length === 0 || pair.rightText.length === 0,
702
+ )
703
+ ) {
704
+ throw new BadRequestException('Matching pair texts cannot be empty');
705
+ }
706
+
707
+ const uniqueIds = new Set(normalized.map((pair) => pair.id));
708
+ if (uniqueIds.size !== normalized.length) {
709
+ throw new BadRequestException('Matching pair ids must be unique');
710
+ }
711
+
712
+ return normalized;
713
+ }
714
+
715
+ private buildSpecialOptions(
716
+ questionType: ExamQuestionType,
717
+ fillBlankAnswers: Array<{ answer: string; alternatives: string[] }> | null,
718
+ matchingPairs: Array<{ id: string; leftText: string; rightText: string }> | null,
719
+ ) {
720
+ if (questionType === 'fill_blank') {
721
+ return (fillBlankAnswers ?? []).map((item) => ({
722
+ optionText: JSON.stringify({
723
+ kind: 'fill_blank',
724
+ answer: item.answer,
725
+ alternatives: item.alternatives,
726
+ }),
727
+ }));
728
+ }
729
+
730
+ if (questionType === 'matching') {
731
+ return (matchingPairs ?? []).map((pair) => ({
732
+ optionText: JSON.stringify({
733
+ kind: 'matching',
734
+ id: pair.id,
735
+ leftText: pair.leftText,
736
+ rightText: pair.rightText,
737
+ }),
738
+ }));
739
+ }
740
+
741
+ return [] as Array<{ optionText: string }>;
742
+ }
743
+
744
+ private parseSpecialOptions(options: any[]) {
745
+ const fillBlankAnswers: Array<{ answer: string; alternatives?: string[] }> = [];
746
+ const matchingPairs: Array<{ id: string; leftText: string; rightText: string }> = [];
747
+
748
+ for (const option of options) {
749
+ try {
750
+ const parsed = JSON.parse(option.option_text);
751
+
752
+ if (parsed?.kind === 'fill_blank' && typeof parsed.answer === 'string') {
753
+ fillBlankAnswers.push({
754
+ answer: parsed.answer,
755
+ alternatives: Array.isArray(parsed.alternatives)
756
+ ? parsed.alternatives
757
+ : [],
758
+ });
759
+ continue;
760
+ }
761
+
762
+ if (
763
+ parsed?.kind === 'matching' &&
764
+ typeof parsed.id === 'string' &&
765
+ typeof parsed.leftText === 'string' &&
766
+ typeof parsed.rightText === 'string'
767
+ ) {
768
+ matchingPairs.push({
769
+ id: parsed.id,
770
+ leftText: parsed.leftText,
771
+ rightText: parsed.rightText,
772
+ });
773
+ }
774
+ } catch {
775
+ // ignore non-JSON options used by objective questions
776
+ }
777
+ }
778
+
779
+ return {
780
+ fillBlankAnswers,
781
+ matchingPairs,
782
+ };
783
+ }
784
+ }