@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,776 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExamAttemptService = void 0;
13
+ const api_prisma_1 = require("@hed-hog/api-prisma");
14
+ const common_1 = require("@nestjs/common");
15
+ const create_exam_question_dto_1 = require("./dto/create-exam-question.dto");
16
+ let ExamAttemptService = class ExamAttemptService {
17
+ constructor(prisma) {
18
+ this.prisma = prisma;
19
+ }
20
+ async getAttemptState(examId, userId, explicitStudentId) {
21
+ const exam = await this.findExamOrThrow(examId);
22
+ const studentId = await this.resolveStudentId(userId, explicitStudentId);
23
+ let attempt = await this.findRelevantAttempt(examId, studentId);
24
+ if (attempt) {
25
+ attempt = await this.maybeFinalizeExpiredAttempt(exam, attempt);
26
+ }
27
+ return this.buildAttemptPayload(exam, studentId, attempt);
28
+ }
29
+ async startAttempt(examId, userId, ipAddress, dto) {
30
+ var _a, _b, _c;
31
+ const exam = await this.findExamOrThrow(examId);
32
+ const studentId = await this.resolveStudentId(userId, dto.studentId);
33
+ let activeAttempt = await this.findActiveAttempt(examId, studentId);
34
+ if (activeAttempt) {
35
+ activeAttempt = await this.maybeFinalizeExpiredAttempt(exam, activeAttempt);
36
+ if (activeAttempt.status === 'in_progress') {
37
+ return this.buildAttemptPayload(exam, studentId, activeAttempt);
38
+ }
39
+ }
40
+ const usedAttempts = await this.countAttempts(examId, studentId);
41
+ const attemptsAllowed = Math.max((_a = exam.attempts_allowed) !== null && _a !== void 0 ? _a : 1, 1);
42
+ if (usedAttempts >= attemptsAllowed) {
43
+ throw new common_1.BadRequestException('No attempts remaining for this exam');
44
+ }
45
+ if (((_b = exam.exam_question) !== null && _b !== void 0 ? _b : []).length === 0) {
46
+ throw new common_1.BadRequestException('Exam has no questions');
47
+ }
48
+ const enrollment = await this.findMatchingEnrollment(exam, studentId);
49
+ const created = await this.prisma.exam_attempt.create({
50
+ data: {
51
+ exam_id: exam.id,
52
+ student_id: studentId,
53
+ course_enrollment_id: (_c = enrollment === null || enrollment === void 0 ? void 0 : enrollment.id) !== null && _c !== void 0 ? _c : null,
54
+ attempt_number: usedAttempts + 1,
55
+ started_at: new Date(),
56
+ ip_address: ipAddress || null,
57
+ },
58
+ include: {
59
+ exam_answer: true,
60
+ },
61
+ });
62
+ return this.buildAttemptPayload(exam, studentId, created);
63
+ }
64
+ async saveAnswers(examId, attemptId, userId, dto) {
65
+ const exam = await this.findExamOrThrow(examId);
66
+ const studentId = await this.resolveStudentId(userId);
67
+ let attempt = await this.findAttemptOrThrow(examId, attemptId, studentId);
68
+ attempt = await this.maybeFinalizeExpiredAttempt(exam, attempt);
69
+ if (attempt.status !== 'in_progress') {
70
+ return this.buildAttemptPayload(exam, studentId, attempt);
71
+ }
72
+ await this.persistAnswers(attempt.id, exam, dto.answers);
73
+ const updated = await this.findAttemptOrThrow(examId, attemptId, studentId);
74
+ return this.buildAttemptPayload(exam, studentId, updated);
75
+ }
76
+ async submitAttempt(examId, attemptId, userId, dto) {
77
+ var _a, _b;
78
+ const exam = await this.findExamOrThrow(examId);
79
+ const studentId = await this.resolveStudentId(userId);
80
+ let attempt = await this.findAttemptOrThrow(examId, attemptId, studentId);
81
+ attempt = await this.maybeFinalizeExpiredAttempt(exam, attempt);
82
+ if (attempt.status === 'completed') {
83
+ return this.buildAttemptPayload(exam, studentId, attempt);
84
+ }
85
+ await this.persistAnswers(attempt.id, exam, (_a = dto.answers) !== null && _a !== void 0 ? _a : []);
86
+ const completed = await this.completeAttempt(exam, attempt.id, (_b = dto.force) !== null && _b !== void 0 ? _b : false);
87
+ return this.buildAttemptPayload(exam, studentId, completed);
88
+ }
89
+ async persistAnswers(attemptId, exam, answers) {
90
+ var _a, _b, _c, _d;
91
+ const normalizedAnswers = new Map();
92
+ for (const answer of answers !== null && answers !== void 0 ? answers : []) {
93
+ normalizedAnswers.set(answer.questionId, {
94
+ examOptionId: (_a = answer.examOptionId) !== null && _a !== void 0 ? _a : null,
95
+ answerText: ((_b = answer.answerText) === null || _b === void 0 ? void 0 : _b.trim()) || null,
96
+ matchingPairs: ((_c = answer.matchingPairs) !== null && _c !== void 0 ? _c : []).map((pair) => {
97
+ var _a, _b;
98
+ return ({
99
+ leftId: String((_a = pair.leftId) !== null && _a !== void 0 ? _a : '').trim(),
100
+ rightId: String((_b = pair.rightId) !== null && _b !== void 0 ? _b : '').trim(),
101
+ });
102
+ }),
103
+ });
104
+ }
105
+ const questionsById = new Map(((_d = exam.exam_question) !== null && _d !== void 0 ? _d : []).map((item) => [item.question_id, item]));
106
+ for (const questionId of normalizedAnswers.keys()) {
107
+ if (!questionsById.has(questionId)) {
108
+ throw new common_1.BadRequestException(`Question ${questionId} does not belong to exam`);
109
+ }
110
+ }
111
+ const questionIds = [...normalizedAnswers.keys()];
112
+ if (questionIds.length === 0) {
113
+ return;
114
+ }
115
+ await this.prisma.$transaction(async (tx) => {
116
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
117
+ const existingAnswers = await tx.exam_answer.findMany({
118
+ where: {
119
+ exam_attempt_id: attemptId,
120
+ question_id: { in: questionIds },
121
+ },
122
+ select: {
123
+ id: true,
124
+ question_id: true,
125
+ },
126
+ });
127
+ const existingByQuestionId = new Map(existingAnswers.map((item) => [item.question_id, item.id]));
128
+ for (const [questionId, answerValue] of normalizedAnswers.entries()) {
129
+ const question = questionsById.get(questionId);
130
+ const existingId = existingByQuestionId.get(questionId);
131
+ if (!question) {
132
+ throw new common_1.BadRequestException(`Question ${questionId} does not belong to exam`);
133
+ }
134
+ const questionType = this.resolveQuestionType((_a = question.question) === null || _a === void 0 ? void 0 : _a.question_type);
135
+ if (questionType === 'essay') {
136
+ if (!answerValue.answerText) {
137
+ if (existingId) {
138
+ await tx.exam_answer.delete({ where: { id: existingId } });
139
+ }
140
+ continue;
141
+ }
142
+ const payload = {
143
+ exam_option_id: null,
144
+ answer_text: answerValue.answerText,
145
+ is_correct: null,
146
+ points_awarded: 0,
147
+ };
148
+ if (existingId) {
149
+ await tx.exam_answer.update({
150
+ where: { id: existingId },
151
+ data: payload,
152
+ });
153
+ }
154
+ else {
155
+ await tx.exam_answer.create({
156
+ data: Object.assign({ exam_attempt_id: attemptId, question_id: questionId }, payload),
157
+ });
158
+ }
159
+ continue;
160
+ }
161
+ if (questionType === 'fill_blank') {
162
+ if (!answerValue.answerText) {
163
+ if (existingId) {
164
+ await tx.exam_answer.delete({ where: { id: existingId } });
165
+ }
166
+ continue;
167
+ }
168
+ const parsedOptions = this.parseSpecialOptions((_c = (_b = question.question) === null || _b === void 0 ? void 0 : _b.exam_option) !== null && _c !== void 0 ? _c : []);
169
+ const expectedAnswers = this.extractFillBlankExpectedAnswers(parsedOptions.fillBlankAnswers);
170
+ if (expectedAnswers.length === 0) {
171
+ throw new common_1.BadRequestException(`Fill-blank question ${questionId} has no expected answers`);
172
+ }
173
+ const isCorrect = this.isFillBlankCorrect(answerValue.answerText, expectedAnswers);
174
+ const payload = {
175
+ exam_option_id: null,
176
+ answer_text: answerValue.answerText,
177
+ is_correct: isCorrect,
178
+ points_awarded: isCorrect ? (_d = question.question.points) !== null && _d !== void 0 ? _d : 0 : 0,
179
+ };
180
+ if (existingId) {
181
+ await tx.exam_answer.update({
182
+ where: { id: existingId },
183
+ data: payload,
184
+ });
185
+ }
186
+ else {
187
+ await tx.exam_answer.create({
188
+ data: Object.assign({ exam_attempt_id: attemptId, question_id: questionId }, payload),
189
+ });
190
+ }
191
+ continue;
192
+ }
193
+ if (questionType === 'matching') {
194
+ const parsedOptions = this.parseSpecialOptions((_f = (_e = question.question) === null || _e === void 0 ? void 0 : _e.exam_option) !== null && _f !== void 0 ? _f : []);
195
+ const expectedPairs = this.extractMatchingPairs(parsedOptions.matchingPairs);
196
+ if (expectedPairs.length < 2) {
197
+ throw new common_1.BadRequestException(`Matching question ${questionId} has no valid pairs`);
198
+ }
199
+ const sanitizedPairs = answerValue.matchingPairs.filter((pair) => pair.leftId.length > 0 && pair.rightId.length > 0);
200
+ if (sanitizedPairs.length === 0) {
201
+ if (existingId) {
202
+ await tx.exam_answer.delete({ where: { id: existingId } });
203
+ }
204
+ continue;
205
+ }
206
+ const isCorrect = this.isMatchingCorrect(sanitizedPairs, expectedPairs);
207
+ const payload = {
208
+ exam_option_id: null,
209
+ answer_text: JSON.stringify({ matchingPairs: sanitizedPairs }),
210
+ is_correct: isCorrect,
211
+ points_awarded: isCorrect ? (_g = question.question.points) !== null && _g !== void 0 ? _g : 0 : 0,
212
+ };
213
+ if (existingId) {
214
+ await tx.exam_answer.update({
215
+ where: { id: existingId },
216
+ data: payload,
217
+ });
218
+ }
219
+ else {
220
+ await tx.exam_answer.create({
221
+ data: Object.assign({ exam_attempt_id: attemptId, question_id: questionId }, payload),
222
+ });
223
+ }
224
+ continue;
225
+ }
226
+ if (!answerValue.examOptionId) {
227
+ if (existingId) {
228
+ await tx.exam_answer.delete({ where: { id: existingId } });
229
+ }
230
+ continue;
231
+ }
232
+ const option = ((_j = (_h = question === null || question === void 0 ? void 0 : question.question) === null || _h === void 0 ? void 0 : _h.exam_option) !== null && _j !== void 0 ? _j : []).find((item) => item.id === answerValue.examOptionId);
233
+ if (!option) {
234
+ throw new common_1.BadRequestException(`Option ${answerValue.examOptionId} does not belong to question ${questionId}`);
235
+ }
236
+ const payload = {
237
+ exam_option_id: option.id,
238
+ answer_text: null,
239
+ is_correct: Boolean(option.is_correct),
240
+ points_awarded: option.is_correct ? (_k = question.question.points) !== null && _k !== void 0 ? _k : 0 : 0,
241
+ };
242
+ if (existingId) {
243
+ await tx.exam_answer.update({
244
+ where: { id: existingId },
245
+ data: payload,
246
+ });
247
+ }
248
+ else {
249
+ await tx.exam_answer.create({
250
+ data: Object.assign({ exam_attempt_id: attemptId, question_id: questionId }, payload),
251
+ });
252
+ }
253
+ }
254
+ });
255
+ }
256
+ async completeAttempt(exam, attemptId, force) {
257
+ var _a, _b;
258
+ const currentAttempt = await this.prisma.exam_attempt.findUnique({
259
+ where: { id: attemptId },
260
+ include: {
261
+ exam_answer: true,
262
+ },
263
+ });
264
+ if (!currentAttempt) {
265
+ throw new common_1.NotFoundException('Attempt not found');
266
+ }
267
+ if (currentAttempt.status === 'completed') {
268
+ return currentAttempt;
269
+ }
270
+ const maxPoints = this.getExamMaxPoints(exam);
271
+ const answeredCount = currentAttempt.exam_answer.length;
272
+ const questionCount = ((_a = exam.exam_question) !== null && _a !== void 0 ? _a : []).length;
273
+ if (!force &&
274
+ exam.require_all_questions_answered_to_finish &&
275
+ answeredCount < questionCount) {
276
+ throw new common_1.BadRequestException('All questions must be answered before finishing');
277
+ }
278
+ const totalPoints = currentAttempt.exam_answer.reduce((sum, answer) => { var _a; return sum + ((_a = answer.points_awarded) !== null && _a !== void 0 ? _a : 0); }, 0);
279
+ const maxScore = Math.max((_b = exam.max_score) !== null && _b !== void 0 ? _b : 100, 1);
280
+ const scaledScore = maxPoints > 0 ? Math.round((totalPoints / maxPoints) * maxScore) : 0;
281
+ return this.prisma.exam_attempt.update({
282
+ where: { id: attemptId },
283
+ data: {
284
+ status: 'completed',
285
+ finished_at: new Date(),
286
+ duration_seconds: Math.max(0, Math.floor((Date.now() - currentAttempt.started_at.getTime()) / 1000)),
287
+ score: scaledScore,
288
+ },
289
+ include: {
290
+ exam_answer: true,
291
+ },
292
+ });
293
+ }
294
+ async buildAttemptPayload(exam, studentId, attempt) {
295
+ var _a, _b, _c, _d, _e, _f, _g;
296
+ const attemptsAllowed = Math.max((_a = exam.attempts_allowed) !== null && _a !== void 0 ? _a : 1, 1);
297
+ const attemptsUsed = await this.countAttempts(exam.id, studentId);
298
+ const maxPoints = this.getExamMaxPoints(exam);
299
+ const questions = this.mapQuestions(exam, (_b = attempt === null || attempt === void 0 ? void 0 : attempt.id) !== null && _b !== void 0 ? _b : exam.id);
300
+ return {
301
+ exam: {
302
+ id: exam.id,
303
+ title: exam.title,
304
+ description: exam.description,
305
+ instructions: exam.instructions,
306
+ questionCount: questions.length,
307
+ maxPoints,
308
+ timeLimitMinutes: exam.time_limit_minutes,
309
+ passingScore: this.scoreToTen((_c = exam.min_score) !== null && _c !== void 0 ? _c : 0),
310
+ passingPercent: this.toPercent((_d = exam.min_score) !== null && _d !== void 0 ? _d : 0, (_e = exam.max_score) !== null && _e !== void 0 ? _e : 100),
311
+ requireAllQuestionsAnsweredToFinish: Boolean(exam.require_all_questions_answered_to_finish),
312
+ showResult: Boolean((_f = exam.show_result) !== null && _f !== void 0 ? _f : true),
313
+ },
314
+ attempts: {
315
+ allowed: attemptsAllowed,
316
+ used: attemptsUsed,
317
+ remaining: Math.max(attemptsAllowed - attemptsUsed, 0),
318
+ canStart: attemptsUsed < attemptsAllowed,
319
+ },
320
+ questions,
321
+ attempt: attempt
322
+ ? {
323
+ id: attempt.id,
324
+ attemptNumber: attempt.attempt_number,
325
+ status: attempt.status,
326
+ startedAt: attempt.started_at,
327
+ finishedAt: attempt.finished_at,
328
+ timeRemainingSeconds: this.getRemainingSeconds(exam, attempt),
329
+ answeredCount: attempt.exam_answer.length,
330
+ answers: ((_g = attempt.exam_answer) !== null && _g !== void 0 ? _g : []).map((answer) => ({
331
+ questionId: answer.question_id,
332
+ examOptionId: answer.exam_option_id,
333
+ answerText: answer.answer_text,
334
+ matchingPairs: this.extractMatchingPairsFromAnswerText(answer.answer_text),
335
+ })),
336
+ result: attempt.status === 'completed'
337
+ ? this.mapAttemptResult(exam, attempt)
338
+ : null,
339
+ }
340
+ : null,
341
+ };
342
+ }
343
+ mapAttemptResult(exam, attempt) {
344
+ var _a, _b, _c, _d, _e, _f, _g, _h;
345
+ const maxPoints = this.getExamMaxPoints(exam);
346
+ const maxScore = Math.max((_a = exam.max_score) !== null && _a !== void 0 ? _a : 100, 1);
347
+ const score = (_b = attempt.score) !== null && _b !== void 0 ? _b : 0;
348
+ const answersByQuestion = new Map(((_c = attempt.exam_answer) !== null && _c !== void 0 ? _c : []).map((answer) => [answer.question_id, answer]));
349
+ const hasPendingReview = ((_d = exam.exam_question) !== null && _d !== void 0 ? _d : []).some((item) => {
350
+ var _a;
351
+ const answer = answersByQuestion.get(item.question_id);
352
+ return this.requiresManualReview((_a = item.question) === null || _a === void 0 ? void 0 : _a.question_type) && Boolean(answer);
353
+ });
354
+ return {
355
+ totalPoints: ((_e = attempt.exam_answer) !== null && _e !== void 0 ? _e : []).reduce((sum, answer) => { var _a; return sum + ((_a = answer.points_awarded) !== null && _a !== void 0 ? _a : 0); }, 0),
356
+ maxPoints,
357
+ score,
358
+ scoreDisplay: this.scoreToTen(score),
359
+ percent: this.toPercent(score, maxScore),
360
+ passed: hasPendingReview ? null : score >= ((_f = exam.min_score) !== null && _f !== void 0 ? _f : 0),
361
+ hasPendingReview,
362
+ pendingReviewCount: ((_g = exam.exam_question) !== null && _g !== void 0 ? _g : []).filter((item) => {
363
+ var _a;
364
+ const answer = answersByQuestion.get(item.question_id);
365
+ return this.requiresManualReview((_a = item.question) === null || _a === void 0 ? void 0 : _a.question_type) && Boolean(answer);
366
+ }).length,
367
+ answersSummary: ((_h = exam.exam_question) !== null && _h !== void 0 ? _h : []).map((item) => {
368
+ var _a, _b;
369
+ const answer = answersByQuestion.get(item.question_id);
370
+ return {
371
+ questionId: item.question_id,
372
+ hasAnswer: Boolean(answer),
373
+ isCorrect: typeof (answer === null || answer === void 0 ? void 0 : answer.is_correct) === 'boolean' ? Boolean(answer.is_correct) : null,
374
+ pointsAwarded: (_a = answer === null || answer === void 0 ? void 0 : answer.points_awarded) !== null && _a !== void 0 ? _a : 0,
375
+ requiresManualReview: this.requiresManualReview((_b = item.question) === null || _b === void 0 ? void 0 : _b.question_type),
376
+ };
377
+ }),
378
+ };
379
+ }
380
+ mapQuestions(exam, seedBase) {
381
+ var _a;
382
+ const orderedQuestions = this.sortWithSeed(exam.shuffle_questions, ((_a = exam.exam_question) !== null && _a !== void 0 ? _a : []), (item) => item.question_id, `${seedBase}:questions`);
383
+ return orderedQuestions.map((item, index) => {
384
+ var _a, _b, _c, _d, _e;
385
+ const questionType = this.resolveQuestionType((_a = item.question) === null || _a === void 0 ? void 0 : _a.question_type);
386
+ const parsedOptions = this.parseSpecialOptions((_c = (_b = item.question) === null || _b === void 0 ? void 0 : _b.exam_option) !== null && _c !== void 0 ? _c : []);
387
+ const objectiveOptions = ((_e = (_d = item.question) === null || _d === void 0 ? void 0 : _d.exam_option) !== null && _e !== void 0 ? _e : []).filter((option) => !this.isJsonString(option.option_text));
388
+ const orderedOptions = this.sortWithSeed(exam.shuffle_options, objectiveOptions, (option) => option.id, `${seedBase}:question:${item.question_id}:options`);
389
+ return {
390
+ id: item.question_id,
391
+ order: index,
392
+ questionType,
393
+ statement: item.question.statement,
394
+ points: item.question.points,
395
+ fillBlankAnswers: parsedOptions.fillBlankAnswers,
396
+ matchingPairs: parsedOptions.matchingPairs,
397
+ matchingOptions: questionType === 'matching'
398
+ ? this.sortWithSeed(true, parsedOptions.matchingPairs.map((pair) => ({
399
+ id: pair.id,
400
+ text: pair.rightText,
401
+ })), (option) => this.hash(option.id), `${seedBase}:question:${item.question_id}:matching-options`)
402
+ : [],
403
+ alternatives: questionType === 'multiple_choice' || questionType === 'true_false'
404
+ ? orderedOptions.map((option) => ({
405
+ id: option.id,
406
+ text: option.option_text,
407
+ }))
408
+ : [],
409
+ };
410
+ });
411
+ }
412
+ sortWithSeed(enabled, items, getId, seed) {
413
+ const list = [...items];
414
+ if (!enabled) {
415
+ return list;
416
+ }
417
+ return list.sort((left, right) => {
418
+ const leftHash = this.hash(`${seed}:${getId(left)}`);
419
+ const rightHash = this.hash(`${seed}:${getId(right)}`);
420
+ if (leftHash === rightHash) {
421
+ return getId(left) - getId(right);
422
+ }
423
+ return leftHash - rightHash;
424
+ });
425
+ }
426
+ hash(value) {
427
+ let hash = 0;
428
+ for (let index = 0; index < value.length; index += 1) {
429
+ hash = (hash * 31 + value.charCodeAt(index)) >>> 0;
430
+ }
431
+ return hash;
432
+ }
433
+ async maybeFinalizeExpiredAttempt(exam, attempt) {
434
+ const remainingSeconds = this.getRemainingSeconds(exam, attempt);
435
+ if (attempt.status !== 'in_progress' || remainingSeconds === null || remainingSeconds > 0) {
436
+ return attempt;
437
+ }
438
+ return this.completeAttempt(exam, attempt.id, true);
439
+ }
440
+ getRemainingSeconds(exam, attempt) {
441
+ if (!exam.time_limit_minutes) {
442
+ return null;
443
+ }
444
+ const endsAt = attempt.started_at.getTime() + exam.time_limit_minutes * 60 * 1000;
445
+ return Math.max(0, Math.floor((endsAt - Date.now()) / 1000));
446
+ }
447
+ getExamMaxPoints(exam) {
448
+ var _a;
449
+ return ((_a = exam.exam_question) !== null && _a !== void 0 ? _a : []).reduce((sum, item) => { var _a, _b; return sum + ((_b = (_a = item.question) === null || _a === void 0 ? void 0 : _a.points) !== null && _b !== void 0 ? _b : 0); }, 0);
450
+ }
451
+ isObjectiveQuestion(questionType) {
452
+ return create_exam_question_dto_1.OBJECTIVE_EXAM_QUESTION_TYPES.includes(this.resolveQuestionType(questionType));
453
+ }
454
+ requiresManualReview(questionType) {
455
+ return this.resolveQuestionType(questionType) === 'essay';
456
+ }
457
+ resolveQuestionType(questionType) {
458
+ var _a;
459
+ return (_a = questionType) !== null && _a !== void 0 ? _a : 'multiple_choice';
460
+ }
461
+ isJsonString(value) {
462
+ try {
463
+ const parsed = JSON.parse(value);
464
+ return typeof parsed === 'object' && parsed !== null;
465
+ }
466
+ catch (_a) {
467
+ return false;
468
+ }
469
+ }
470
+ parseSpecialOptions(options) {
471
+ const fillBlankAnswers = [];
472
+ const matchingPairs = [];
473
+ for (const option of options) {
474
+ try {
475
+ const parsed = JSON.parse(option.option_text);
476
+ if ((parsed === null || parsed === void 0 ? void 0 : parsed.kind) === 'fill_blank' && typeof parsed.answer === 'string') {
477
+ fillBlankAnswers.push({
478
+ answer: parsed.answer,
479
+ alternatives: Array.isArray(parsed.alternatives)
480
+ ? parsed.alternatives
481
+ : [],
482
+ });
483
+ continue;
484
+ }
485
+ if ((parsed === null || parsed === void 0 ? void 0 : parsed.kind) === 'matching' &&
486
+ typeof parsed.id === 'string' &&
487
+ typeof parsed.leftText === 'string' &&
488
+ typeof parsed.rightText === 'string') {
489
+ matchingPairs.push({
490
+ id: parsed.id,
491
+ leftText: parsed.leftText,
492
+ rightText: parsed.rightText,
493
+ });
494
+ }
495
+ }
496
+ catch (_a) {
497
+ // Ignore objective options
498
+ }
499
+ }
500
+ return {
501
+ fillBlankAnswers,
502
+ matchingPairs,
503
+ };
504
+ }
505
+ extractFillBlankExpectedAnswers(rawValue) {
506
+ if (!Array.isArray(rawValue)) {
507
+ return [];
508
+ }
509
+ return rawValue.flatMap((item) => {
510
+ const primary = typeof (item === null || item === void 0 ? void 0 : item.answer) === 'string' ? [item.answer] : [];
511
+ const alternatives = Array.isArray(item === null || item === void 0 ? void 0 : item.alternatives)
512
+ ? item.alternatives.filter((alternative) => typeof alternative === 'string')
513
+ : [];
514
+ return [...primary, ...alternatives]
515
+ .map((value) => value.trim())
516
+ .filter((value) => value.length > 0);
517
+ });
518
+ }
519
+ isFillBlankCorrect(answerText, expectedAnswers) {
520
+ const normalizedAnswer = answerText.trim().toLowerCase();
521
+ return expectedAnswers.some((expected) => expected.trim().toLowerCase() === normalizedAnswer);
522
+ }
523
+ extractMatchingPairs(rawValue) {
524
+ if (!Array.isArray(rawValue)) {
525
+ return [];
526
+ }
527
+ return rawValue
528
+ .map((pair) => {
529
+ var _a, _b, _c;
530
+ return ({
531
+ id: String((_a = pair === null || pair === void 0 ? void 0 : pair.id) !== null && _a !== void 0 ? _a : '').trim(),
532
+ leftText: String((_b = pair === null || pair === void 0 ? void 0 : pair.leftText) !== null && _b !== void 0 ? _b : '').trim(),
533
+ rightText: String((_c = pair === null || pair === void 0 ? void 0 : pair.rightText) !== null && _c !== void 0 ? _c : '').trim(),
534
+ });
535
+ })
536
+ .filter((pair) => pair.id.length > 0 &&
537
+ pair.leftText.length > 0 &&
538
+ pair.rightText.length > 0);
539
+ }
540
+ isMatchingCorrect(submittedPairs, expectedPairs) {
541
+ if (submittedPairs.length !== expectedPairs.length) {
542
+ return false;
543
+ }
544
+ const expectedMap = new Map(expectedPairs.map((pair) => [pair.id, pair.id]));
545
+ const submittedMap = new Map(submittedPairs.map((pair) => [pair.leftId, pair.rightId]));
546
+ if (submittedMap.size !== expectedMap.size) {
547
+ return false;
548
+ }
549
+ for (const [leftId, expectedRightId] of expectedMap.entries()) {
550
+ if (submittedMap.get(leftId) !== expectedRightId) {
551
+ return false;
552
+ }
553
+ }
554
+ return true;
555
+ }
556
+ extractMatchingPairsFromAnswerText(answerText) {
557
+ if (!answerText) {
558
+ return [];
559
+ }
560
+ try {
561
+ const parsed = JSON.parse(answerText);
562
+ if (!Array.isArray(parsed === null || parsed === void 0 ? void 0 : parsed.matchingPairs)) {
563
+ return [];
564
+ }
565
+ return parsed.matchingPairs
566
+ .map((pair) => {
567
+ var _a, _b;
568
+ return ({
569
+ leftId: String((_a = pair === null || pair === void 0 ? void 0 : pair.leftId) !== null && _a !== void 0 ? _a : '').trim(),
570
+ rightId: String((_b = pair === null || pair === void 0 ? void 0 : pair.rightId) !== null && _b !== void 0 ? _b : '').trim(),
571
+ });
572
+ })
573
+ .filter((pair) => pair.leftId.length > 0 && pair.rightId.length > 0);
574
+ }
575
+ catch (_a) {
576
+ return [];
577
+ }
578
+ }
579
+ async findExamOrThrow(examId) {
580
+ const exam = await this.prisma.exam.findUnique({
581
+ where: { id: examId },
582
+ include: {
583
+ exam_question: {
584
+ orderBy: { order: 'asc' },
585
+ include: {
586
+ question: {
587
+ include: {
588
+ exam_option: {
589
+ orderBy: { position: 'asc' },
590
+ },
591
+ },
592
+ },
593
+ },
594
+ },
595
+ },
596
+ });
597
+ if (!exam) {
598
+ throw new common_1.NotFoundException('Exam not found');
599
+ }
600
+ return exam;
601
+ }
602
+ async findRelevantAttempt(examId, studentId) {
603
+ const activeAttempt = await this.findActiveAttempt(examId, studentId);
604
+ if (activeAttempt) {
605
+ return activeAttempt;
606
+ }
607
+ return this.prisma.exam_attempt.findFirst({
608
+ where: {
609
+ exam_id: examId,
610
+ student_id: studentId,
611
+ },
612
+ orderBy: { created_at: 'desc' },
613
+ include: {
614
+ exam_answer: true,
615
+ },
616
+ });
617
+ }
618
+ findActiveAttempt(examId, studentId) {
619
+ return this.prisma.exam_attempt.findFirst({
620
+ where: {
621
+ exam_id: examId,
622
+ student_id: studentId,
623
+ status: 'in_progress',
624
+ },
625
+ orderBy: { created_at: 'desc' },
626
+ include: {
627
+ exam_answer: true,
628
+ },
629
+ });
630
+ }
631
+ async findAttemptOrThrow(examId, attemptId, studentId) {
632
+ const attempt = await this.prisma.exam_attempt.findFirst({
633
+ where: {
634
+ id: attemptId,
635
+ exam_id: examId,
636
+ student_id: studentId,
637
+ },
638
+ include: {
639
+ exam_answer: true,
640
+ },
641
+ });
642
+ if (!attempt) {
643
+ throw new common_1.NotFoundException('Attempt not found');
644
+ }
645
+ return attempt;
646
+ }
647
+ countAttempts(examId, studentId) {
648
+ return this.prisma.exam_attempt.count({
649
+ where: {
650
+ exam_id: examId,
651
+ student_id: studentId,
652
+ status: {
653
+ not: 'voided',
654
+ },
655
+ },
656
+ });
657
+ }
658
+ async findMatchingEnrollment(exam, studentId) {
659
+ if (exam.course_class_group_id) {
660
+ return this.prisma.course_enrollment.findFirst({
661
+ where: {
662
+ person_id: studentId,
663
+ course_class_group_id: exam.course_class_group_id,
664
+ },
665
+ orderBy: { updated_at: 'desc' },
666
+ select: { id: true },
667
+ });
668
+ }
669
+ if (exam.course_id) {
670
+ return this.prisma.course_enrollment.findFirst({
671
+ where: {
672
+ person_id: studentId,
673
+ course_id: exam.course_id,
674
+ },
675
+ orderBy: { updated_at: 'desc' },
676
+ select: { id: true },
677
+ });
678
+ }
679
+ return null;
680
+ }
681
+ async resolveStudentId(userId, explicitStudentId) {
682
+ var _a, _b, _c;
683
+ if (explicitStudentId) {
684
+ const person = await this.prisma.person.findUnique({
685
+ where: { id: explicitStudentId },
686
+ select: { id: true },
687
+ });
688
+ if (!person) {
689
+ throw new common_1.NotFoundException('Student not found');
690
+ }
691
+ return person.id;
692
+ }
693
+ const user = await this.prisma.user.findUnique({
694
+ where: { id: userId },
695
+ select: {
696
+ id: true,
697
+ name: true,
698
+ user_identifier: {
699
+ where: {
700
+ type: 'email',
701
+ enabled: true,
702
+ },
703
+ select: {
704
+ value: true,
705
+ },
706
+ take: 1,
707
+ },
708
+ },
709
+ });
710
+ if (!user) {
711
+ throw new common_1.NotFoundException('Authenticated user not found');
712
+ }
713
+ const userEmail = (_c = (_b = (_a = user.user_identifier) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.trim().toLowerCase();
714
+ if (userEmail) {
715
+ const matchingPersons = await this.prisma.person.findMany({
716
+ where: {
717
+ contact: {
718
+ some: {
719
+ value: { equals: userEmail, mode: 'insensitive' },
720
+ contact_type: {
721
+ code: 'email',
722
+ },
723
+ },
724
+ },
725
+ },
726
+ select: { id: true },
727
+ take: 2,
728
+ });
729
+ if (matchingPersons.length === 1) {
730
+ return matchingPersons[0].id;
731
+ }
732
+ }
733
+ const sameIdPerson = await this.prisma.person.findUnique({
734
+ where: { id: userId },
735
+ select: { id: true },
736
+ });
737
+ if (sameIdPerson) {
738
+ return sameIdPerson.id;
739
+ }
740
+ const emailType = await this.prisma.contact_type.findFirst({
741
+ where: { code: 'email' },
742
+ select: { id: true },
743
+ });
744
+ const createdPerson = await this.prisma.person.create({
745
+ data: Object.assign({ name: user.name, type: 'individual', status: 'active' }, (userEmail && emailType
746
+ ? {
747
+ contact: {
748
+ create: {
749
+ contact_type_id: emailType.id,
750
+ value: userEmail,
751
+ is_primary: true,
752
+ },
753
+ },
754
+ }
755
+ : {})),
756
+ select: { id: true },
757
+ });
758
+ return createdPerson.id;
759
+ }
760
+ toPercent(value, max) {
761
+ if (!max)
762
+ return 0;
763
+ return Math.round((value / max) * 100);
764
+ }
765
+ scoreToTen(score) {
766
+ if (!score)
767
+ return 0;
768
+ return score > 10 ? Number((score / 10).toFixed(1)) : Number(score.toFixed(1));
769
+ }
770
+ };
771
+ exports.ExamAttemptService = ExamAttemptService;
772
+ exports.ExamAttemptService = ExamAttemptService = __decorate([
773
+ (0, common_1.Injectable)(),
774
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService])
775
+ ], ExamAttemptService);
776
+ //# sourceMappingURL=exam-attempt.service.js.map